UNPKG

ut2

Version:

一个现代 JavaScript 实用工具库。[点击查看在线文档]。

45 lines (42 loc) 1.82 kB
import { dataViewTag, mapTag, promiseTag, setTag, weakMapTag, stringUndefined, objectTag, nativeUndefined } from './native.js'; import { toSource } from './helpers.js'; import getTag from './getTag.js'; var dataViewExisted = typeof DataView !== stringUndefined; var mapExisted = typeof Map !== stringUndefined; var promiseExisted = typeof Promise !== stringUndefined; var setExisted = typeof Set !== stringUndefined; var weakMapExisted = typeof WeakMap !== stringUndefined; var dataViewCtorString = toSource(DataView); var mapCtorString = toSource(Map); var promiseCtorString = toSource(Promise); var setCtorString = toSource(Set); var weakMapCtorString = toSource(WeakMap); var getTagWithBugfix = getTag; if ((dataViewExisted && getTag(new DataView(new ArrayBuffer(1))) !== dataViewTag) || (mapExisted && getTag(new Map()) !== mapTag) || (promiseExisted && getTag(Promise.resolve()) !== promiseTag) || (setExisted && getTag(new Set()) !== setTag) || (weakMapExisted && getTag(new WeakMap()) !== weakMapTag)) { getTagWithBugfix = function (value) { var result = getTag(value); var Ctor = result === objectTag ? value.constructor : nativeUndefined; var ctorString = Ctor ? toSource(Ctor) : ''; if (ctorString) { switch (ctorString) { case dataViewCtorString: return dataViewTag; case mapCtorString: return mapTag; case promiseCtorString: return promiseTag; case setCtorString: return setTag; case weakMapCtorString: return weakMapTag; } } return result; }; } var getTagWithBugfix$1 = getTagWithBugfix; export { getTagWithBugfix$1 as default };