RAHHH
This commit is contained in:
19
backend/frontend/node_modules/tcomb/lib/create.js
generated
vendored
Normal file
19
backend/frontend/node_modules/tcomb/lib/create.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
var isType = require('./isType');
|
||||
var getFunctionName = require('./getFunctionName');
|
||||
var assert = require('./assert');
|
||||
var stringify = require('./stringify');
|
||||
|
||||
// creates an instance of a type, handling the optional new operator
|
||||
module.exports = function create(type, value, path) {
|
||||
if (isType(type)) {
|
||||
return !type.meta.identity && typeof value === 'object' && value !== null ? new type(value, path): type(value, path);
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
// here type should be a class constructor and value some instance, just check membership and return the value
|
||||
path = path || [getFunctionName(type)];
|
||||
assert(value instanceof type, function () { return 'Invalid value ' + stringify(value) + ' supplied to ' + path.join('/'); });
|
||||
}
|
||||
|
||||
return value;
|
||||
};
|
||||
Reference in New Issue
Block a user