opencadc-js
Advanced tools
Comparing version 2.0.6 to 2.0.7
@@ -131,2 +131,25 @@ 'use strict'; | ||
/** | ||
* Utility class to check for proper true or false values. | ||
* | ||
* @constructor | ||
*/ | ||
function BooleanUtil() | ||
{ | ||
var _TRUTH_REGEX_ = | ||
new RegExp('^' + '\\s*' + '\\b' + 'y[es]?|true' + '\\b' + '\\s*' + '$','i'); | ||
/** | ||
* Return whether the given value is true, or 'positive'. This will test for | ||
* things like 'true', true, 1, 'yes', 'y'. | ||
* | ||
* @param {*} _val | ||
*/ | ||
this.truthiness = function(_val) | ||
{ | ||
return (_val == true) | ||
|| ((typeof _val === 'string') && _TRUTH_REGEX_.test(_val)); | ||
}; | ||
} | ||
/** | ||
* Format numeric values for output. | ||
@@ -372,2 +395,3 @@ * | ||
exports.StringUtil = StringUtil; | ||
exports.BooleanUtil = BooleanUtil; | ||
exports.ArrayUtil = ArrayUtil; | ||
@@ -374,0 +398,0 @@ exports.NumberFormat = NumberFormat; |
{ | ||
"name": "opencadc-js", | ||
"version": "2.0.6", | ||
"version": "2.0.7", | ||
"description": "OpenCADC JavaScript libraries.", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
@@ -315,2 +315,49 @@ var assert = require('assert'); | ||
}); | ||
}); | ||
}); | ||
describe('BooleanUtil values.', function () | ||
{ | ||
var testSubject = new opencadcJS.BooleanUtil(); | ||
it ('Check base primitive.', function () | ||
{ | ||
assert.ok(testSubject.truthiness(true)); | ||
assert.ok(testSubject.truthiness(1), 'Check value of 1.'); | ||
}); | ||
it ('Check for "y"', function () | ||
{ | ||
assert.ok(testSubject.truthiness('y'), 'Check for "y"'); | ||
}); | ||
it ('Check for "Y"', function () | ||
{ | ||
assert.ok(testSubject.truthiness('Y'), 'Check for "Y"'); | ||
}); | ||
it ('Check for "yes"', function () | ||
{ | ||
assert.ok(testSubject.truthiness('Yes'), 'Check for "Yes"'); | ||
assert.ok(testSubject.truthiness('yEs'), 'Check for "yEs"'); | ||
}); | ||
it ('Check string "true"', function () | ||
{ | ||
assert.ok(testSubject.truthiness('true')); | ||
}); | ||
it ('Check string "false"', function () | ||
{ | ||
assert.ok(testSubject.truthiness('false') === false); | ||
}); | ||
it ('Check string "no"', function () | ||
{ | ||
assert.ok(testSubject.truthiness('no') === false); | ||
}); | ||
it ('Check string "n"', function () | ||
{ | ||
assert.ok(testSubject.truthiness('n') === false); | ||
}); | ||
}); |
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
239760
3528