Skip to content

Instantly share code, notes, and snippets.

@underground
Created June 19, 2017 00:58
Show Gist options
  • Save underground/0c571a58d3e1300d78f07a6a6d2d9fc2 to your computer and use it in GitHub Desktop.
Save underground/0c571a58d3e1300d78f07a6a6d2d9fc2 to your computer and use it in GitHub Desktop.
import _ from 'lodash';
_.mixin({
isInt: (value) => {
return Number(value) === value && value % 1 === 0;
},
isFloat: (value) => {
return Number(value) === value && value % 1 !== 0;
},
toBoolean: (value) => {
return _.includes(['true', 'yes', 'on', '1'], _.toLower(_.toString(value)));
},
toFloat: (value, precision) => {
var num = 0.0;
if (/^(-?[0-9]\d*|0)(\.\d+)?$/.test(value)) {
num = parseFloat(value);
} else if (_.isNumber(value)) {
num = value;
}
return num;
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment