判断 实参类型 isOfType.类型,输出boolean类型
例:
isOfType.null(null) // true
isOfType.array([]) // true
const isOfType = (() => {// create a plain object with no prototypeconst type = Object.create(null);// check for null typetype.null = x => x === null;// check for undefined typetype.undefined = x => x === undefined;// check for nil type. Either null or undefinedtype.nil = x => type.null(x) || type.undefined(x);// check for strings and string literal type. e.g: 's', "s", `str`, new String()type.string = x => !type.nil(x) && (typeof x === 'string' || x instanceof String);// check for number or number literal type. e.g: 12, 30.5, new Number()type.number = x => !type.nil(x)&& (// NaN & Infinity have typeof "number" and this excludes that(!isNaN(x) && isFinite(x)&& typeof x === 'number') || x instanceof Number);// check for boolean or boolean literal type. e.g: true, false, new Boolean()type.boolean = x => !type.nil(x) && (typeof x === 'boolean' || x instanceof Boolean);// check for array typetype.array = x => !type.nil(x) && Array.isArray(x);// check for object or object literal type. e.g: {}, new Object(), Object.create(null)type.object = x => ({}).toString.call(x) === '[object Object]';// check for provided type instancetype.type = (x, X) => !type.nil(x) && x instanceof X;// check for set typetype.set = x => type.type(x, Set);// check for map typetype.map = x => type.type(x, Map);// check for date typetype.date = x => type.type(x, Date);return type;})()
