Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
47fad335
Commit
47fad335
authored
Nov 21, 2018
by
Winnie Hellmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add parseBoolean helper function
parent
ea8f0f3b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
1 deletion
+35
-1
app/assets/javascripts/lib/utils/common_utils.js
app/assets/javascripts/lib/utils/common_utils.js
+17
-1
spec/javascripts/lib/utils/common_utils_spec.js
spec/javascripts/lib/utils/common_utils_spec.js
+18
-0
No files found.
app/assets/javascripts/lib/utils/common_utils.js
View file @
47fad335
...
@@ -420,13 +420,29 @@ export const historyPushState = newUrl => {
...
@@ -420,13 +420,29 @@ export const historyPushState = newUrl => {
window
.
history
.
pushState
({},
document
.
title
,
newUrl
);
window
.
history
.
pushState
({},
document
.
title
,
newUrl
);
};
};
/**
* Returns true for a String "true" and false otherwise.
* This is the opposite of Boolean(...).toString()
*
* @param {String} value
* @returns {Boolean}
*/
export
const
parseBoolean
=
value
=>
value
===
'
true
'
;
/**
/**
* Converts permission provided as strings to booleans.
* Converts permission provided as strings to booleans.
*
*
* @param {String} string
* @param {String} string
* @returns {Boolean}
* @returns {Boolean}
*/
*/
export
const
convertPermissionToBoolean
=
permission
=>
permission
===
'
true
'
;
export
const
convertPermissionToBoolean
=
permission
=>
{
if
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
{
// eslint-disable-next-line no-console
console
.
warn
(
'
convertPermissionToBoolean is deprecated! Please use parseBoolean instead.
'
);
}
return
parseBoolean
(
permission
);
};
/**
/**
* Back Off exponential algorithm
* Back Off exponential algorithm
...
...
spec/javascripts/lib/utils/common_utils_spec.js
View file @
47fad335
...
@@ -346,6 +346,24 @@ describe('common_utils', () => {
...
@@ -346,6 +346,24 @@ describe('common_utils', () => {
});
});
});
});
describe
(
'
parseBoolean
'
,
()
=>
{
it
(
'
returns true for "true"
'
,
()
=>
{
expect
(
commonUtils
.
parseBoolean
(
'
true
'
)).
toEqual
(
true
);
});
it
(
'
returns false for "false"
'
,
()
=>
{
expect
(
commonUtils
.
parseBoolean
(
'
false
'
)).
toEqual
(
false
);
});
it
(
'
returns false for "something"
'
,
()
=>
{
expect
(
commonUtils
.
parseBoolean
(
'
something
'
)).
toEqual
(
false
);
});
it
(
'
returns false for null
'
,
()
=>
{
expect
(
commonUtils
.
parseBoolean
(
null
)).
toEqual
(
false
);
});
});
describe
(
'
convertPermissionToBoolean
'
,
()
=>
{
describe
(
'
convertPermissionToBoolean
'
,
()
=>
{
it
(
'
should convert a boolean in a string to a boolean
'
,
()
=>
{
it
(
'
should convert a boolean in a string to a boolean
'
,
()
=>
{
expect
(
commonUtils
.
convertPermissionToBoolean
(
'
true
'
)).
toEqual
(
true
);
expect
(
commonUtils
.
convertPermissionToBoolean
(
'
true
'
)).
toEqual
(
true
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment