0.1.3 add addTrue and addFalse opts for adding additons on create, add offline/online to lists
parent
36daa6b5b9
commit
6ec7fece2b
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@uci-utils/to-boolean",
|
||||
"version": "0.1.2",
|
||||
"version": "0.1.3",
|
||||
"description": "function to return a boolean value from sets of default values",
|
||||
"main": "src/boolean.js",
|
||||
"scripts": {
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
const rTrue=['t','true','y','yes','on','positive','up','enabled','affirmative','yea','sure']
|
||||
const rFalse=['f','false','n','no','off','negative','down','disabled','nope']
|
||||
let rTrue=['t','true','y','yes','on','positive','up','enabled','affirmative','yea','sure','online']
|
||||
let rFalse=['f','false','n','no','off','negative','down','disabled','nope','offline']
|
||||
|
||||
function createBoolean (opts={}) {
|
||||
return (value => {
|
||||
if (opts.addTrue) rTrue = rTrue.concat(opts.addTrue)
|
||||
if (opts.addFalse) rFalse = rFalse.concat(opts.addFalse)
|
||||
if (value===undefined) return opts.undefined==='same' ? undefined : opts.undefined || false
|
||||
if (value===null) return opts.null==='same' ? null : opts.null || false
|
||||
if (!isNaN(Number(value))) return (opts.number==='default' ? !!value : (Number(value) > (opts.number || 0)? true : false))
|
||||
|
|
Loading…
Reference in New Issue