+ string util: stringToBoolean

This commit is contained in:
tmshv committed 2016-03-03 01:30:06 +03:00
1 parent ac0e7e089d
commit 5add54d1a4
1 file changed
+14
+14
View File
@@ -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
);
}