@lyra/form-builder
Version:
Lyra form builder
58 lines (50 loc) • 1.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.resolveJSType = resolveJSType;
const toString = Object.prototype.toString;
// Copied from https://github.com/ForbesLindesay/type-of, but inlined to have fine grained control
function resolveJSType(val) {
switch (toString.call(val)) {
case '[object Function]':
return 'function';
case '[object Date]':
return 'date';
case '[object RegExp]':
return 'regexp';
case '[object Arguments]':
return 'arguments';
case '[object Array]':
return 'array';
case '[object String]':
return 'string';
default:
}
if (typeof val == 'object' && val && typeof val.length == 'number') {
try {
if (typeof val.callee == 'function') {
// eslint-disable-line max-depth
return 'arguments';
}
} catch (ex) {
if (ex instanceof TypeError) {
// eslint-disable-line max-depth
return 'arguments';
}
}
}
if (val === null) {
return 'null';
}
if (val === undefined) {
return 'undefined';
}
if (val && val.nodeType === 1) {
return 'element';
}
if (val === Object(val)) {
return 'object';
}
return typeof val;
}