+ string util: stringToBoolean
This commit is contained in:
1 parent
ac0e7e089d
commit
5add54d1a4
1 file changed
+14
@@ -1,3 +1,5 @@
|
||||
import {map} from './common';
|
||||
|
||||
/**
|
||||
* Return a function that accept one String parameter and returns result of replacing.
|
||||
*
|
||||
@@ -6,3 +8,15 @@
|
||||
*/
|
||||
export const stringReplace = (searchValue, replaceValue) =>
|
||||
str => str.replace(searchValue, replaceValue);
|
||||
|
||||
let toTrue = map(true, i => i === 'true');
|
||||
let toFalse = map(false, i => i === 'false');
|
||||
const boolProcessors = [toTrue, toFalse];
|
||||
|
||||
export function stringToBoolean(string){
|
||||
return boolProcessors
|
||||
.reduce(
|
||||
(value, fn) => fn(value),
|
||||
string
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user