UNPKG

wecui

Version:

一款基于Vue2.x版本的移动端web组件

21 lines (18 loc) 827 B
var isType = require('./isType'); var isStruct = require('./isStruct'); 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)) { // for structs the new operator is allowed return isStruct(type) ? 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; };