booler/src/booler.js

15 lines
373 B
JavaScript
Raw Normal View History

2019-10-31 09:03:22 +07:00
/**
*
* Booler can convert any value to Boolean type.
2019-10-31 09:03:22 +07:00
*
* @author Samob Chea <sombochea@cubetiqs.com>
2019-10-31 09:03:22 +07:00
* @param {*} val Value to parse.
*/
const booler = (val) => {
2019-10-31 09:45:34 +07:00
// transform to string lower case.
2019-10-31 09:51:04 +07:00
val = (val + "").toLowerCase();
2019-10-31 09:03:22 +07:00
return val == 't' || val == 'true' || val == 1;
}
// export module within function name `booler`.
module.exports = booler;