sectom
Version:
Sectom is a useful npm package that has multiple easy to use functions.
27 lines (22 loc) • 479 B
JavaScript
/**
*
* @param {string} input
* @returns {boolean | null}
*/
function stringToBoolean(input) {
if (typeof input == "boolean") return input;
const variations = {
yes: true,
["true"]: true,
right: true,
correct: true,
perfect: true,
no: false,
["false"]: false,
incorrect: false,
wrong: false,
imperfect: false,
};
return variations[`${input}`] || null;
}
exports.stringToBoolean = stringToBoolean;