UNPKG

vanilla-type-check

Version:
65 lines (64 loc) 1.88 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); // same implementation as lodash library var objectProto = Object.prototype; var hasOwnProperty = objectProto.hasOwnProperty; var toString = objectProto.toString; var symToStringTag = typeof Symbol != 'undefined' ? Symbol.toStringTag : undefined; /* * lodash.baseGetTag */ /* istanbul ignore next */ function baseGetTag(value) { if (value == null) { return value === undefined ? '[object Undefined]' : '[object Null]'; } if (!(symToStringTag && symToStringTag in Object(value))) { return toString.call(value); } var isOwn = hasOwnProperty.call(value, symToStringTag); var tag = value[symToStringTag]; var unmasked = false; try { value[symToStringTag] = undefined; unmasked = true; } catch (e) { } var result = toString.call(value); if (unmasked) { if (isOwn) { value[symToStringTag] = tag; } else { delete value[symToStringTag]; } } return result; } /* * lodash.isObjectLike */ /* istanbul ignore next */ function isObjectLike(value) { return typeof value == 'object' && value !== null; } /** * Check if a value is a plain object (that is, not a class instance, etc.) * * @param value value to check * @returns `true` if `obj` is a plain object */ function isPlainObject(value) { if (!isObjectLike(value) || baseGetTag(value) != '[object Object]') { return false; } if (Object.getPrototypeOf(value) === null) { return true; } var proto = value; while (Object.getPrototypeOf(proto) !== null) { proto = Object.getPrototypeOf(proto); } return Object.getPrototypeOf(value) === proto; } exports.isPlainObject = isPlainObject;