RAHHH
This commit is contained in:
36
backend/frontend/node_modules/tcomb/lib/irreducible.js
generated
vendored
Normal file
36
backend/frontend/node_modules/tcomb/lib/irreducible.js
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
var assert = require('./assert');
|
||||
var isString = require('./isString');
|
||||
var isFunction = require('./isFunction');
|
||||
var forbidNewOperator = require('./forbidNewOperator');
|
||||
|
||||
module.exports = function irreducible(name, predicate) {
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
assert(isString(name), function () { return 'Invalid argument name ' + assert.stringify(name) + ' supplied to irreducible(name, predicate) (expected a string)'; });
|
||||
assert(isFunction(predicate), 'Invalid argument predicate ' + assert.stringify(predicate) + ' supplied to irreducible(name, predicate) (expected a function)');
|
||||
}
|
||||
|
||||
function Irreducible(value, path) {
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
forbidNewOperator(this, Irreducible);
|
||||
path = path || [name];
|
||||
assert(predicate(value), function () { return 'Invalid value ' + assert.stringify(value) + ' supplied to ' + path.join('/'); });
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
Irreducible.meta = {
|
||||
kind: 'irreducible',
|
||||
name: name,
|
||||
predicate: predicate,
|
||||
identity: true
|
||||
};
|
||||
|
||||
Irreducible.displayName = name;
|
||||
|
||||
Irreducible.is = predicate;
|
||||
|
||||
return Irreducible;
|
||||
};
|
||||
Reference in New Issue
Block a user