Comparing version 4.4.1 to 4.5.0
@@ -67,2 +67,19 @@ // @flow | ||
/** | ||
* Return a specific checker. | ||
* @param {string|Function|Array|Object} type A single stringy type reference (e.g. 'str'), functional shorthand type reference (e.g. `String`), or an object/array with list of types (e.g. `{name:'str'}` or `['str', 'num']`). | ||
* @return {function} The specified checker or undefined if it doesn't exist. | ||
*/ | ||
checker(type) { | ||
// Check args. | ||
runChecker(this._checkers.string, type, "arguments[0]", BlorkError); | ||
// Return the checker. | ||
const checker = this._checkers[type]; | ||
if (checker) return checker; | ||
// Not found. | ||
throwError(BlorkError, "Checker not found", type, "arguments[0]"); | ||
} | ||
/** | ||
* Check values against types. | ||
@@ -69,0 +86,0 @@ * Throws an error if a value doesn't match a specified type. |
@@ -9,3 +9,3 @@ const ValueError = require("./errors/ValueError"); | ||
// Make a default instance. | ||
const { args, check, add, throws } = blork(); | ||
const { args, check, add, checker, throws } = blork(); | ||
@@ -17,2 +17,3 @@ // Exports. | ||
exports.add = add; | ||
exports.checker = checker; | ||
exports.throws = throws; | ||
@@ -19,0 +20,0 @@ exports.format = format; |
@@ -20,5 +20,6 @@ const Blorker = require("../classes/Blorker"); | ||
args: blorker.args.bind(blorker), | ||
throws: blorker.throws.bind(blorker), | ||
add: blorker.add.bind(blorker) | ||
add: blorker.add.bind(blorker), | ||
checker: blorker.checker.bind(blorker), | ||
throws: blorker.throws.bind(blorker) | ||
}; | ||
}; |
{ | ||
"name": "blork", | ||
"description": "Blork! Mini runtime type checking in Javascript", | ||
"version": "4.4.1", | ||
"version": "4.5.0", | ||
"license": "0BSD", | ||
@@ -6,0 +6,0 @@ "author": "Dave Houlbrooke <dave@shax.com>", |
@@ -518,2 +518,4 @@ # Blork! Mini runtime type checking in Javascript | ||
- 4.5.0 | ||
- Add `checker()` function to return the boolean checker function itself. | ||
- 4.4.0 | ||
@@ -520,0 +522,0 @@ - Add `json` checker to check for JSON-friendly values (null, true, false, finite numbers, strings, plain objects, plain arrays) |
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
113836
38
1930
542