Comparing version 0.0.0 to 0.0.1
'use strict'; | ||
var boolean = function () {}; | ||
var boolean = function (value) { | ||
if (!value) { | ||
return false; | ||
} | ||
if (typeof value === 'string') { | ||
return /^true|t|yes|y|1$/i.test(value); | ||
} | ||
return true; | ||
}; | ||
module.exports = boolean; |
{ | ||
"name": "boolean", | ||
"version": "0.0.0", | ||
"version": "0.0.1", | ||
"description": "boolean converts lots of things to boolean.", | ||
@@ -5,0 +5,0 @@ "contributors": [ |
@@ -17,2 +17,24 @@ # boolean | ||
To verify a value for its boolean value, call the `boolean` function and provide the value in question as parameter. | ||
```javascript | ||
console.log(boolean('true')); // => true | ||
``` | ||
The `boolean` function considers the following values to be equivalent to `true`: | ||
- `true` (boolean) | ||
- `'true'` (string) | ||
- `'TRUE'` (string) | ||
- `'t'` (string) | ||
- `'T'` (string) | ||
- `'yes (string)'` (string) | ||
- `'YES (string)'` (string) | ||
- `'y'` (string) | ||
- `'Y'` (string) | ||
- `'1'` (string) | ||
- `1` (number) | ||
All other values, including `undefined` and `null` are considered to be `false`. | ||
## Running the build | ||
@@ -19,0 +41,0 @@ |
@@ -12,2 +12,132 @@ 'use strict'; | ||
}); | ||
suite('undefined', function () { | ||
test('returns false.', function (done) { | ||
assert.that(boolean(undefined), is.false()); | ||
done(); | ||
}); | ||
}); | ||
suite('null', function () { | ||
test('returns false.', function (done) { | ||
assert.that(boolean(null), is.false()); | ||
done(); | ||
}); | ||
}); | ||
suite('boolean', function () { | ||
test('true returns true.', function (done) { | ||
assert.that(boolean(true), is.true()); | ||
done(); | ||
}); | ||
test('false returns false.', function (done) { | ||
assert.that(boolean(false), is.false()); | ||
done(); | ||
}); | ||
}); | ||
suite('string', function () { | ||
test('"true" returns true.', function (done) { | ||
assert.that(boolean('true'), is.true()); | ||
done(); | ||
}); | ||
test('"false" returns false.', function (done) { | ||
assert.that(boolean('false'), is.false()); | ||
done(); | ||
}); | ||
test('"TRUE" returns true.', function (done) { | ||
assert.that(boolean('TRUE'), is.true()); | ||
done(); | ||
}); | ||
test('"FALSE" returns false.', function (done) { | ||
assert.that(boolean('FALSE'), is.false()); | ||
done(); | ||
}); | ||
test('"t" returns true.', function (done) { | ||
assert.that(boolean('t'), is.true()); | ||
done(); | ||
}); | ||
test('"f" returns false.', function (done) { | ||
assert.that(boolean('f'), is.false()); | ||
done(); | ||
}); | ||
test('"T" returns true.', function (done) { | ||
assert.that(boolean('T'), is.true()); | ||
done(); | ||
}); | ||
test('"F" returns false.', function (done) { | ||
assert.that(boolean('F'), is.false()); | ||
done(); | ||
}); | ||
test('"yes" returns true.', function (done) { | ||
assert.that(boolean('yes'), is.true()); | ||
done(); | ||
}); | ||
test('"no" returns false.', function (done) { | ||
assert.that(boolean('no'), is.false()); | ||
done(); | ||
}); | ||
test('"YES" returns true.', function (done) { | ||
assert.that(boolean('YES'), is.true()); | ||
done(); | ||
}); | ||
test('"NO" returns false.', function (done) { | ||
assert.that(boolean('NO'), is.false()); | ||
done(); | ||
}); | ||
test('"y" returns true.', function (done) { | ||
assert.that(boolean('y'), is.true()); | ||
done(); | ||
}); | ||
test('"n" returns false.', function (done) { | ||
assert.that(boolean('n'), is.false()); | ||
done(); | ||
}); | ||
test('"Y" returns true.', function (done) { | ||
assert.that(boolean('Y'), is.true()); | ||
done(); | ||
}); | ||
test('"N" returns false.', function (done) { | ||
assert.that(boolean('N'), is.false()); | ||
done(); | ||
}); | ||
test('"1" returns true.', function (done) { | ||
assert.that(boolean('1'), is.true()); | ||
done(); | ||
}); | ||
test('"0" returns false.', function (done) { | ||
assert.that(boolean('0'), is.false()); | ||
done(); | ||
}); | ||
}); | ||
suite('number', function () { | ||
test('1 returns true.', function (done) { | ||
assert.that(boolean(1), is.true()); | ||
done(); | ||
}); | ||
test('0 returns false.', function (done) { | ||
assert.that(boolean(0), is.false()); | ||
done(); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6574
136
55