forked from gcanti/tcomb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
irreducible.js
36 lines (27 loc) · 1.12 KB
/
irreducible.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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;
};