New source found from dndbeyond.com
This commit is contained in:
+11
@@ -0,0 +1,11 @@
|
||||
'use strict';
|
||||
var isConstructor = require('../internals/is-constructor');
|
||||
var tryToString = require('../internals/try-to-string');
|
||||
|
||||
var $TypeError = TypeError;
|
||||
|
||||
// `Assert: IsConstructor(argument) is true`
|
||||
module.exports = function (argument) {
|
||||
if (isConstructor(argument)) return argument;
|
||||
throw new $TypeError(tryToString(argument) + ' is not a constructor');
|
||||
};
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
var classof = require('../internals/classof');
|
||||
|
||||
var $TypeError = TypeError;
|
||||
|
||||
module.exports = function (argument) {
|
||||
if (classof(argument) === 'DataView') return argument;
|
||||
throw new $TypeError('Argument is not a DataView');
|
||||
};
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
'use strict';
|
||||
var has = require('../internals/map-helpers').has;
|
||||
|
||||
// Perform ? RequireInternalSlot(M, [[MapData]])
|
||||
module.exports = function (it) {
|
||||
has(it);
|
||||
return it;
|
||||
};
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
'use strict';
|
||||
var has = require('../internals/set-helpers').has;
|
||||
|
||||
// Perform ? RequireInternalSlot(M, [[SetData]])
|
||||
module.exports = function (it) {
|
||||
has(it);
|
||||
return it;
|
||||
};
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
'use strict';
|
||||
var $TypeError = TypeError;
|
||||
|
||||
module.exports = function (argument) {
|
||||
if (typeof argument == 'string') return argument;
|
||||
throw new $TypeError('Argument is not a string');
|
||||
};
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
'use strict';
|
||||
var WeakMapHelpers = require('../internals/weak-map-helpers');
|
||||
|
||||
var weakmap = new WeakMapHelpers.WeakMap();
|
||||
var set = WeakMapHelpers.set;
|
||||
var remove = WeakMapHelpers.remove;
|
||||
|
||||
module.exports = function (key) {
|
||||
set(weakmap, key, 1);
|
||||
remove(weakmap, key);
|
||||
return key;
|
||||
};
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
'use strict';
|
||||
var has = require('../internals/weak-map-helpers').has;
|
||||
|
||||
// Perform ? RequireInternalSlot(M, [[WeakMapData]])
|
||||
module.exports = function (it) {
|
||||
has(it);
|
||||
return it;
|
||||
};
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
'use strict';
|
||||
var getBuiltIn = require('../internals/get-built-in');
|
||||
var call = require('../internals/function-call');
|
||||
var uncurryThis = require('../internals/function-uncurry-this');
|
||||
var bind = require('../internals/function-bind-context');
|
||||
var anObject = require('../internals/an-object');
|
||||
var aCallable = require('../internals/a-callable');
|
||||
var isNullOrUndefined = require('../internals/is-null-or-undefined');
|
||||
var getMethod = require('../internals/get-method');
|
||||
var wellKnownSymbol = require('../internals/well-known-symbol');
|
||||
|
||||
var ASYNC_DISPOSE = wellKnownSymbol('asyncDispose');
|
||||
var DISPOSE = wellKnownSymbol('dispose');
|
||||
|
||||
var push = uncurryThis([].push);
|
||||
|
||||
// `GetDisposeMethod` abstract operation
|
||||
// https://tc39.es/proposal-explicit-resource-management/#sec-getdisposemethod
|
||||
var getDisposeMethod = function (V, hint) {
|
||||
if (hint === 'async-dispose') {
|
||||
var method = getMethod(V, ASYNC_DISPOSE);
|
||||
if (method !== undefined) return method;
|
||||
method = getMethod(V, DISPOSE);
|
||||
if (method === undefined) return method;
|
||||
return function () {
|
||||
var O = this;
|
||||
var Promise = getBuiltIn('Promise');
|
||||
return new Promise(function (resolve) {
|
||||
call(method, O);
|
||||
resolve(undefined);
|
||||
});
|
||||
};
|
||||
} return getMethod(V, DISPOSE);
|
||||
};
|
||||
|
||||
// `CreateDisposableResource` abstract operation
|
||||
// https://tc39.es/proposal-explicit-resource-management/#sec-createdisposableresource
|
||||
var createDisposableResource = function (V, hint, method) {
|
||||
if (arguments.length < 3 && !isNullOrUndefined(V)) {
|
||||
method = aCallable(getDisposeMethod(anObject(V), hint));
|
||||
}
|
||||
|
||||
return method === undefined ? function () {
|
||||
return undefined;
|
||||
} : bind(method, V);
|
||||
};
|
||||
|
||||
// `AddDisposableResource` abstract operation
|
||||
// https://tc39.es/proposal-explicit-resource-management/#sec-adddisposableresource
|
||||
module.exports = function (disposable, V, hint, method) {
|
||||
var resource;
|
||||
if (arguments.length < 4) {
|
||||
// When `V`` is either `null` or `undefined` and hint is `async-dispose`,
|
||||
// we record that the resource was evaluated to ensure we will still perform an `Await` when resources are later disposed.
|
||||
if (isNullOrUndefined(V) && hint === 'sync-dispose') return;
|
||||
resource = createDisposableResource(V, hint);
|
||||
} else {
|
||||
resource = createDisposableResource(undefined, hint, method);
|
||||
}
|
||||
|
||||
push(disposable.stack, resource);
|
||||
};
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
'use strict';
|
||||
var charAt = require('../internals/string-multibyte').charAt;
|
||||
|
||||
// `AdvanceStringIndex` abstract operation
|
||||
// https://tc39.es/ecma262/#sec-advancestringindex
|
||||
module.exports = function (S, index, unicode) {
|
||||
return index + (unicode ? charAt(S, index).length : 1);
|
||||
};
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
'use strict';
|
||||
var isObject = require('../internals/is-object');
|
||||
|
||||
var $String = String;
|
||||
var $TypeError = TypeError;
|
||||
|
||||
module.exports = function (argument) {
|
||||
if (argument === undefined || isObject(argument)) return argument;
|
||||
throw new $TypeError($String(argument) + ' is not an object or undefined');
|
||||
};
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
'use strict';
|
||||
var classof = require('../internals/classof');
|
||||
|
||||
var $TypeError = TypeError;
|
||||
|
||||
// Perform ? RequireInternalSlot(argument, [[TypedArrayName]])
|
||||
// If argument.[[TypedArrayName]] is not "Uint8Array", throw a TypeError exception
|
||||
module.exports = function (argument) {
|
||||
if (classof(argument) === 'Uint8Array') return argument;
|
||||
throw new $TypeError('Argument is not an Uint8Array');
|
||||
};
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
'use strict';
|
||||
// eslint-disable-next-line es/no-typed-arrays -- safe
|
||||
module.exports = typeof ArrayBuffer != 'undefined' && typeof DataView != 'undefined';
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
'use strict';
|
||||
var globalThis = require('../internals/global-this');
|
||||
var uncurryThisAccessor = require('../internals/function-uncurry-this-accessor');
|
||||
var classof = require('../internals/classof-raw');
|
||||
|
||||
var ArrayBuffer = globalThis.ArrayBuffer;
|
||||
var TypeError = globalThis.TypeError;
|
||||
|
||||
// Includes
|
||||
// - Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
|
||||
// - If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
|
||||
module.exports = ArrayBuffer && uncurryThisAccessor(ArrayBuffer.prototype, 'byteLength', 'get') || function (O) {
|
||||
if (classof(O) !== 'ArrayBuffer') throw new TypeError('ArrayBuffer expected');
|
||||
return O.byteLength;
|
||||
};
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
'use strict';
|
||||
var globalThis = require('../internals/global-this');
|
||||
var NATIVE_ARRAY_BUFFER = require('../internals/array-buffer-basic-detection');
|
||||
var arrayBufferByteLength = require('../internals/array-buffer-byte-length');
|
||||
|
||||
var DataView = globalThis.DataView;
|
||||
|
||||
module.exports = function (O) {
|
||||
if (!NATIVE_ARRAY_BUFFER || arrayBufferByteLength(O) !== 0) return false;
|
||||
try {
|
||||
// eslint-disable-next-line no-new -- thrower
|
||||
new DataView(O);
|
||||
return false;
|
||||
} catch (error) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
'use strict';
|
||||
// FF26- bug: ArrayBuffers are non-extensible, but Object.isExtensible does not report it
|
||||
var fails = require('../internals/fails');
|
||||
|
||||
module.exports = fails(function () {
|
||||
if (typeof ArrayBuffer == 'function') {
|
||||
var buffer = new ArrayBuffer(8);
|
||||
// eslint-disable-next-line es/no-object-isextensible, es/no-object-defineproperty -- safe
|
||||
if (Object.isExtensible(buffer)) Object.defineProperty(buffer, 'a', { value: 8 });
|
||||
}
|
||||
});
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
var isDetached = require('../internals/array-buffer-is-detached');
|
||||
|
||||
var $TypeError = TypeError;
|
||||
|
||||
module.exports = function (it) {
|
||||
if (isDetached(it)) throw new $TypeError('ArrayBuffer is detached');
|
||||
return it;
|
||||
};
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
'use strict';
|
||||
var globalThis = require('../internals/global-this');
|
||||
var uncurryThis = require('../internals/function-uncurry-this');
|
||||
var uncurryThisAccessor = require('../internals/function-uncurry-this-accessor');
|
||||
var toIndex = require('../internals/to-index');
|
||||
var notDetached = require('../internals/array-buffer-not-detached');
|
||||
var arrayBufferByteLength = require('../internals/array-buffer-byte-length');
|
||||
var detachTransferable = require('../internals/detach-transferable');
|
||||
var PROPER_STRUCTURED_CLONE_TRANSFER = require('../internals/structured-clone-proper-transfer');
|
||||
|
||||
var structuredClone = globalThis.structuredClone;
|
||||
var ArrayBuffer = globalThis.ArrayBuffer;
|
||||
var DataView = globalThis.DataView;
|
||||
var min = Math.min;
|
||||
var ArrayBufferPrototype = ArrayBuffer.prototype;
|
||||
var DataViewPrototype = DataView.prototype;
|
||||
var slice = uncurryThis(ArrayBufferPrototype.slice);
|
||||
var isResizable = uncurryThisAccessor(ArrayBufferPrototype, 'resizable', 'get');
|
||||
var maxByteLength = uncurryThisAccessor(ArrayBufferPrototype, 'maxByteLength', 'get');
|
||||
var getInt8 = uncurryThis(DataViewPrototype.getInt8);
|
||||
var setInt8 = uncurryThis(DataViewPrototype.setInt8);
|
||||
|
||||
module.exports = (PROPER_STRUCTURED_CLONE_TRANSFER || detachTransferable) && function (arrayBuffer, newLength, preserveResizability) {
|
||||
var byteLength = arrayBufferByteLength(arrayBuffer);
|
||||
var newByteLength = newLength === undefined ? byteLength : toIndex(newLength);
|
||||
var fixedLength = !isResizable || !isResizable(arrayBuffer);
|
||||
var newBuffer;
|
||||
notDetached(arrayBuffer);
|
||||
if (PROPER_STRUCTURED_CLONE_TRANSFER) {
|
||||
arrayBuffer = structuredClone(arrayBuffer, { transfer: [arrayBuffer] });
|
||||
if (byteLength === newByteLength && (preserveResizability || fixedLength)) return arrayBuffer;
|
||||
}
|
||||
if (byteLength >= newByteLength && (!preserveResizability || fixedLength)) {
|
||||
newBuffer = slice(arrayBuffer, 0, newByteLength);
|
||||
} else {
|
||||
var options = preserveResizability && !fixedLength && maxByteLength ? { maxByteLength: maxByteLength(arrayBuffer) } : undefined;
|
||||
newBuffer = new ArrayBuffer(newByteLength, options);
|
||||
var a = new DataView(arrayBuffer);
|
||||
var b = new DataView(newBuffer);
|
||||
var copyLength = min(newByteLength, byteLength);
|
||||
for (var i = 0; i < copyLength; i++) setInt8(b, i, getInt8(a, i));
|
||||
}
|
||||
if (!PROPER_STRUCTURED_CLONE_TRANSFER) detachTransferable(arrayBuffer);
|
||||
return newBuffer;
|
||||
};
|
||||
+193
@@ -0,0 +1,193 @@
|
||||
'use strict';
|
||||
var NATIVE_ARRAY_BUFFER = require('../internals/array-buffer-basic-detection');
|
||||
var DESCRIPTORS = require('../internals/descriptors');
|
||||
var globalThis = require('../internals/global-this');
|
||||
var isCallable = require('../internals/is-callable');
|
||||
var isObject = require('../internals/is-object');
|
||||
var hasOwn = require('../internals/has-own-property');
|
||||
var classof = require('../internals/classof');
|
||||
var tryToString = require('../internals/try-to-string');
|
||||
var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
|
||||
var defineBuiltIn = require('../internals/define-built-in');
|
||||
var defineBuiltInAccessor = require('../internals/define-built-in-accessor');
|
||||
var isPrototypeOf = require('../internals/object-is-prototype-of');
|
||||
var getPrototypeOf = require('../internals/object-get-prototype-of');
|
||||
var setPrototypeOf = require('../internals/object-set-prototype-of');
|
||||
var wellKnownSymbol = require('../internals/well-known-symbol');
|
||||
var uid = require('../internals/uid');
|
||||
var InternalStateModule = require('../internals/internal-state');
|
||||
|
||||
var enforceInternalState = InternalStateModule.enforce;
|
||||
var getInternalState = InternalStateModule.get;
|
||||
var Int8Array = globalThis.Int8Array;
|
||||
var Int8ArrayPrototype = Int8Array && Int8Array.prototype;
|
||||
var Uint8ClampedArray = globalThis.Uint8ClampedArray;
|
||||
var Uint8ClampedArrayPrototype = Uint8ClampedArray && Uint8ClampedArray.prototype;
|
||||
var TypedArray = Int8Array && getPrototypeOf(Int8Array);
|
||||
var TypedArrayPrototype = Int8ArrayPrototype && getPrototypeOf(Int8ArrayPrototype);
|
||||
var ObjectPrototype = Object.prototype;
|
||||
var TypeError = globalThis.TypeError;
|
||||
|
||||
var TO_STRING_TAG = wellKnownSymbol('toStringTag');
|
||||
var TYPED_ARRAY_TAG = uid('TYPED_ARRAY_TAG');
|
||||
var TYPED_ARRAY_CONSTRUCTOR = 'TypedArrayConstructor';
|
||||
// Fixing native typed arrays in Opera Presto crashes the browser, see #595
|
||||
var NATIVE_ARRAY_BUFFER_VIEWS = NATIVE_ARRAY_BUFFER && !!setPrototypeOf && classof(globalThis.opera) !== 'Opera';
|
||||
var TYPED_ARRAY_TAG_REQUIRED = false;
|
||||
var NAME, Constructor, Prototype;
|
||||
|
||||
var TypedArrayConstructorsList = {
|
||||
Int8Array: 1,
|
||||
Uint8Array: 1,
|
||||
Uint8ClampedArray: 1,
|
||||
Int16Array: 2,
|
||||
Uint16Array: 2,
|
||||
Int32Array: 4,
|
||||
Uint32Array: 4,
|
||||
Float32Array: 4,
|
||||
Float64Array: 8
|
||||
};
|
||||
|
||||
var BigIntArrayConstructorsList = {
|
||||
BigInt64Array: 8,
|
||||
BigUint64Array: 8
|
||||
};
|
||||
|
||||
var isView = function isView(it) {
|
||||
if (!isObject(it)) return false;
|
||||
var klass = classof(it);
|
||||
return klass === 'DataView'
|
||||
|| hasOwn(TypedArrayConstructorsList, klass)
|
||||
|| hasOwn(BigIntArrayConstructorsList, klass);
|
||||
};
|
||||
|
||||
var getTypedArrayConstructor = function (it) {
|
||||
var proto = getPrototypeOf(it);
|
||||
if (!isObject(proto)) return;
|
||||
var state = getInternalState(proto);
|
||||
return (state && hasOwn(state, TYPED_ARRAY_CONSTRUCTOR)) ? state[TYPED_ARRAY_CONSTRUCTOR] : getTypedArrayConstructor(proto);
|
||||
};
|
||||
|
||||
var isTypedArray = function (it) {
|
||||
if (!isObject(it)) return false;
|
||||
var klass = classof(it);
|
||||
return hasOwn(TypedArrayConstructorsList, klass)
|
||||
|| hasOwn(BigIntArrayConstructorsList, klass);
|
||||
};
|
||||
|
||||
var aTypedArray = function (it) {
|
||||
if (isTypedArray(it)) return it;
|
||||
throw new TypeError('Target is not a typed array');
|
||||
};
|
||||
|
||||
var aTypedArrayConstructor = function (C) {
|
||||
if (isCallable(C) && (!setPrototypeOf || isPrototypeOf(TypedArray, C))) return C;
|
||||
throw new TypeError(tryToString(C) + ' is not a typed array constructor');
|
||||
};
|
||||
|
||||
var exportTypedArrayMethod = function (KEY, property, forced, options) {
|
||||
if (!DESCRIPTORS) return;
|
||||
if (forced) for (var ARRAY in TypedArrayConstructorsList) {
|
||||
var TypedArrayConstructor = globalThis[ARRAY];
|
||||
if (TypedArrayConstructor && hasOwn(TypedArrayConstructor.prototype, KEY)) try {
|
||||
delete TypedArrayConstructor.prototype[KEY];
|
||||
} catch (error) {
|
||||
// old WebKit bug - some methods are non-configurable
|
||||
try {
|
||||
TypedArrayConstructor.prototype[KEY] = property;
|
||||
} catch (error2) { /* empty */ }
|
||||
}
|
||||
}
|
||||
if (!TypedArrayPrototype[KEY] || forced) {
|
||||
defineBuiltIn(TypedArrayPrototype, KEY, forced ? property
|
||||
: NATIVE_ARRAY_BUFFER_VIEWS && Int8ArrayPrototype[KEY] || property, options);
|
||||
}
|
||||
};
|
||||
|
||||
var exportTypedArrayStaticMethod = function (KEY, property, forced) {
|
||||
var ARRAY, TypedArrayConstructor;
|
||||
if (!DESCRIPTORS) return;
|
||||
if (setPrototypeOf) {
|
||||
if (forced) for (ARRAY in TypedArrayConstructorsList) {
|
||||
TypedArrayConstructor = globalThis[ARRAY];
|
||||
if (TypedArrayConstructor && hasOwn(TypedArrayConstructor, KEY)) try {
|
||||
delete TypedArrayConstructor[KEY];
|
||||
} catch (error) { /* empty */ }
|
||||
}
|
||||
if (!TypedArray[KEY] || forced) {
|
||||
// V8 ~ Chrome 49-50 `%TypedArray%` methods are non-writable non-configurable
|
||||
try {
|
||||
return defineBuiltIn(TypedArray, KEY, forced ? property : NATIVE_ARRAY_BUFFER_VIEWS && TypedArray[KEY] || property);
|
||||
} catch (error) { /* empty */ }
|
||||
} else return;
|
||||
}
|
||||
for (ARRAY in TypedArrayConstructorsList) {
|
||||
TypedArrayConstructor = globalThis[ARRAY];
|
||||
if (TypedArrayConstructor && (!TypedArrayConstructor[KEY] || forced)) {
|
||||
defineBuiltIn(TypedArrayConstructor, KEY, property);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
for (NAME in TypedArrayConstructorsList) {
|
||||
Constructor = globalThis[NAME];
|
||||
Prototype = Constructor && Constructor.prototype;
|
||||
if (Prototype) enforceInternalState(Prototype)[TYPED_ARRAY_CONSTRUCTOR] = Constructor;
|
||||
else NATIVE_ARRAY_BUFFER_VIEWS = false;
|
||||
}
|
||||
|
||||
for (NAME in BigIntArrayConstructorsList) {
|
||||
Constructor = globalThis[NAME];
|
||||
Prototype = Constructor && Constructor.prototype;
|
||||
if (Prototype) enforceInternalState(Prototype)[TYPED_ARRAY_CONSTRUCTOR] = Constructor;
|
||||
}
|
||||
|
||||
// WebKit bug - typed arrays constructors prototype is Object.prototype
|
||||
if (!NATIVE_ARRAY_BUFFER_VIEWS || !isCallable(TypedArray) || TypedArray === Function.prototype) {
|
||||
// eslint-disable-next-line no-shadow -- safe
|
||||
TypedArray = function TypedArray() {
|
||||
throw new TypeError('Incorrect invocation');
|
||||
};
|
||||
if (NATIVE_ARRAY_BUFFER_VIEWS) for (NAME in TypedArrayConstructorsList) {
|
||||
if (globalThis[NAME]) setPrototypeOf(globalThis[NAME], TypedArray);
|
||||
}
|
||||
}
|
||||
|
||||
if (!NATIVE_ARRAY_BUFFER_VIEWS || !TypedArrayPrototype || TypedArrayPrototype === ObjectPrototype) {
|
||||
TypedArrayPrototype = TypedArray.prototype;
|
||||
if (NATIVE_ARRAY_BUFFER_VIEWS) for (NAME in TypedArrayConstructorsList) {
|
||||
if (globalThis[NAME]) setPrototypeOf(globalThis[NAME].prototype, TypedArrayPrototype);
|
||||
}
|
||||
}
|
||||
|
||||
// WebKit bug - one more object in Uint8ClampedArray prototype chain
|
||||
if (NATIVE_ARRAY_BUFFER_VIEWS && getPrototypeOf(Uint8ClampedArrayPrototype) !== TypedArrayPrototype) {
|
||||
setPrototypeOf(Uint8ClampedArrayPrototype, TypedArrayPrototype);
|
||||
}
|
||||
|
||||
if (DESCRIPTORS && !hasOwn(TypedArrayPrototype, TO_STRING_TAG)) {
|
||||
TYPED_ARRAY_TAG_REQUIRED = true;
|
||||
defineBuiltInAccessor(TypedArrayPrototype, TO_STRING_TAG, {
|
||||
configurable: true,
|
||||
get: function () {
|
||||
return isObject(this) ? this[TYPED_ARRAY_TAG] : undefined;
|
||||
}
|
||||
});
|
||||
for (NAME in TypedArrayConstructorsList) if (globalThis[NAME]) {
|
||||
createNonEnumerableProperty(globalThis[NAME], TYPED_ARRAY_TAG, NAME);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
NATIVE_ARRAY_BUFFER_VIEWS: NATIVE_ARRAY_BUFFER_VIEWS,
|
||||
TYPED_ARRAY_TAG: TYPED_ARRAY_TAG_REQUIRED && TYPED_ARRAY_TAG,
|
||||
aTypedArray: aTypedArray,
|
||||
aTypedArrayConstructor: aTypedArrayConstructor,
|
||||
exportTypedArrayMethod: exportTypedArrayMethod,
|
||||
exportTypedArrayStaticMethod: exportTypedArrayStaticMethod,
|
||||
getTypedArrayConstructor: getTypedArrayConstructor,
|
||||
isView: isView,
|
||||
isTypedArray: isTypedArray,
|
||||
TypedArray: TypedArray,
|
||||
TypedArrayPrototype: TypedArrayPrototype
|
||||
};
|
||||
+260
@@ -0,0 +1,260 @@
|
||||
'use strict';
|
||||
var globalThis = require('../internals/global-this');
|
||||
var uncurryThis = require('../internals/function-uncurry-this');
|
||||
var DESCRIPTORS = require('../internals/descriptors');
|
||||
var NATIVE_ARRAY_BUFFER = require('../internals/array-buffer-basic-detection');
|
||||
var FunctionName = require('../internals/function-name');
|
||||
var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
|
||||
var defineBuiltInAccessor = require('../internals/define-built-in-accessor');
|
||||
var defineBuiltIns = require('../internals/define-built-ins');
|
||||
var fails = require('../internals/fails');
|
||||
var anInstance = require('../internals/an-instance');
|
||||
var toIntegerOrInfinity = require('../internals/to-integer-or-infinity');
|
||||
var toLength = require('../internals/to-length');
|
||||
var toIndex = require('../internals/to-index');
|
||||
var fround = require('../internals/math-fround');
|
||||
var IEEE754 = require('../internals/ieee754');
|
||||
var getPrototypeOf = require('../internals/object-get-prototype-of');
|
||||
var setPrototypeOf = require('../internals/object-set-prototype-of');
|
||||
var arrayFill = require('../internals/array-fill');
|
||||
var arraySlice = require('../internals/array-slice');
|
||||
var inheritIfRequired = require('../internals/inherit-if-required');
|
||||
var copyConstructorProperties = require('../internals/copy-constructor-properties');
|
||||
var setToStringTag = require('../internals/set-to-string-tag');
|
||||
var InternalStateModule = require('../internals/internal-state');
|
||||
|
||||
var PROPER_FUNCTION_NAME = FunctionName.PROPER;
|
||||
var CONFIGURABLE_FUNCTION_NAME = FunctionName.CONFIGURABLE;
|
||||
var ARRAY_BUFFER = 'ArrayBuffer';
|
||||
var DATA_VIEW = 'DataView';
|
||||
var PROTOTYPE = 'prototype';
|
||||
var WRONG_LENGTH = 'Wrong length';
|
||||
var WRONG_INDEX = 'Wrong index';
|
||||
var getInternalArrayBufferState = InternalStateModule.getterFor(ARRAY_BUFFER);
|
||||
var getInternalDataViewState = InternalStateModule.getterFor(DATA_VIEW);
|
||||
var setInternalState = InternalStateModule.set;
|
||||
var NativeArrayBuffer = globalThis[ARRAY_BUFFER];
|
||||
var $ArrayBuffer = NativeArrayBuffer;
|
||||
var ArrayBufferPrototype = $ArrayBuffer && $ArrayBuffer[PROTOTYPE];
|
||||
var $DataView = globalThis[DATA_VIEW];
|
||||
var DataViewPrototype = $DataView && $DataView[PROTOTYPE];
|
||||
var ObjectPrototype = Object.prototype;
|
||||
var Array = globalThis.Array;
|
||||
var RangeError = globalThis.RangeError;
|
||||
var fill = uncurryThis(arrayFill);
|
||||
var reverse = uncurryThis([].reverse);
|
||||
|
||||
var packIEEE754 = IEEE754.pack;
|
||||
var unpackIEEE754 = IEEE754.unpack;
|
||||
|
||||
var packInt8 = function (number) {
|
||||
return [number & 0xFF];
|
||||
};
|
||||
|
||||
var packInt16 = function (number) {
|
||||
return [number & 0xFF, number >> 8 & 0xFF];
|
||||
};
|
||||
|
||||
var packInt32 = function (number) {
|
||||
return [number & 0xFF, number >> 8 & 0xFF, number >> 16 & 0xFF, number >> 24 & 0xFF];
|
||||
};
|
||||
|
||||
var unpackInt32 = function (buffer) {
|
||||
return buffer[3] << 24 | buffer[2] << 16 | buffer[1] << 8 | buffer[0];
|
||||
};
|
||||
|
||||
var packFloat32 = function (number) {
|
||||
return packIEEE754(fround(number), 23, 4);
|
||||
};
|
||||
|
||||
var packFloat64 = function (number) {
|
||||
return packIEEE754(number, 52, 8);
|
||||
};
|
||||
|
||||
var addGetter = function (Constructor, key, getInternalState) {
|
||||
defineBuiltInAccessor(Constructor[PROTOTYPE], key, {
|
||||
configurable: true,
|
||||
get: function () {
|
||||
return getInternalState(this)[key];
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var get = function (view, count, index, isLittleEndian) {
|
||||
var store = getInternalDataViewState(view);
|
||||
var intIndex = toIndex(index);
|
||||
var boolIsLittleEndian = !!isLittleEndian;
|
||||
if (intIndex + count > store.byteLength) throw new RangeError(WRONG_INDEX);
|
||||
var bytes = store.bytes;
|
||||
var start = intIndex + store.byteOffset;
|
||||
var pack = arraySlice(bytes, start, start + count);
|
||||
return boolIsLittleEndian ? pack : reverse(pack);
|
||||
};
|
||||
|
||||
var set = function (view, count, index, conversion, value, isLittleEndian) {
|
||||
var store = getInternalDataViewState(view);
|
||||
var intIndex = toIndex(index);
|
||||
var pack = conversion(+value);
|
||||
var boolIsLittleEndian = !!isLittleEndian;
|
||||
if (intIndex + count > store.byteLength) throw new RangeError(WRONG_INDEX);
|
||||
var bytes = store.bytes;
|
||||
var start = intIndex + store.byteOffset;
|
||||
for (var i = 0; i < count; i++) bytes[start + i] = pack[boolIsLittleEndian ? i : count - i - 1];
|
||||
};
|
||||
|
||||
if (!NATIVE_ARRAY_BUFFER) {
|
||||
$ArrayBuffer = function ArrayBuffer(length) {
|
||||
anInstance(this, ArrayBufferPrototype);
|
||||
var byteLength = toIndex(length);
|
||||
setInternalState(this, {
|
||||
type: ARRAY_BUFFER,
|
||||
bytes: fill(Array(byteLength), 0),
|
||||
byteLength: byteLength
|
||||
});
|
||||
if (!DESCRIPTORS) {
|
||||
this.byteLength = byteLength;
|
||||
this.detached = false;
|
||||
}
|
||||
};
|
||||
|
||||
ArrayBufferPrototype = $ArrayBuffer[PROTOTYPE];
|
||||
|
||||
$DataView = function DataView(buffer, byteOffset, byteLength) {
|
||||
anInstance(this, DataViewPrototype);
|
||||
anInstance(buffer, ArrayBufferPrototype);
|
||||
var bufferState = getInternalArrayBufferState(buffer);
|
||||
var bufferLength = bufferState.byteLength;
|
||||
var offset = toIntegerOrInfinity(byteOffset);
|
||||
if (offset < 0 || offset > bufferLength) throw new RangeError('Wrong offset');
|
||||
byteLength = byteLength === undefined ? bufferLength - offset : toLength(byteLength);
|
||||
if (offset + byteLength > bufferLength) throw new RangeError(WRONG_LENGTH);
|
||||
setInternalState(this, {
|
||||
type: DATA_VIEW,
|
||||
buffer: buffer,
|
||||
byteLength: byteLength,
|
||||
byteOffset: offset,
|
||||
bytes: bufferState.bytes
|
||||
});
|
||||
if (!DESCRIPTORS) {
|
||||
this.buffer = buffer;
|
||||
this.byteLength = byteLength;
|
||||
this.byteOffset = offset;
|
||||
}
|
||||
};
|
||||
|
||||
DataViewPrototype = $DataView[PROTOTYPE];
|
||||
|
||||
if (DESCRIPTORS) {
|
||||
addGetter($ArrayBuffer, 'byteLength', getInternalArrayBufferState);
|
||||
addGetter($DataView, 'buffer', getInternalDataViewState);
|
||||
addGetter($DataView, 'byteLength', getInternalDataViewState);
|
||||
addGetter($DataView, 'byteOffset', getInternalDataViewState);
|
||||
}
|
||||
|
||||
defineBuiltIns(DataViewPrototype, {
|
||||
getInt8: function getInt8(byteOffset) {
|
||||
return get(this, 1, byteOffset)[0] << 24 >> 24;
|
||||
},
|
||||
getUint8: function getUint8(byteOffset) {
|
||||
return get(this, 1, byteOffset)[0];
|
||||
},
|
||||
getInt16: function getInt16(byteOffset /* , littleEndian */) {
|
||||
var bytes = get(this, 2, byteOffset, arguments.length > 1 ? arguments[1] : false);
|
||||
return (bytes[1] << 8 | bytes[0]) << 16 >> 16;
|
||||
},
|
||||
getUint16: function getUint16(byteOffset /* , littleEndian */) {
|
||||
var bytes = get(this, 2, byteOffset, arguments.length > 1 ? arguments[1] : false);
|
||||
return bytes[1] << 8 | bytes[0];
|
||||
},
|
||||
getInt32: function getInt32(byteOffset /* , littleEndian */) {
|
||||
return unpackInt32(get(this, 4, byteOffset, arguments.length > 1 ? arguments[1] : false));
|
||||
},
|
||||
getUint32: function getUint32(byteOffset /* , littleEndian */) {
|
||||
return unpackInt32(get(this, 4, byteOffset, arguments.length > 1 ? arguments[1] : false)) >>> 0;
|
||||
},
|
||||
getFloat32: function getFloat32(byteOffset /* , littleEndian */) {
|
||||
return unpackIEEE754(get(this, 4, byteOffset, arguments.length > 1 ? arguments[1] : false), 23);
|
||||
},
|
||||
getFloat64: function getFloat64(byteOffset /* , littleEndian */) {
|
||||
return unpackIEEE754(get(this, 8, byteOffset, arguments.length > 1 ? arguments[1] : false), 52);
|
||||
},
|
||||
setInt8: function setInt8(byteOffset, value) {
|
||||
set(this, 1, byteOffset, packInt8, value);
|
||||
},
|
||||
setUint8: function setUint8(byteOffset, value) {
|
||||
set(this, 1, byteOffset, packInt8, value);
|
||||
},
|
||||
setInt16: function setInt16(byteOffset, value /* , littleEndian */) {
|
||||
set(this, 2, byteOffset, packInt16, value, arguments.length > 2 ? arguments[2] : false);
|
||||
},
|
||||
setUint16: function setUint16(byteOffset, value /* , littleEndian */) {
|
||||
set(this, 2, byteOffset, packInt16, value, arguments.length > 2 ? arguments[2] : false);
|
||||
},
|
||||
setInt32: function setInt32(byteOffset, value /* , littleEndian */) {
|
||||
set(this, 4, byteOffset, packInt32, value, arguments.length > 2 ? arguments[2] : false);
|
||||
},
|
||||
setUint32: function setUint32(byteOffset, value /* , littleEndian */) {
|
||||
set(this, 4, byteOffset, packInt32, value, arguments.length > 2 ? arguments[2] : false);
|
||||
},
|
||||
setFloat32: function setFloat32(byteOffset, value /* , littleEndian */) {
|
||||
set(this, 4, byteOffset, packFloat32, value, arguments.length > 2 ? arguments[2] : false);
|
||||
},
|
||||
setFloat64: function setFloat64(byteOffset, value /* , littleEndian */) {
|
||||
set(this, 8, byteOffset, packFloat64, value, arguments.length > 2 ? arguments[2] : false);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
var INCORRECT_ARRAY_BUFFER_NAME = PROPER_FUNCTION_NAME && NativeArrayBuffer.name !== ARRAY_BUFFER;
|
||||
/* eslint-disable no-new, sonarjs/inconsistent-function-call -- required for testing */
|
||||
if (!fails(function () {
|
||||
NativeArrayBuffer(1);
|
||||
}) || !fails(function () {
|
||||
new NativeArrayBuffer(-1);
|
||||
}) || fails(function () {
|
||||
new NativeArrayBuffer();
|
||||
new NativeArrayBuffer(1.5);
|
||||
new NativeArrayBuffer(NaN);
|
||||
return NativeArrayBuffer.length !== 1 || INCORRECT_ARRAY_BUFFER_NAME && !CONFIGURABLE_FUNCTION_NAME;
|
||||
})) {
|
||||
/* eslint-enable no-new, sonarjs/inconsistent-function-call -- required for testing */
|
||||
$ArrayBuffer = function ArrayBuffer(length) {
|
||||
anInstance(this, ArrayBufferPrototype);
|
||||
return inheritIfRequired(new NativeArrayBuffer(toIndex(length)), this, $ArrayBuffer);
|
||||
};
|
||||
|
||||
$ArrayBuffer[PROTOTYPE] = ArrayBufferPrototype;
|
||||
|
||||
ArrayBufferPrototype.constructor = $ArrayBuffer;
|
||||
|
||||
copyConstructorProperties($ArrayBuffer, NativeArrayBuffer);
|
||||
} else if (INCORRECT_ARRAY_BUFFER_NAME && CONFIGURABLE_FUNCTION_NAME) {
|
||||
createNonEnumerableProperty(NativeArrayBuffer, 'name', ARRAY_BUFFER);
|
||||
}
|
||||
|
||||
// WebKit bug - the same parent prototype for typed arrays and data view
|
||||
if (setPrototypeOf && getPrototypeOf(DataViewPrototype) !== ObjectPrototype) {
|
||||
setPrototypeOf(DataViewPrototype, ObjectPrototype);
|
||||
}
|
||||
|
||||
// iOS Safari 7.x bug
|
||||
var testView = new $DataView(new $ArrayBuffer(2));
|
||||
var $setInt8 = uncurryThis(DataViewPrototype.setInt8);
|
||||
testView.setInt8(0, 2147483648);
|
||||
testView.setInt8(1, 2147483649);
|
||||
if (testView.getInt8(0) || !testView.getInt8(1)) defineBuiltIns(DataViewPrototype, {
|
||||
setInt8: function setInt8(byteOffset, value) {
|
||||
$setInt8(this, byteOffset, value << 24 >> 24);
|
||||
},
|
||||
setUint8: function setUint8(byteOffset, value) {
|
||||
$setInt8(this, byteOffset, value << 24 >> 24);
|
||||
}
|
||||
}, { unsafe: true });
|
||||
}
|
||||
|
||||
setToStringTag($ArrayBuffer, ARRAY_BUFFER);
|
||||
setToStringTag($DataView, DATA_VIEW);
|
||||
|
||||
module.exports = {
|
||||
ArrayBuffer: $ArrayBuffer,
|
||||
DataView: $DataView
|
||||
};
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
'use strict';
|
||||
var toObject = require('../internals/to-object');
|
||||
var toAbsoluteIndex = require('../internals/to-absolute-index');
|
||||
var lengthOfArrayLike = require('../internals/length-of-array-like');
|
||||
var deletePropertyOrThrow = require('../internals/delete-property-or-throw');
|
||||
|
||||
var min = Math.min;
|
||||
|
||||
// `Array.prototype.copyWithin` method implementation
|
||||
// https://tc39.es/ecma262/#sec-array.prototype.copywithin
|
||||
// eslint-disable-next-line es/no-array-prototype-copywithin -- safe
|
||||
module.exports = [].copyWithin || function copyWithin(target /* = 0 */, start /* = 0, end = @length */) {
|
||||
var O = toObject(this);
|
||||
var len = lengthOfArrayLike(O);
|
||||
var to = toAbsoluteIndex(target, len);
|
||||
var from = toAbsoluteIndex(start, len);
|
||||
var end = arguments.length > 2 ? arguments[2] : undefined;
|
||||
var count = min((end === undefined ? len : toAbsoluteIndex(end, len)) - from, len - to);
|
||||
var inc = 1;
|
||||
if (from < to && to < from + count) {
|
||||
inc = -1;
|
||||
from += count - 1;
|
||||
to += count - 1;
|
||||
}
|
||||
while (count-- > 0) {
|
||||
if (from in O) O[to] = O[from];
|
||||
else deletePropertyOrThrow(O, to);
|
||||
to += inc;
|
||||
from += inc;
|
||||
} return O;
|
||||
};
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
'use strict';
|
||||
var toObject = require('../internals/to-object');
|
||||
var toAbsoluteIndex = require('../internals/to-absolute-index');
|
||||
var lengthOfArrayLike = require('../internals/length-of-array-like');
|
||||
|
||||
// `Array.prototype.fill` method implementation
|
||||
// https://tc39.es/ecma262/#sec-array.prototype.fill
|
||||
module.exports = function fill(value /* , start = 0, end = @length */) {
|
||||
var O = toObject(this);
|
||||
var length = lengthOfArrayLike(O);
|
||||
var argumentsLength = arguments.length;
|
||||
var index = toAbsoluteIndex(argumentsLength > 1 ? arguments[1] : undefined, length);
|
||||
var end = argumentsLength > 2 ? arguments[2] : undefined;
|
||||
var endPos = end === undefined ? length : toAbsoluteIndex(end, length);
|
||||
while (endPos > index) O[index++] = value;
|
||||
return O;
|
||||
};
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
'use strict';
|
||||
var $forEach = require('../internals/array-iteration').forEach;
|
||||
var arrayMethodIsStrict = require('../internals/array-method-is-strict');
|
||||
|
||||
var STRICT_METHOD = arrayMethodIsStrict('forEach');
|
||||
|
||||
// `Array.prototype.forEach` method implementation
|
||||
// https://tc39.es/ecma262/#sec-array.prototype.foreach
|
||||
module.exports = !STRICT_METHOD ? function forEach(callbackfn /* , thisArg */) {
|
||||
return $forEach(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined);
|
||||
// eslint-disable-next-line es/no-array-prototype-foreach -- safe
|
||||
} : [].forEach;
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
'use strict';
|
||||
var bind = require('../internals/function-bind-context');
|
||||
var uncurryThis = require('../internals/function-uncurry-this');
|
||||
var toObject = require('../internals/to-object');
|
||||
var isConstructor = require('../internals/is-constructor');
|
||||
var getAsyncIterator = require('../internals/get-async-iterator');
|
||||
var getIterator = require('../internals/get-iterator');
|
||||
var getIteratorDirect = require('../internals/get-iterator-direct');
|
||||
var getIteratorMethod = require('../internals/get-iterator-method');
|
||||
var getMethod = require('../internals/get-method');
|
||||
var getBuiltIn = require('../internals/get-built-in');
|
||||
var getBuiltInPrototypeMethod = require('../internals/get-built-in-prototype-method');
|
||||
var wellKnownSymbol = require('../internals/well-known-symbol');
|
||||
var AsyncFromSyncIterator = require('../internals/async-from-sync-iterator');
|
||||
var toArray = require('../internals/async-iterator-iteration').toArray;
|
||||
|
||||
var ASYNC_ITERATOR = wellKnownSymbol('asyncIterator');
|
||||
var arrayIterator = uncurryThis(getBuiltInPrototypeMethod('Array', 'values'));
|
||||
var arrayIteratorNext = uncurryThis(arrayIterator([]).next);
|
||||
|
||||
var safeArrayIterator = function () {
|
||||
return new SafeArrayIterator(this);
|
||||
};
|
||||
|
||||
var SafeArrayIterator = function (O) {
|
||||
this.iterator = arrayIterator(O);
|
||||
};
|
||||
|
||||
SafeArrayIterator.prototype.next = function () {
|
||||
return arrayIteratorNext(this.iterator);
|
||||
};
|
||||
|
||||
// `Array.fromAsync` method implementation
|
||||
// https://github.com/tc39/proposal-array-from-async
|
||||
module.exports = function fromAsync(asyncItems /* , mapfn = undefined, thisArg = undefined */) {
|
||||
var C = this;
|
||||
var argumentsLength = arguments.length;
|
||||
var mapfn = argumentsLength > 1 ? arguments[1] : undefined;
|
||||
var thisArg = argumentsLength > 2 ? arguments[2] : undefined;
|
||||
return new (getBuiltIn('Promise'))(function (resolve) {
|
||||
var O = toObject(asyncItems);
|
||||
if (mapfn !== undefined) mapfn = bind(mapfn, thisArg);
|
||||
var usingAsyncIterator = getMethod(O, ASYNC_ITERATOR);
|
||||
var usingSyncIterator = usingAsyncIterator ? undefined : getIteratorMethod(O) || safeArrayIterator;
|
||||
var A = isConstructor(C) ? new C() : [];
|
||||
var iterator = usingAsyncIterator
|
||||
? getAsyncIterator(O, usingAsyncIterator)
|
||||
: new AsyncFromSyncIterator(getIteratorDirect(getIterator(O, usingSyncIterator)));
|
||||
resolve(toArray(iterator, mapfn, A));
|
||||
});
|
||||
};
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
'use strict';
|
||||
var lengthOfArrayLike = require('../internals/length-of-array-like');
|
||||
|
||||
module.exports = function (Constructor, list, $length) {
|
||||
var index = 0;
|
||||
var length = arguments.length > 2 ? $length : lengthOfArrayLike(list);
|
||||
var result = new Constructor(length);
|
||||
while (length > index) result[index] = list[index++];
|
||||
return result;
|
||||
};
|
||||
+2
-1
@@ -7,6 +7,7 @@ var isArrayIteratorMethod = require('../internals/is-array-iterator-method');
|
||||
var isConstructor = require('../internals/is-constructor');
|
||||
var lengthOfArrayLike = require('../internals/length-of-array-like');
|
||||
var createProperty = require('../internals/create-property');
|
||||
var setArrayLength = require('../internals/array-set-length');
|
||||
var getIterator = require('../internals/get-iterator');
|
||||
var getIteratorMethod = require('../internals/get-iterator-method');
|
||||
|
||||
@@ -41,6 +42,6 @@ module.exports = function from(arrayLike /* , mapfn = undefined, thisArg = undef
|
||||
createProperty(result, index, value);
|
||||
}
|
||||
}
|
||||
result.length = index;
|
||||
setArrayLength(result, index);
|
||||
return result;
|
||||
};
|
||||
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
'use strict';
|
||||
var bind = require('../internals/function-bind-context');
|
||||
var IndexedObject = require('../internals/indexed-object');
|
||||
var toObject = require('../internals/to-object');
|
||||
var lengthOfArrayLike = require('../internals/length-of-array-like');
|
||||
|
||||
// `Array.prototype.{ findLast, findLastIndex }` methods implementation
|
||||
var createMethod = function (TYPE) {
|
||||
var IS_FIND_LAST_INDEX = TYPE === 1;
|
||||
return function ($this, callbackfn, that) {
|
||||
var O = toObject($this);
|
||||
var self = IndexedObject(O);
|
||||
var index = lengthOfArrayLike(self);
|
||||
var boundFunction = bind(callbackfn, that);
|
||||
var value, result;
|
||||
while (index-- > 0) {
|
||||
value = self[index];
|
||||
result = boundFunction(value, index, O);
|
||||
if (result) switch (TYPE) {
|
||||
case 0: return value; // findLast
|
||||
case 1: return index; // findLastIndex
|
||||
}
|
||||
}
|
||||
return IS_FIND_LAST_INDEX ? -1 : undefined;
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
// `Array.prototype.findLast` method
|
||||
// https://github.com/tc39/proposal-array-find-from-last
|
||||
findLast: createMethod(0),
|
||||
// `Array.prototype.findLastIndex` method
|
||||
// https://github.com/tc39/proposal-array-find-from-last
|
||||
findLastIndex: createMethod(1)
|
||||
};
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
'use strict';
|
||||
var bind = require('../internals/function-bind-context');
|
||||
var IndexedObject = require('../internals/indexed-object');
|
||||
var toObject = require('../internals/to-object');
|
||||
var lengthOfArrayLike = require('../internals/length-of-array-like');
|
||||
var arraySpeciesCreate = require('../internals/array-species-create');
|
||||
var createProperty = require('../internals/create-property');
|
||||
|
||||
// `Array.prototype.{ forEach, map, filter, some, every, find, findIndex, filterReject }` methods implementation
|
||||
var createMethod = function (TYPE) {
|
||||
var IS_MAP = TYPE === 1;
|
||||
var IS_FILTER = TYPE === 2;
|
||||
var IS_SOME = TYPE === 3;
|
||||
var IS_EVERY = TYPE === 4;
|
||||
var IS_FIND_INDEX = TYPE === 6;
|
||||
var IS_FILTER_REJECT = TYPE === 7;
|
||||
var NO_HOLES = TYPE === 5 || IS_FIND_INDEX;
|
||||
return function ($this, callbackfn, that) {
|
||||
var O = toObject($this);
|
||||
var self = IndexedObject(O);
|
||||
var length = lengthOfArrayLike(self);
|
||||
var boundFunction = bind(callbackfn, that);
|
||||
var index = 0;
|
||||
var resIndex = 0;
|
||||
var target = IS_MAP ? arraySpeciesCreate($this, length) : IS_FILTER || IS_FILTER_REJECT ? arraySpeciesCreate($this, 0) : undefined;
|
||||
var value, result;
|
||||
for (;length > index; index++) if (NO_HOLES || index in self) {
|
||||
value = self[index];
|
||||
result = boundFunction(value, index, O);
|
||||
if (TYPE) {
|
||||
if (IS_MAP) createProperty(target, index, result); // map
|
||||
else if (result) switch (TYPE) {
|
||||
case 3: return true; // some
|
||||
case 5: return value; // find
|
||||
case 6: return index; // findIndex
|
||||
case 2: createProperty(target, resIndex++, value); // filter
|
||||
} else switch (TYPE) {
|
||||
case 4: return false; // every
|
||||
case 7: createProperty(target, resIndex++, value); // filterReject
|
||||
}
|
||||
}
|
||||
}
|
||||
return IS_FIND_INDEX ? -1 : IS_SOME || IS_EVERY ? IS_EVERY : target;
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
// `Array.prototype.forEach` method
|
||||
// https://tc39.es/ecma262/#sec-array.prototype.foreach
|
||||
forEach: createMethod(0),
|
||||
// `Array.prototype.map` method
|
||||
// https://tc39.es/ecma262/#sec-array.prototype.map
|
||||
map: createMethod(1),
|
||||
// `Array.prototype.filter` method
|
||||
// https://tc39.es/ecma262/#sec-array.prototype.filter
|
||||
filter: createMethod(2),
|
||||
// `Array.prototype.some` method
|
||||
// https://tc39.es/ecma262/#sec-array.prototype.some
|
||||
some: createMethod(3),
|
||||
// `Array.prototype.every` method
|
||||
// https://tc39.es/ecma262/#sec-array.prototype.every
|
||||
every: createMethod(4),
|
||||
// `Array.prototype.find` method
|
||||
// https://tc39.es/ecma262/#sec-array.prototype.find
|
||||
find: createMethod(5),
|
||||
// `Array.prototype.findIndex` method
|
||||
// https://tc39.es/ecma262/#sec-array.prototype.findIndex
|
||||
findIndex: createMethod(6),
|
||||
// `Array.prototype.filterReject` method
|
||||
// https://github.com/tc39/proposal-array-filtering
|
||||
filterReject: createMethod(7)
|
||||
};
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
/* eslint-disable es/no-array-prototype-lastindexof -- safe */
|
||||
var apply = require('../internals/function-apply');
|
||||
var toIndexedObject = require('../internals/to-indexed-object');
|
||||
var toIntegerOrInfinity = require('../internals/to-integer-or-infinity');
|
||||
var lengthOfArrayLike = require('../internals/length-of-array-like');
|
||||
var arrayMethodIsStrict = require('../internals/array-method-is-strict');
|
||||
|
||||
var min = Math.min;
|
||||
var $lastIndexOf = [].lastIndexOf;
|
||||
var NEGATIVE_ZERO = !!$lastIndexOf && 1 / [1].lastIndexOf(1, -0) < 0;
|
||||
var STRICT_METHOD = arrayMethodIsStrict('lastIndexOf');
|
||||
var FORCED = NEGATIVE_ZERO || !STRICT_METHOD;
|
||||
|
||||
// `Array.prototype.lastIndexOf` method implementation
|
||||
// https://tc39.es/ecma262/#sec-array.prototype.lastindexof
|
||||
module.exports = FORCED ? function lastIndexOf(searchElement /* , fromIndex = @[*-1] */) {
|
||||
// convert -0 to +0
|
||||
if (NEGATIVE_ZERO) return apply($lastIndexOf, this, arguments) || 0;
|
||||
var O = toIndexedObject(this);
|
||||
var length = lengthOfArrayLike(O);
|
||||
if (length === 0) return -1;
|
||||
var index = length - 1;
|
||||
if (arguments.length > 1) index = min(index, toIntegerOrInfinity(arguments[1]));
|
||||
if (index < 0) index = length + index;
|
||||
for (;index >= 0; index--) if (index in O && O[index] === searchElement) return index || 0;
|
||||
return -1;
|
||||
} : $lastIndexOf;
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
var fails = require('../internals/fails');
|
||||
var wellKnownSymbol = require('../internals/well-known-symbol');
|
||||
var V8_VERSION = require('../internals/environment-v8-version');
|
||||
|
||||
var SPECIES = wellKnownSymbol('species');
|
||||
|
||||
module.exports = function (METHOD_NAME) {
|
||||
// We can't use this feature detection in V8 since it causes
|
||||
// deoptimization and serious performance degradation
|
||||
// https://github.com/zloirock/core-js/issues/677
|
||||
return V8_VERSION >= 51 || !fails(function () {
|
||||
var array = [];
|
||||
var constructor = array.constructor = {};
|
||||
constructor[SPECIES] = function () {
|
||||
return { foo: 1 };
|
||||
};
|
||||
return array[METHOD_NAME](Boolean).foo !== 1;
|
||||
});
|
||||
};
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
'use strict';
|
||||
var fails = require('../internals/fails');
|
||||
|
||||
module.exports = function (METHOD_NAME, argument) {
|
||||
var method = [][METHOD_NAME];
|
||||
return !!method && fails(function () {
|
||||
// eslint-disable-next-line no-useless-call -- required for testing
|
||||
method.call(null, argument || function () { return 1; }, 1);
|
||||
});
|
||||
};
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
'use strict';
|
||||
var aCallable = require('../internals/a-callable');
|
||||
var toObject = require('../internals/to-object');
|
||||
var IndexedObject = require('../internals/indexed-object');
|
||||
var lengthOfArrayLike = require('../internals/length-of-array-like');
|
||||
|
||||
var $TypeError = TypeError;
|
||||
|
||||
var REDUCE_EMPTY = 'Reduce of empty array with no initial value';
|
||||
|
||||
// `Array.prototype.{ reduce, reduceRight }` methods implementation
|
||||
var createMethod = function (IS_RIGHT) {
|
||||
return function (that, callbackfn, argumentsLength, memo) {
|
||||
var O = toObject(that);
|
||||
var self = IndexedObject(O);
|
||||
var length = lengthOfArrayLike(O);
|
||||
aCallable(callbackfn);
|
||||
if (length === 0 && argumentsLength < 2) throw new $TypeError(REDUCE_EMPTY);
|
||||
var index = IS_RIGHT ? length - 1 : 0;
|
||||
var i = IS_RIGHT ? -1 : 1;
|
||||
if (argumentsLength < 2) while (true) {
|
||||
if (index in self) {
|
||||
memo = self[index];
|
||||
index += i;
|
||||
break;
|
||||
}
|
||||
index += i;
|
||||
if (IS_RIGHT ? index < 0 : length <= index) {
|
||||
throw new $TypeError(REDUCE_EMPTY);
|
||||
}
|
||||
}
|
||||
for (;IS_RIGHT ? index >= 0 : length > index; index += i) if (index in self) {
|
||||
memo = callbackfn(memo, self[index], index, O);
|
||||
}
|
||||
return memo;
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
// `Array.prototype.reduce` method
|
||||
// https://tc39.es/ecma262/#sec-array.prototype.reduce
|
||||
left: createMethod(false),
|
||||
// `Array.prototype.reduceRight` method
|
||||
// https://tc39.es/ecma262/#sec-array.prototype.reduceright
|
||||
right: createMethod(true)
|
||||
};
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
'use strict';
|
||||
var DESCRIPTORS = require('../internals/descriptors');
|
||||
var isArray = require('../internals/is-array');
|
||||
|
||||
var $TypeError = TypeError;
|
||||
// eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
|
||||
var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
|
||||
|
||||
// Safari < 13 does not throw an error in this case
|
||||
var SILENT_ON_NON_WRITABLE_LENGTH_SET = DESCRIPTORS && !function () {
|
||||
// makes no sense without proper strict mode support
|
||||
if (this !== undefined) return true;
|
||||
try {
|
||||
// eslint-disable-next-line es/no-object-defineproperty -- safe
|
||||
Object.defineProperty([], 'length', { writable: false }).length = 1;
|
||||
} catch (error) {
|
||||
return error instanceof TypeError;
|
||||
}
|
||||
}();
|
||||
|
||||
module.exports = SILENT_ON_NON_WRITABLE_LENGTH_SET ? function (O, length) {
|
||||
if (isArray(O) && !getOwnPropertyDescriptor(O, 'length').writable) {
|
||||
throw new $TypeError('Cannot set read only .length');
|
||||
} return O.length = length;
|
||||
} : function (O, length) {
|
||||
return O.length = length;
|
||||
};
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
'use strict';
|
||||
var isArray = require('../internals/is-array');
|
||||
var isConstructor = require('../internals/is-constructor');
|
||||
var isObject = require('../internals/is-object');
|
||||
var wellKnownSymbol = require('../internals/well-known-symbol');
|
||||
|
||||
var SPECIES = wellKnownSymbol('species');
|
||||
var $Array = Array;
|
||||
|
||||
// a part of `ArraySpeciesCreate` abstract operation
|
||||
// https://tc39.es/ecma262/#sec-arrayspeciescreate
|
||||
module.exports = function (originalArray) {
|
||||
var C;
|
||||
if (isArray(originalArray)) {
|
||||
C = originalArray.constructor;
|
||||
// cross-realm fallback
|
||||
if (isConstructor(C) && (C === $Array || isArray(C.prototype))) C = undefined;
|
||||
else if (isObject(C)) {
|
||||
C = C[SPECIES];
|
||||
if (C === null) C = undefined;
|
||||
}
|
||||
} return C === undefined ? $Array : C;
|
||||
};
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
'use strict';
|
||||
var arraySpeciesConstructor = require('../internals/array-species-constructor');
|
||||
|
||||
// `ArraySpeciesCreate` abstract operation
|
||||
// https://tc39.es/ecma262/#sec-arrayspeciescreate
|
||||
module.exports = function (originalArray, length) {
|
||||
return new (arraySpeciesConstructor(originalArray))(length === 0 ? 0 : length);
|
||||
};
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
'use strict';
|
||||
var call = require('../internals/function-call');
|
||||
var anObject = require('../internals/an-object');
|
||||
var create = require('../internals/object-create');
|
||||
var getMethod = require('../internals/get-method');
|
||||
var defineBuiltIns = require('../internals/define-built-ins');
|
||||
var InternalStateModule = require('../internals/internal-state');
|
||||
var iteratorClose = require('../internals/iterator-close');
|
||||
var getBuiltIn = require('../internals/get-built-in');
|
||||
var AsyncIteratorPrototype = require('../internals/async-iterator-prototype');
|
||||
var createIterResultObject = require('../internals/create-iter-result-object');
|
||||
|
||||
var Promise = getBuiltIn('Promise');
|
||||
|
||||
var ASYNC_FROM_SYNC_ITERATOR = 'AsyncFromSyncIterator';
|
||||
var setInternalState = InternalStateModule.set;
|
||||
var getInternalState = InternalStateModule.getterFor(ASYNC_FROM_SYNC_ITERATOR);
|
||||
|
||||
var asyncFromSyncIteratorContinuation = function (result, resolve, reject, syncIterator, closeOnRejection) {
|
||||
var done = result.done;
|
||||
Promise.resolve(result.value).then(function (value) {
|
||||
resolve(createIterResultObject(value, done));
|
||||
}, function (error) {
|
||||
if (!done && closeOnRejection) {
|
||||
try {
|
||||
iteratorClose(syncIterator, 'throw', error);
|
||||
} catch (error2) {
|
||||
error = error2;
|
||||
}
|
||||
}
|
||||
|
||||
reject(error);
|
||||
});
|
||||
};
|
||||
|
||||
var AsyncFromSyncIterator = function AsyncIterator(iteratorRecord) {
|
||||
iteratorRecord.type = ASYNC_FROM_SYNC_ITERATOR;
|
||||
setInternalState(this, iteratorRecord);
|
||||
};
|
||||
|
||||
AsyncFromSyncIterator.prototype = defineBuiltIns(create(AsyncIteratorPrototype), {
|
||||
next: function next() {
|
||||
var state = getInternalState(this);
|
||||
return new Promise(function (resolve, reject) {
|
||||
var result = anObject(call(state.next, state.iterator));
|
||||
asyncFromSyncIteratorContinuation(result, resolve, reject, state.iterator, true);
|
||||
});
|
||||
},
|
||||
'return': function () {
|
||||
var iterator = getInternalState(this).iterator;
|
||||
return new Promise(function (resolve, reject) {
|
||||
var $return = getMethod(iterator, 'return');
|
||||
if ($return === undefined) return resolve(createIterResultObject(undefined, true));
|
||||
var result = anObject(call($return, iterator));
|
||||
asyncFromSyncIteratorContinuation(result, resolve, reject, iterator);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = AsyncFromSyncIterator;
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
'use strict';
|
||||
var call = require('../internals/function-call');
|
||||
var getBuiltIn = require('../internals/get-built-in');
|
||||
var getMethod = require('../internals/get-method');
|
||||
|
||||
module.exports = function (iterator, method, argument, reject) {
|
||||
try {
|
||||
var returnMethod = getMethod(iterator, 'return');
|
||||
if (returnMethod) {
|
||||
return getBuiltIn('Promise').resolve(call(returnMethod, iterator)).then(function () {
|
||||
method(argument);
|
||||
}, function (error) {
|
||||
reject(error);
|
||||
});
|
||||
}
|
||||
} catch (error2) {
|
||||
return reject(error2);
|
||||
} method(argument);
|
||||
};
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
'use strict';
|
||||
// https://github.com/tc39/proposal-async-iterator-helpers
|
||||
// https://github.com/tc39/proposal-array-from-async
|
||||
var call = require('../internals/function-call');
|
||||
var aCallable = require('../internals/a-callable');
|
||||
var anObject = require('../internals/an-object');
|
||||
var isObject = require('../internals/is-object');
|
||||
var doesNotExceedSafeInteger = require('../internals/does-not-exceed-safe-integer');
|
||||
var getBuiltIn = require('../internals/get-built-in');
|
||||
var createProperty = require('../internals/create-property');
|
||||
var setArrayLength = require('../internals/array-set-length');
|
||||
var getIteratorDirect = require('../internals/get-iterator-direct');
|
||||
var closeAsyncIteration = require('../internals/async-iterator-close');
|
||||
|
||||
var createMethod = function (TYPE) {
|
||||
var IS_TO_ARRAY = TYPE === 0;
|
||||
var IS_FOR_EACH = TYPE === 1;
|
||||
var IS_EVERY = TYPE === 2;
|
||||
var IS_SOME = TYPE === 3;
|
||||
return function (object, fn, target) {
|
||||
anObject(object);
|
||||
var MAPPING = fn !== undefined;
|
||||
if (MAPPING || !IS_TO_ARRAY) aCallable(fn);
|
||||
var record = getIteratorDirect(object);
|
||||
var Promise = getBuiltIn('Promise');
|
||||
var iterator = record.iterator;
|
||||
var next = record.next;
|
||||
var counter = 0;
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
var ifAbruptCloseAsyncIterator = function (error) {
|
||||
closeAsyncIteration(iterator, reject, error, reject);
|
||||
};
|
||||
|
||||
var loop = function () {
|
||||
try {
|
||||
if (MAPPING) try {
|
||||
doesNotExceedSafeInteger(counter);
|
||||
} catch (error5) { ifAbruptCloseAsyncIterator(error5); }
|
||||
Promise.resolve(anObject(call(next, iterator))).then(function (step) {
|
||||
try {
|
||||
if (anObject(step).done) {
|
||||
if (IS_TO_ARRAY) {
|
||||
setArrayLength(target, counter);
|
||||
resolve(target);
|
||||
} else resolve(IS_SOME ? false : IS_EVERY || undefined);
|
||||
} else {
|
||||
var value = step.value;
|
||||
try {
|
||||
if (MAPPING) {
|
||||
var result = fn(value, counter);
|
||||
|
||||
var handler = function ($result) {
|
||||
if (IS_FOR_EACH) {
|
||||
loop();
|
||||
} else if (IS_EVERY) {
|
||||
$result ? loop() : closeAsyncIteration(iterator, resolve, false, reject);
|
||||
} else if (IS_TO_ARRAY) {
|
||||
try {
|
||||
createProperty(target, counter++, $result);
|
||||
loop();
|
||||
} catch (error4) { ifAbruptCloseAsyncIterator(error4); }
|
||||
} else {
|
||||
$result ? closeAsyncIteration(iterator, resolve, IS_SOME || value, reject) : loop();
|
||||
}
|
||||
};
|
||||
|
||||
if (isObject(result)) Promise.resolve(result).then(handler, ifAbruptCloseAsyncIterator);
|
||||
else handler(result);
|
||||
} else {
|
||||
createProperty(target, counter++, value);
|
||||
loop();
|
||||
}
|
||||
} catch (error3) { ifAbruptCloseAsyncIterator(error3); }
|
||||
}
|
||||
} catch (error2) { reject(error2); }
|
||||
}, reject);
|
||||
} catch (error) { reject(error); }
|
||||
};
|
||||
|
||||
loop();
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
// `AsyncIterator.prototype.toArray` / `Array.fromAsync` methods
|
||||
toArray: createMethod(0),
|
||||
// `AsyncIterator.prototype.forEach` method
|
||||
forEach: createMethod(1),
|
||||
// `AsyncIterator.prototype.every` method
|
||||
every: createMethod(2),
|
||||
// `AsyncIterator.prototype.some` method
|
||||
some: createMethod(3),
|
||||
// `AsyncIterator.prototype.find` method
|
||||
find: createMethod(4)
|
||||
};
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
'use strict';
|
||||
var globalThis = require('../internals/global-this');
|
||||
var shared = require('../internals/shared-store');
|
||||
var isCallable = require('../internals/is-callable');
|
||||
var create = require('../internals/object-create');
|
||||
var getPrototypeOf = require('../internals/object-get-prototype-of');
|
||||
var defineBuiltIn = require('../internals/define-built-in');
|
||||
var wellKnownSymbol = require('../internals/well-known-symbol');
|
||||
var IS_PURE = require('../internals/is-pure');
|
||||
|
||||
var USE_FUNCTION_CONSTRUCTOR = 'USE_FUNCTION_CONSTRUCTOR';
|
||||
var ASYNC_ITERATOR = wellKnownSymbol('asyncIterator');
|
||||
var AsyncIterator = globalThis.AsyncIterator;
|
||||
var PassedAsyncIteratorPrototype = shared.AsyncIteratorPrototype;
|
||||
var AsyncIteratorPrototype, prototype;
|
||||
|
||||
if (PassedAsyncIteratorPrototype) {
|
||||
AsyncIteratorPrototype = PassedAsyncIteratorPrototype;
|
||||
} else if (isCallable(AsyncIterator)) {
|
||||
AsyncIteratorPrototype = AsyncIterator.prototype;
|
||||
} else if (shared[USE_FUNCTION_CONSTRUCTOR] || globalThis[USE_FUNCTION_CONSTRUCTOR]) {
|
||||
try {
|
||||
// eslint-disable-next-line no-new-func -- we have no alternatives without usage of modern syntax
|
||||
prototype = getPrototypeOf(getPrototypeOf(getPrototypeOf(Function('return async function*(){}()')())));
|
||||
if (getPrototypeOf(prototype) === Object.prototype) AsyncIteratorPrototype = prototype;
|
||||
} catch (error) { /* empty */ }
|
||||
}
|
||||
|
||||
if (!AsyncIteratorPrototype) AsyncIteratorPrototype = {};
|
||||
else if (IS_PURE) AsyncIteratorPrototype = create(AsyncIteratorPrototype);
|
||||
|
||||
if (!isCallable(AsyncIteratorPrototype[ASYNC_ITERATOR])) {
|
||||
defineBuiltIn(AsyncIteratorPrototype, ASYNC_ITERATOR, function () {
|
||||
return this;
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = AsyncIteratorPrototype;
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
'use strict';
|
||||
var commonAlphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||
var base64Alphabet = commonAlphabet + '+/';
|
||||
var base64UrlAlphabet = commonAlphabet + '-_';
|
||||
|
||||
var inverse = function (characters) {
|
||||
// TODO: use `Object.create(null)` in `core-js@4`
|
||||
var result = {};
|
||||
var index = 0;
|
||||
for (; index < 64; index++) result[characters.charAt(index)] = index;
|
||||
return result;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
i2c: base64Alphabet,
|
||||
c2i: inverse(base64Alphabet),
|
||||
i2cUrl: base64UrlAlphabet,
|
||||
c2iUrl: inverse(base64UrlAlphabet)
|
||||
};
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
'use strict';
|
||||
var wellKnownSymbol = require('../internals/well-known-symbol');
|
||||
|
||||
var ITERATOR = wellKnownSymbol('iterator');
|
||||
var SAFE_CLOSING = false;
|
||||
|
||||
try {
|
||||
var called = 0;
|
||||
var iteratorWithReturn = {
|
||||
next: function () {
|
||||
return { done: !!called++ };
|
||||
},
|
||||
'return': function () {
|
||||
SAFE_CLOSING = true;
|
||||
}
|
||||
};
|
||||
// eslint-disable-next-line unicorn/no-immediate-mutation -- ES3 syntax limitation
|
||||
iteratorWithReturn[ITERATOR] = function () {
|
||||
return this;
|
||||
};
|
||||
// eslint-disable-next-line es/no-array-from, no-throw-literal -- required for testing
|
||||
Array.from(iteratorWithReturn, function () { throw 2; });
|
||||
} catch (error) { /* empty */ }
|
||||
|
||||
module.exports = function (exec, SKIP_CLOSING) {
|
||||
try {
|
||||
if (!SKIP_CLOSING && !SAFE_CLOSING) return false;
|
||||
} catch (error) { return false; } // workaround of old WebKit + `eval` bug
|
||||
var ITERATION_SUPPORT = false;
|
||||
try {
|
||||
var object = {};
|
||||
// eslint-disable-next-line unicorn/no-immediate-mutation -- ES3 syntax limitation
|
||||
object[ITERATOR] = function () {
|
||||
return {
|
||||
next: function () {
|
||||
return { done: ITERATION_SUPPORT = true };
|
||||
}
|
||||
};
|
||||
};
|
||||
exec(object);
|
||||
} catch (error) { /* empty */ }
|
||||
return ITERATION_SUPPORT;
|
||||
};
|
||||
+206
@@ -0,0 +1,206 @@
|
||||
'use strict';
|
||||
var create = require('../internals/object-create');
|
||||
var defineBuiltInAccessor = require('../internals/define-built-in-accessor');
|
||||
var defineBuiltIns = require('../internals/define-built-ins');
|
||||
var bind = require('../internals/function-bind-context');
|
||||
var anInstance = require('../internals/an-instance');
|
||||
var isNullOrUndefined = require('../internals/is-null-or-undefined');
|
||||
var iterate = require('../internals/iterate');
|
||||
var defineIterator = require('../internals/iterator-define');
|
||||
var createIterResultObject = require('../internals/create-iter-result-object');
|
||||
var setSpecies = require('../internals/set-species');
|
||||
var DESCRIPTORS = require('../internals/descriptors');
|
||||
var fastKey = require('../internals/internal-metadata').fastKey;
|
||||
var InternalStateModule = require('../internals/internal-state');
|
||||
|
||||
var setInternalState = InternalStateModule.set;
|
||||
var internalStateGetterFor = InternalStateModule.getterFor;
|
||||
|
||||
module.exports = {
|
||||
getConstructor: function (wrapper, CONSTRUCTOR_NAME, IS_MAP, ADDER) {
|
||||
var Constructor = wrapper(function (that, iterable) {
|
||||
anInstance(that, Prototype);
|
||||
setInternalState(that, {
|
||||
type: CONSTRUCTOR_NAME,
|
||||
index: create(null),
|
||||
first: null,
|
||||
last: null,
|
||||
size: 0
|
||||
});
|
||||
if (!DESCRIPTORS) that.size = 0;
|
||||
if (!isNullOrUndefined(iterable)) iterate(iterable, that[ADDER], { that: that, AS_ENTRIES: IS_MAP });
|
||||
});
|
||||
|
||||
var Prototype = Constructor.prototype;
|
||||
|
||||
var getInternalState = internalStateGetterFor(CONSTRUCTOR_NAME);
|
||||
|
||||
var define = function (that, key, value) {
|
||||
var state = getInternalState(that);
|
||||
var entry = getEntry(that, key);
|
||||
var previous, index;
|
||||
// change existing entry
|
||||
if (entry) {
|
||||
entry.value = value;
|
||||
// create new entry
|
||||
} else {
|
||||
state.last = entry = {
|
||||
index: index = fastKey(key, true),
|
||||
key: key,
|
||||
value: value,
|
||||
previous: previous = state.last,
|
||||
next: null,
|
||||
removed: false
|
||||
};
|
||||
if (!state.first) state.first = entry;
|
||||
if (previous) previous.next = entry;
|
||||
if (DESCRIPTORS) state.size++;
|
||||
else that.size++;
|
||||
// add to index
|
||||
if (index !== 'F') state.index[index] = entry;
|
||||
} return that;
|
||||
};
|
||||
|
||||
var getEntry = function (that, key) {
|
||||
var state = getInternalState(that);
|
||||
// fast case
|
||||
var index = fastKey(key);
|
||||
var entry;
|
||||
if (index !== 'F') return state.index[index];
|
||||
// frozen object case
|
||||
for (entry = state.first; entry; entry = entry.next) {
|
||||
if (entry.key === key) return entry;
|
||||
}
|
||||
};
|
||||
|
||||
defineBuiltIns(Prototype, {
|
||||
// `{ Map, Set }.prototype.clear()` methods
|
||||
// https://tc39.es/ecma262/#sec-map.prototype.clear
|
||||
// https://tc39.es/ecma262/#sec-set.prototype.clear
|
||||
clear: function clear() {
|
||||
var that = this;
|
||||
var state = getInternalState(that);
|
||||
var entry = state.first;
|
||||
while (entry) {
|
||||
entry.removed = true;
|
||||
if (entry.previous) entry.previous = entry.previous.next = null;
|
||||
entry = entry.next;
|
||||
}
|
||||
state.first = state.last = null;
|
||||
state.index = create(null);
|
||||
if (DESCRIPTORS) state.size = 0;
|
||||
else that.size = 0;
|
||||
},
|
||||
// `{ Map, Set }.prototype.delete(key)` methods
|
||||
// https://tc39.es/ecma262/#sec-map.prototype.delete
|
||||
// https://tc39.es/ecma262/#sec-set.prototype.delete
|
||||
'delete': function (key) {
|
||||
var that = this;
|
||||
var state = getInternalState(that);
|
||||
var entry = getEntry(that, key);
|
||||
if (entry) {
|
||||
var next = entry.next;
|
||||
var prev = entry.previous;
|
||||
delete state.index[entry.index];
|
||||
entry.removed = true;
|
||||
if (prev) prev.next = next;
|
||||
if (next) next.previous = prev;
|
||||
if (state.first === entry) state.first = next;
|
||||
if (state.last === entry) state.last = prev;
|
||||
if (DESCRIPTORS) state.size--;
|
||||
else that.size--;
|
||||
} return !!entry;
|
||||
},
|
||||
// `{ Map, Set }.prototype.forEach(callbackfn, thisArg = undefined)` methods
|
||||
// https://tc39.es/ecma262/#sec-map.prototype.foreach
|
||||
// https://tc39.es/ecma262/#sec-set.prototype.foreach
|
||||
forEach: function forEach(callbackfn /* , that = undefined */) {
|
||||
var state = getInternalState(this);
|
||||
var boundFunction = bind(callbackfn, arguments.length > 1 ? arguments[1] : undefined);
|
||||
var entry;
|
||||
while (entry = entry ? entry.next : state.first) {
|
||||
boundFunction(entry.value, entry.key, this);
|
||||
// revert to the last existing entry
|
||||
while (entry && entry.removed) entry = entry.previous;
|
||||
}
|
||||
},
|
||||
// `{ Map, Set}.prototype.has(key)` methods
|
||||
// https://tc39.es/ecma262/#sec-map.prototype.has
|
||||
// https://tc39.es/ecma262/#sec-set.prototype.has
|
||||
has: function has(key) {
|
||||
return !!getEntry(this, key);
|
||||
}
|
||||
});
|
||||
|
||||
defineBuiltIns(Prototype, IS_MAP ? {
|
||||
// `Map.prototype.get(key)` method
|
||||
// https://tc39.es/ecma262/#sec-map.prototype.get
|
||||
get: function get(key) {
|
||||
var entry = getEntry(this, key);
|
||||
return entry && entry.value;
|
||||
},
|
||||
// `Map.prototype.set(key, value)` method
|
||||
// https://tc39.es/ecma262/#sec-map.prototype.set
|
||||
set: function set(key, value) {
|
||||
return define(this, key === 0 ? 0 : key, value);
|
||||
}
|
||||
} : {
|
||||
// `Set.prototype.add(value)` method
|
||||
// https://tc39.es/ecma262/#sec-set.prototype.add
|
||||
add: function add(value) {
|
||||
return define(this, value = value === 0 ? 0 : value, value);
|
||||
}
|
||||
});
|
||||
if (DESCRIPTORS) defineBuiltInAccessor(Prototype, 'size', {
|
||||
configurable: true,
|
||||
get: function () {
|
||||
return getInternalState(this).size;
|
||||
}
|
||||
});
|
||||
return Constructor;
|
||||
},
|
||||
setStrong: function (Constructor, CONSTRUCTOR_NAME, IS_MAP) {
|
||||
var ITERATOR_NAME = CONSTRUCTOR_NAME + ' Iterator';
|
||||
var getInternalCollectionState = internalStateGetterFor(CONSTRUCTOR_NAME);
|
||||
var getInternalIteratorState = internalStateGetterFor(ITERATOR_NAME);
|
||||
// `{ Map, Set }.prototype.{ keys, values, entries, @@iterator }()` methods
|
||||
// https://tc39.es/ecma262/#sec-map.prototype.entries
|
||||
// https://tc39.es/ecma262/#sec-map.prototype.keys
|
||||
// https://tc39.es/ecma262/#sec-map.prototype.values
|
||||
// https://tc39.es/ecma262/#sec-map.prototype-@@iterator
|
||||
// https://tc39.es/ecma262/#sec-set.prototype.entries
|
||||
// https://tc39.es/ecma262/#sec-set.prototype.keys
|
||||
// https://tc39.es/ecma262/#sec-set.prototype.values
|
||||
// https://tc39.es/ecma262/#sec-set.prototype-@@iterator
|
||||
defineIterator(Constructor, CONSTRUCTOR_NAME, function (iterated, kind) {
|
||||
setInternalState(this, {
|
||||
type: ITERATOR_NAME,
|
||||
target: iterated,
|
||||
state: getInternalCollectionState(iterated),
|
||||
kind: kind,
|
||||
last: null
|
||||
});
|
||||
}, function () {
|
||||
var state = getInternalIteratorState(this);
|
||||
var kind = state.kind;
|
||||
var entry = state.last;
|
||||
// revert to the last existing entry
|
||||
while (entry && entry.removed) entry = entry.previous;
|
||||
// get next entry
|
||||
if (!state.target || !(state.last = entry = entry ? entry.next : state.state.first)) {
|
||||
// or finish the iteration
|
||||
state.target = null;
|
||||
return createIterResultObject(undefined, true);
|
||||
}
|
||||
// return step by kind
|
||||
if (kind === 'keys') return createIterResultObject(entry.key, false);
|
||||
if (kind === 'values') return createIterResultObject(entry.value, false);
|
||||
return createIterResultObject([entry.key, entry.value], false);
|
||||
}, IS_MAP ? 'entries' : 'values', !IS_MAP, true);
|
||||
|
||||
// `{ Map, Set }.prototype[@@species]` accessors
|
||||
// https://tc39.es/ecma262/#sec-get-map-@@species
|
||||
// https://tc39.es/ecma262/#sec-get-set-@@species
|
||||
setSpecies(CONSTRUCTOR_NAME);
|
||||
}
|
||||
};
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
'use strict';
|
||||
var uncurryThis = require('../internals/function-uncurry-this');
|
||||
var defineBuiltIns = require('../internals/define-built-ins');
|
||||
var getWeakData = require('../internals/internal-metadata').getWeakData;
|
||||
var anInstance = require('../internals/an-instance');
|
||||
var anObject = require('../internals/an-object');
|
||||
var isNullOrUndefined = require('../internals/is-null-or-undefined');
|
||||
var isObject = require('../internals/is-object');
|
||||
var iterate = require('../internals/iterate');
|
||||
var ArrayIterationModule = require('../internals/array-iteration');
|
||||
var hasOwn = require('../internals/has-own-property');
|
||||
var InternalStateModule = require('../internals/internal-state');
|
||||
|
||||
var setInternalState = InternalStateModule.set;
|
||||
var internalStateGetterFor = InternalStateModule.getterFor;
|
||||
var find = ArrayIterationModule.find;
|
||||
var findIndex = ArrayIterationModule.findIndex;
|
||||
var splice = uncurryThis([].splice);
|
||||
var id = 0;
|
||||
|
||||
// fallback for uncaught frozen keys
|
||||
var uncaughtFrozenStore = function (state) {
|
||||
return state.frozen || (state.frozen = new UncaughtFrozenStore());
|
||||
};
|
||||
|
||||
var UncaughtFrozenStore = function () {
|
||||
this.entries = [];
|
||||
};
|
||||
|
||||
var findUncaughtFrozen = function (store, key) {
|
||||
return find(store.entries, function (it) {
|
||||
return it[0] === key;
|
||||
});
|
||||
};
|
||||
|
||||
UncaughtFrozenStore.prototype = {
|
||||
get: function (key) {
|
||||
var entry = findUncaughtFrozen(this, key);
|
||||
if (entry) return entry[1];
|
||||
},
|
||||
has: function (key) {
|
||||
return !!findUncaughtFrozen(this, key);
|
||||
},
|
||||
set: function (key, value) {
|
||||
var entry = findUncaughtFrozen(this, key);
|
||||
if (entry) entry[1] = value;
|
||||
else this.entries.push([key, value]);
|
||||
},
|
||||
'delete': function (key) {
|
||||
var index = findIndex(this.entries, function (it) {
|
||||
return it[0] === key;
|
||||
});
|
||||
if (~index) splice(this.entries, index, 1);
|
||||
return !!~index;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
getConstructor: function (wrapper, CONSTRUCTOR_NAME, IS_MAP, ADDER) {
|
||||
var Constructor = wrapper(function (that, iterable) {
|
||||
anInstance(that, Prototype);
|
||||
setInternalState(that, {
|
||||
type: CONSTRUCTOR_NAME,
|
||||
id: id++,
|
||||
frozen: null
|
||||
});
|
||||
if (!isNullOrUndefined(iterable)) iterate(iterable, that[ADDER], { that: that, AS_ENTRIES: IS_MAP });
|
||||
});
|
||||
|
||||
var Prototype = Constructor.prototype;
|
||||
|
||||
var getInternalState = internalStateGetterFor(CONSTRUCTOR_NAME);
|
||||
|
||||
var define = function (that, key, value) {
|
||||
var state = getInternalState(that);
|
||||
var data = getWeakData(anObject(key), true);
|
||||
if (data === true) uncaughtFrozenStore(state).set(key, value);
|
||||
else data[state.id] = value;
|
||||
return that;
|
||||
};
|
||||
|
||||
defineBuiltIns(Prototype, {
|
||||
// `{ WeakMap, WeakSet }.prototype.delete(key)` methods
|
||||
// https://tc39.es/ecma262/#sec-weakmap.prototype.delete
|
||||
// https://tc39.es/ecma262/#sec-weakset.prototype.delete
|
||||
'delete': function (key) {
|
||||
var state = getInternalState(this);
|
||||
if (!isObject(key)) return false;
|
||||
var data = getWeakData(key);
|
||||
if (data === true) return uncaughtFrozenStore(state)['delete'](key);
|
||||
return data && hasOwn(data, state.id) && delete data[state.id];
|
||||
},
|
||||
// `{ WeakMap, WeakSet }.prototype.has(key)` methods
|
||||
// https://tc39.es/ecma262/#sec-weakmap.prototype.has
|
||||
// https://tc39.es/ecma262/#sec-weakset.prototype.has
|
||||
has: function has(key) {
|
||||
var state = getInternalState(this);
|
||||
if (!isObject(key)) return false;
|
||||
var data = getWeakData(key);
|
||||
if (data === true) return uncaughtFrozenStore(state).has(key);
|
||||
return data && hasOwn(data, state.id);
|
||||
}
|
||||
});
|
||||
|
||||
defineBuiltIns(Prototype, IS_MAP ? {
|
||||
// `WeakMap.prototype.get(key)` method
|
||||
// https://tc39.es/ecma262/#sec-weakmap.prototype.get
|
||||
get: function get(key) {
|
||||
var state = getInternalState(this);
|
||||
if (isObject(key)) {
|
||||
var data = getWeakData(key);
|
||||
if (data === true) return uncaughtFrozenStore(state).get(key);
|
||||
if (data) return data[state.id];
|
||||
}
|
||||
},
|
||||
// `WeakMap.prototype.set(key, value)` method
|
||||
// https://tc39.es/ecma262/#sec-weakmap.prototype.set
|
||||
set: function set(key, value) {
|
||||
return define(this, key, value);
|
||||
}
|
||||
} : {
|
||||
// `WeakSet.prototype.add(value)` method
|
||||
// https://tc39.es/ecma262/#sec-weakset.prototype.add
|
||||
add: function add(value) {
|
||||
return define(this, value, true);
|
||||
}
|
||||
});
|
||||
|
||||
return Constructor;
|
||||
}
|
||||
};
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
'use strict';
|
||||
var $ = require('../internals/export');
|
||||
var globalThis = require('../internals/global-this');
|
||||
var uncurryThis = require('../internals/function-uncurry-this');
|
||||
var isForced = require('../internals/is-forced');
|
||||
var defineBuiltIn = require('../internals/define-built-in');
|
||||
var InternalMetadataModule = require('../internals/internal-metadata');
|
||||
var iterate = require('../internals/iterate');
|
||||
var anInstance = require('../internals/an-instance');
|
||||
var isCallable = require('../internals/is-callable');
|
||||
var isNullOrUndefined = require('../internals/is-null-or-undefined');
|
||||
var isObject = require('../internals/is-object');
|
||||
var fails = require('../internals/fails');
|
||||
var checkCorrectnessOfIteration = require('../internals/check-correctness-of-iteration');
|
||||
var setToStringTag = require('../internals/set-to-string-tag');
|
||||
var inheritIfRequired = require('../internals/inherit-if-required');
|
||||
|
||||
module.exports = function (CONSTRUCTOR_NAME, wrapper, common) {
|
||||
var IS_MAP = CONSTRUCTOR_NAME.indexOf('Map') !== -1;
|
||||
var IS_WEAK = CONSTRUCTOR_NAME.indexOf('Weak') !== -1;
|
||||
var ADDER = IS_MAP ? 'set' : 'add';
|
||||
var NativeConstructor = globalThis[CONSTRUCTOR_NAME];
|
||||
var NativePrototype = NativeConstructor && NativeConstructor.prototype;
|
||||
var Constructor = NativeConstructor;
|
||||
var exported = {};
|
||||
|
||||
var fixMethod = function (KEY) {
|
||||
var uncurriedNativeMethod = uncurryThis(NativePrototype[KEY]);
|
||||
defineBuiltIn(NativePrototype, KEY,
|
||||
KEY === 'add' ? function add(value) {
|
||||
uncurriedNativeMethod(this, value === 0 ? 0 : value);
|
||||
return this;
|
||||
} : KEY === 'delete' ? function (key) {
|
||||
return IS_WEAK && !isObject(key) ? false : uncurriedNativeMethod(this, key === 0 ? 0 : key);
|
||||
} : KEY === 'get' ? function get(key) {
|
||||
return IS_WEAK && !isObject(key) ? undefined : uncurriedNativeMethod(this, key === 0 ? 0 : key);
|
||||
} : KEY === 'has' ? function has(key) {
|
||||
return IS_WEAK && !isObject(key) ? false : uncurriedNativeMethod(this, key === 0 ? 0 : key);
|
||||
} : function set(key, value) {
|
||||
uncurriedNativeMethod(this, key === 0 ? 0 : key, value);
|
||||
return this;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
var REPLACE = isForced(
|
||||
CONSTRUCTOR_NAME,
|
||||
!isCallable(NativeConstructor) || !(IS_WEAK || NativePrototype.forEach && !fails(function () {
|
||||
new NativeConstructor().entries().next();
|
||||
}))
|
||||
);
|
||||
|
||||
if (REPLACE) {
|
||||
// create collection constructor
|
||||
Constructor = common.getConstructor(wrapper, CONSTRUCTOR_NAME, IS_MAP, ADDER);
|
||||
InternalMetadataModule.enable();
|
||||
} else if (isForced(CONSTRUCTOR_NAME, true)) {
|
||||
var instance = new Constructor();
|
||||
// early implementations not supports chaining
|
||||
var HASNT_CHAINING = instance[ADDER](IS_WEAK ? {} : -0, 1) !== instance;
|
||||
// V8 ~ Chromium 40- weak-collections throws on primitives, but should return false
|
||||
var THROWS_ON_PRIMITIVES = fails(function () { instance.has(1); });
|
||||
// most early implementations doesn't supports iterables, most modern - not close it correctly
|
||||
// eslint-disable-next-line no-new -- required for testing
|
||||
var ACCEPT_ITERABLES = checkCorrectnessOfIteration(function (iterable) { new NativeConstructor(iterable); });
|
||||
// for early implementations -0 and +0 not the same
|
||||
var BUGGY_ZERO = !IS_WEAK && fails(function () {
|
||||
// V8 ~ Chromium 42- fails only with 5+ elements
|
||||
var $instance = new NativeConstructor();
|
||||
var index = 5;
|
||||
while (index--) $instance[ADDER](index, index);
|
||||
return !$instance.has(-0);
|
||||
});
|
||||
|
||||
if (!ACCEPT_ITERABLES) {
|
||||
Constructor = wrapper(function (dummy, iterable) {
|
||||
anInstance(dummy, NativePrototype);
|
||||
var that = inheritIfRequired(new NativeConstructor(), dummy, Constructor);
|
||||
if (!isNullOrUndefined(iterable)) iterate(iterable, that[ADDER], { that: that, AS_ENTRIES: IS_MAP });
|
||||
return that;
|
||||
});
|
||||
Constructor.prototype = NativePrototype;
|
||||
NativePrototype.constructor = Constructor;
|
||||
}
|
||||
|
||||
if (THROWS_ON_PRIMITIVES || BUGGY_ZERO) {
|
||||
fixMethod('delete');
|
||||
fixMethod('has');
|
||||
IS_MAP && fixMethod('get');
|
||||
}
|
||||
|
||||
if (BUGGY_ZERO || HASNT_CHAINING) fixMethod(ADDER);
|
||||
|
||||
// weak collections should not contains .clear method
|
||||
if (IS_WEAK && NativePrototype.clear) delete NativePrototype.clear;
|
||||
}
|
||||
|
||||
exported[CONSTRUCTOR_NAME] = Constructor;
|
||||
$({ global: true, constructor: true, forced: Constructor !== NativeConstructor }, exported);
|
||||
|
||||
setToStringTag(Constructor, CONSTRUCTOR_NAME);
|
||||
|
||||
if (!IS_WEAK) common.setStrong(Constructor, CONSTRUCTOR_NAME, IS_MAP);
|
||||
|
||||
return Constructor;
|
||||
};
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
'use strict';
|
||||
var wellKnownSymbol = require('../internals/well-known-symbol');
|
||||
|
||||
var MATCH = wellKnownSymbol('match');
|
||||
|
||||
module.exports = function (METHOD_NAME) {
|
||||
var regexp = /./;
|
||||
try {
|
||||
'/./'[METHOD_NAME](regexp);
|
||||
} catch (error1) {
|
||||
try {
|
||||
regexp[MATCH] = false;
|
||||
return '/./'[METHOD_NAME](regexp);
|
||||
} catch (error2) { /* empty */ }
|
||||
} return false;
|
||||
};
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
'use strict';
|
||||
var uncurryThis = require('../internals/function-uncurry-this');
|
||||
var requireObjectCoercible = require('../internals/require-object-coercible');
|
||||
var toString = require('../internals/to-string');
|
||||
|
||||
var quot = /"/g;
|
||||
var replace = uncurryThis(''.replace);
|
||||
|
||||
// `CreateHTML` abstract operation
|
||||
// https://tc39.es/ecma262/#sec-createhtml
|
||||
module.exports = function (string, tag, attribute, value) {
|
||||
var S = toString(requireObjectCoercible(string));
|
||||
var p1 = '<' + tag;
|
||||
if (attribute !== '') p1 += ' ' + attribute + '="' + replace(toString(value), quot, '"') + '"';
|
||||
return p1 + '>' + S + '</' + tag + '>';
|
||||
};
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
'use strict';
|
||||
var uncurryThis = require('../internals/function-uncurry-this');
|
||||
var fails = require('../internals/fails');
|
||||
var padStart = require('../internals/string-pad').start;
|
||||
|
||||
var $RangeError = RangeError;
|
||||
var $isFinite = isFinite;
|
||||
var abs = Math.abs;
|
||||
var DatePrototype = Date.prototype;
|
||||
var nativeDateToISOString = DatePrototype.toISOString;
|
||||
var thisTimeValue = uncurryThis(DatePrototype.getTime);
|
||||
var getUTCDate = uncurryThis(DatePrototype.getUTCDate);
|
||||
var getUTCFullYear = uncurryThis(DatePrototype.getUTCFullYear);
|
||||
var getUTCHours = uncurryThis(DatePrototype.getUTCHours);
|
||||
var getUTCMilliseconds = uncurryThis(DatePrototype.getUTCMilliseconds);
|
||||
var getUTCMinutes = uncurryThis(DatePrototype.getUTCMinutes);
|
||||
var getUTCMonth = uncurryThis(DatePrototype.getUTCMonth);
|
||||
var getUTCSeconds = uncurryThis(DatePrototype.getUTCSeconds);
|
||||
|
||||
// `Date.prototype.toISOString` method implementation
|
||||
// https://tc39.es/ecma262/#sec-date.prototype.toisostring
|
||||
// PhantomJS / old WebKit fails here:
|
||||
module.exports = (fails(function () {
|
||||
return nativeDateToISOString.call(new Date(-5e13 - 1)) !== '0385-07-25T07:06:39.999Z';
|
||||
}) || !fails(function () {
|
||||
nativeDateToISOString.call(new Date(NaN));
|
||||
})) ? function toISOString() {
|
||||
if (!$isFinite(thisTimeValue(this))) throw new $RangeError('Invalid time value');
|
||||
var date = this;
|
||||
var year = getUTCFullYear(date);
|
||||
var milliseconds = getUTCMilliseconds(date);
|
||||
var sign = year < 0 ? '-' : year > 9999 ? '+' : '';
|
||||
return sign + padStart(abs(year), sign ? 6 : 4, 0) +
|
||||
'-' + padStart(getUTCMonth(date) + 1, 2, 0) +
|
||||
'-' + padStart(getUTCDate(date), 2, 0) +
|
||||
'T' + padStart(getUTCHours(date), 2, 0) +
|
||||
':' + padStart(getUTCMinutes(date), 2, 0) +
|
||||
':' + padStart(getUTCSeconds(date), 2, 0) +
|
||||
'.' + padStart(milliseconds, 3, 0) +
|
||||
'Z';
|
||||
} : nativeDateToISOString;
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
var anObject = require('../internals/an-object');
|
||||
var ordinaryToPrimitive = require('../internals/ordinary-to-primitive');
|
||||
|
||||
var $TypeError = TypeError;
|
||||
|
||||
// `Date.prototype[@@toPrimitive](hint)` method implementation
|
||||
// https://tc39.es/ecma262/#sec-date.prototype-@@toprimitive
|
||||
module.exports = function (hint) {
|
||||
anObject(this);
|
||||
if (hint === 'string' || hint === 'default') hint = 'string';
|
||||
else if (hint !== 'number') throw new $TypeError('Incorrect hint');
|
||||
return ordinaryToPrimitive(this, hint);
|
||||
};
|
||||
+3
-3
@@ -1,13 +1,13 @@
|
||||
'use strict';
|
||||
var global = require('../internals/global');
|
||||
var globalThis = require('../internals/global-this');
|
||||
|
||||
// eslint-disable-next-line es/no-object-defineproperty -- safe
|
||||
var defineProperty = Object.defineProperty;
|
||||
|
||||
module.exports = function (key, value) {
|
||||
try {
|
||||
defineProperty(global, key, { value: value, configurable: true, writable: true });
|
||||
defineProperty(globalThis, key, { value: value, configurable: true, writable: true });
|
||||
} catch (error) {
|
||||
global[key] = value;
|
||||
globalThis[key] = value;
|
||||
} return value;
|
||||
};
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
'use strict';
|
||||
var tryToString = require('../internals/try-to-string');
|
||||
|
||||
var $TypeError = TypeError;
|
||||
|
||||
module.exports = function (O, P) {
|
||||
if (!delete O[P]) throw new $TypeError('Cannot delete property ' + tryToString(P) + ' of ' + tryToString(O));
|
||||
};
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
'use strict';
|
||||
var globalThis = require('../internals/global-this');
|
||||
var getBuiltInNodeModule = require('../internals/get-built-in-node-module');
|
||||
var PROPER_STRUCTURED_CLONE_TRANSFER = require('../internals/structured-clone-proper-transfer');
|
||||
|
||||
var structuredClone = globalThis.structuredClone;
|
||||
var $ArrayBuffer = globalThis.ArrayBuffer;
|
||||
var $MessageChannel = globalThis.MessageChannel;
|
||||
var detach = false;
|
||||
var WorkerThreads, channel, buffer, $detach;
|
||||
|
||||
if (PROPER_STRUCTURED_CLONE_TRANSFER) {
|
||||
detach = function (transferable) {
|
||||
structuredClone(transferable, { transfer: [transferable] });
|
||||
};
|
||||
} else if ($ArrayBuffer) try {
|
||||
if (!$MessageChannel) {
|
||||
WorkerThreads = getBuiltInNodeModule('worker_threads');
|
||||
if (WorkerThreads) $MessageChannel = WorkerThreads.MessageChannel;
|
||||
}
|
||||
|
||||
if ($MessageChannel) {
|
||||
channel = new $MessageChannel();
|
||||
buffer = new $ArrayBuffer(2);
|
||||
|
||||
$detach = function (transferable) {
|
||||
channel.port1.postMessage(null, [transferable]);
|
||||
};
|
||||
|
||||
if (buffer.byteLength === 2) {
|
||||
$detach(buffer);
|
||||
if (buffer.byteLength === 0) detach = $detach;
|
||||
}
|
||||
}
|
||||
} catch (error) { /* empty */ }
|
||||
|
||||
module.exports = detach;
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
'use strict';
|
||||
var global = require('../internals/global');
|
||||
var globalThis = require('../internals/global-this');
|
||||
var isObject = require('../internals/is-object');
|
||||
|
||||
var document = global.document;
|
||||
var document = globalThis.document;
|
||||
// typeof document.createElement is 'object' in old IE
|
||||
var EXISTS = isObject(document) && isObject(document.createElement);
|
||||
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
'use strict';
|
||||
var $TypeError = TypeError;
|
||||
var MAX_SAFE_INTEGER = 0x1FFFFFFFFFFFFF; // 2 ** 53 - 1 == 9007199254740991
|
||||
|
||||
module.exports = function (it) {
|
||||
if (it > MAX_SAFE_INTEGER) throw $TypeError('Maximum allowed index exceeded');
|
||||
return it;
|
||||
};
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
IndexSizeError: { s: 'INDEX_SIZE_ERR', c: 1, m: 1 },
|
||||
DOMStringSizeError: { s: 'DOMSTRING_SIZE_ERR', c: 2, m: 0 },
|
||||
HierarchyRequestError: { s: 'HIERARCHY_REQUEST_ERR', c: 3, m: 1 },
|
||||
WrongDocumentError: { s: 'WRONG_DOCUMENT_ERR', c: 4, m: 1 },
|
||||
InvalidCharacterError: { s: 'INVALID_CHARACTER_ERR', c: 5, m: 1 },
|
||||
NoDataAllowedError: { s: 'NO_DATA_ALLOWED_ERR', c: 6, m: 0 },
|
||||
NoModificationAllowedError: { s: 'NO_MODIFICATION_ALLOWED_ERR', c: 7, m: 1 },
|
||||
NotFoundError: { s: 'NOT_FOUND_ERR', c: 8, m: 1 },
|
||||
NotSupportedError: { s: 'NOT_SUPPORTED_ERR', c: 9, m: 1 },
|
||||
InUseAttributeError: { s: 'INUSE_ATTRIBUTE_ERR', c: 10, m: 1 },
|
||||
InvalidStateError: { s: 'INVALID_STATE_ERR', c: 11, m: 1 },
|
||||
SyntaxError: { s: 'SYNTAX_ERR', c: 12, m: 1 },
|
||||
InvalidModificationError: { s: 'INVALID_MODIFICATION_ERR', c: 13, m: 1 },
|
||||
NamespaceError: { s: 'NAMESPACE_ERR', c: 14, m: 1 },
|
||||
InvalidAccessError: { s: 'INVALID_ACCESS_ERR', c: 15, m: 1 },
|
||||
ValidationError: { s: 'VALIDATION_ERR', c: 16, m: 0 },
|
||||
TypeMismatchError: { s: 'TYPE_MISMATCH_ERR', c: 17, m: 1 },
|
||||
SecurityError: { s: 'SECURITY_ERR', c: 18, m: 1 },
|
||||
NetworkError: { s: 'NETWORK_ERR', c: 19, m: 1 },
|
||||
AbortError: { s: 'ABORT_ERR', c: 20, m: 1 },
|
||||
URLMismatchError: { s: 'URL_MISMATCH_ERR', c: 21, m: 1 },
|
||||
QuotaExceededError: { s: 'QUOTA_EXCEEDED_ERR', c: 22, m: 1 },
|
||||
TimeoutError: { s: 'TIMEOUT_ERR', c: 23, m: 1 },
|
||||
InvalidNodeTypeError: { s: 'INVALID_NODE_TYPE_ERR', c: 24, m: 1 },
|
||||
DataCloneError: { s: 'DATA_CLONE_ERR', c: 25, m: 1 }
|
||||
};
|
||||
-2
@@ -1,2 +0,0 @@
|
||||
'use strict';
|
||||
module.exports = typeof navigator != 'undefined' && String(navigator.userAgent) || '';
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
'use strict';
|
||||
var userAgent = require('../internals/environment-user-agent');
|
||||
|
||||
var firefox = userAgent.match(/firefox\/(\d+)/i);
|
||||
|
||||
module.exports = !!firefox && +firefox[1];
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
'use strict';
|
||||
var UA = require('../internals/environment-user-agent');
|
||||
|
||||
module.exports = /MSIE|Trident/.test(UA);
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
'use strict';
|
||||
var userAgent = require('../internals/environment-user-agent');
|
||||
|
||||
module.exports = /ipad|iphone|ipod/i.test(userAgent) && typeof Pebble != 'undefined';
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
var userAgent = require('../internals/environment-user-agent');
|
||||
|
||||
// eslint-disable-next-line redos/no-vulnerable -- safe
|
||||
module.exports = /(?:ipad|iphone|ipod).*applewebkit/i.test(userAgent);
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
'use strict';
|
||||
var ENVIRONMENT = require('../internals/environment');
|
||||
|
||||
module.exports = ENVIRONMENT === 'NODE';
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
'use strict';
|
||||
var userAgent = require('../internals/environment-user-agent');
|
||||
|
||||
module.exports = /web0s(?!.*chrome)/i.test(userAgent);
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
'use strict';
|
||||
var globalThis = require('../internals/global-this');
|
||||
|
||||
var navigator = globalThis.navigator;
|
||||
var userAgent = navigator && navigator.userAgent;
|
||||
|
||||
module.exports = userAgent ? String(userAgent) : '';
|
||||
Generated
Vendored
+4
-4
@@ -1,9 +1,9 @@
|
||||
'use strict';
|
||||
var global = require('../internals/global');
|
||||
var userAgent = require('../internals/engine-user-agent');
|
||||
var globalThis = require('../internals/global-this');
|
||||
var userAgent = require('../internals/environment-user-agent');
|
||||
|
||||
var process = global.process;
|
||||
var Deno = global.Deno;
|
||||
var process = globalThis.process;
|
||||
var Deno = globalThis.Deno;
|
||||
var versions = process && process.versions || Deno && Deno.version;
|
||||
var v8 = versions && versions.v8;
|
||||
var match, version;
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
'use strict';
|
||||
var userAgent = require('../internals/environment-user-agent');
|
||||
|
||||
var webkit = userAgent.match(/AppleWebKit\/(\d+)\./);
|
||||
|
||||
module.exports = !!webkit && +webkit[1];
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
'use strict';
|
||||
/* global Bun, Deno -- detection */
|
||||
var globalThis = require('../internals/global-this');
|
||||
var userAgent = require('../internals/environment-user-agent');
|
||||
var classof = require('../internals/classof-raw');
|
||||
|
||||
var userAgentStartsWith = function (string) {
|
||||
return userAgent.slice(0, string.length) === string;
|
||||
};
|
||||
|
||||
module.exports = (function () {
|
||||
if (userAgentStartsWith('Bun/')) return 'BUN';
|
||||
if (userAgentStartsWith('Cloudflare-Workers')) return 'CLOUDFLARE';
|
||||
if (userAgentStartsWith('Deno/')) return 'DENO';
|
||||
if (userAgentStartsWith('Node.js/')) return 'NODE';
|
||||
if (globalThis.Bun && typeof Bun.version == 'string') return 'BUN';
|
||||
if (globalThis.Deno && typeof Deno.version == 'object') return 'DENO';
|
||||
if (classof(globalThis.process) === 'process') return 'NODE';
|
||||
if (globalThis.window && globalThis.document) return 'BROWSER';
|
||||
return 'REST';
|
||||
})();
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
'use strict';
|
||||
var uncurryThis = require('../internals/function-uncurry-this');
|
||||
|
||||
var $Error = Error;
|
||||
var replace = uncurryThis(''.replace);
|
||||
|
||||
var TEST = (function (arg) { return String(new $Error(arg).stack); })('zxcasd');
|
||||
// eslint-disable-next-line redos/no-vulnerable, sonarjs/slow-regex -- safe
|
||||
var V8_OR_CHAKRA_STACK_ENTRY = /\n\s*at [^:]*:[^\n]*/;
|
||||
var IS_V8_OR_CHAKRA_STACK = V8_OR_CHAKRA_STACK_ENTRY.test(TEST);
|
||||
|
||||
module.exports = function (stack, dropEntries) {
|
||||
if (IS_V8_OR_CHAKRA_STACK && typeof stack == 'string' && !$Error.prepareStackTrace) {
|
||||
while (dropEntries--) stack = replace(stack, V8_OR_CHAKRA_STACK_ENTRY, '');
|
||||
} return stack;
|
||||
};
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
'use strict';
|
||||
var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
|
||||
var clearErrorStack = require('../internals/error-stack-clear');
|
||||
var ERROR_STACK_INSTALLABLE = require('../internals/error-stack-installable');
|
||||
|
||||
// non-standard V8
|
||||
// eslint-disable-next-line es/no-nonstandard-error-properties -- safe
|
||||
var captureStackTrace = Error.captureStackTrace;
|
||||
|
||||
module.exports = function (error, C, stack, dropEntries) {
|
||||
if (ERROR_STACK_INSTALLABLE) {
|
||||
if (captureStackTrace) captureStackTrace(error, C);
|
||||
else createNonEnumerableProperty(error, 'stack', clearErrorStack(stack, dropEntries));
|
||||
}
|
||||
};
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
'use strict';
|
||||
var fails = require('../internals/fails');
|
||||
var createPropertyDescriptor = require('../internals/create-property-descriptor');
|
||||
|
||||
module.exports = !fails(function () {
|
||||
var error = new Error('a');
|
||||
if (!('stack' in error)) return true;
|
||||
// eslint-disable-next-line es/no-object-defineproperty -- safe
|
||||
Object.defineProperty(error, 'stack', createPropertyDescriptor(1, 7));
|
||||
return error.stack !== 7;
|
||||
});
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
'use strict';
|
||||
var DESCRIPTORS = require('../internals/descriptors');
|
||||
var fails = require('../internals/fails');
|
||||
var anObject = require('../internals/an-object');
|
||||
var normalizeStringArgument = require('../internals/normalize-string-argument');
|
||||
|
||||
var nativeErrorToString = Error.prototype.toString;
|
||||
|
||||
var INCORRECT_TO_STRING = fails(function () {
|
||||
if (DESCRIPTORS) {
|
||||
// Chrome 32- incorrectly call accessor
|
||||
// eslint-disable-next-line es/no-object-create, es/no-object-defineproperty -- safe
|
||||
var object = Object.create(Object.defineProperty({}, 'name', { get: function () {
|
||||
return this === object;
|
||||
} }));
|
||||
if (nativeErrorToString.call(object) !== 'true') return true;
|
||||
}
|
||||
// FF10- does not properly handle non-strings
|
||||
return nativeErrorToString.call({ message: 1, name: 2 }) !== '2: 1'
|
||||
// IE8 does not properly handle defaults
|
||||
|| nativeErrorToString.call({}) !== 'Error';
|
||||
});
|
||||
|
||||
module.exports = INCORRECT_TO_STRING ? function toString() {
|
||||
var O = anObject(this);
|
||||
var name = normalizeStringArgument(O.name, 'Error');
|
||||
var message = normalizeStringArgument(O.message);
|
||||
return !name ? message : !message ? name : name + ': ' + message;
|
||||
} : nativeErrorToString;
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
'use strict';
|
||||
var global = require('../internals/global');
|
||||
var globalThis = require('../internals/global-this');
|
||||
var getOwnPropertyDescriptor = require('../internals/object-get-own-property-descriptor').f;
|
||||
var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
|
||||
var defineBuiltIn = require('../internals/define-built-in');
|
||||
@@ -28,11 +28,11 @@ module.exports = function (options, source) {
|
||||
var STATIC = options.stat;
|
||||
var FORCED, target, key, targetProperty, sourceProperty, descriptor;
|
||||
if (GLOBAL) {
|
||||
target = global;
|
||||
target = globalThis;
|
||||
} else if (STATIC) {
|
||||
target = global[TARGET] || defineGlobalProperty(TARGET, {});
|
||||
target = globalThis[TARGET] || defineGlobalProperty(TARGET, {});
|
||||
} else {
|
||||
target = global[TARGET] && global[TARGET].prototype;
|
||||
target = globalThis[TARGET] && globalThis[TARGET].prototype;
|
||||
}
|
||||
if (target) for (key in source) {
|
||||
sourceProperty = source[key];
|
||||
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
'use strict';
|
||||
// TODO: Remove from `core-js@4` since it's moved to entry points
|
||||
require('../modules/es.regexp.exec');
|
||||
var call = require('../internals/function-call');
|
||||
var defineBuiltIn = require('../internals/define-built-in');
|
||||
var regexpExec = require('../internals/regexp-exec');
|
||||
var fails = require('../internals/fails');
|
||||
var wellKnownSymbol = require('../internals/well-known-symbol');
|
||||
var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
|
||||
|
||||
var SPECIES = wellKnownSymbol('species');
|
||||
var RegExpPrototype = RegExp.prototype;
|
||||
|
||||
module.exports = function (KEY, exec, FORCED, SHAM) {
|
||||
var SYMBOL = wellKnownSymbol(KEY);
|
||||
|
||||
var DELEGATES_TO_SYMBOL = !fails(function () {
|
||||
// String methods call symbol-named RegExp methods
|
||||
var O = {};
|
||||
// eslint-disable-next-line unicorn/no-immediate-mutation -- ES3 syntax limitation
|
||||
O[SYMBOL] = function () { return 7; };
|
||||
return ''[KEY](O) !== 7;
|
||||
});
|
||||
|
||||
var DELEGATES_TO_EXEC = DELEGATES_TO_SYMBOL && !fails(function () {
|
||||
// Symbol-named RegExp methods call .exec
|
||||
var execCalled = false;
|
||||
var re = /a/;
|
||||
|
||||
if (KEY === 'split') {
|
||||
// We can't use real regex here since it causes deoptimization
|
||||
// and serious performance degradation in V8
|
||||
// https://github.com/zloirock/core-js/issues/306
|
||||
// RegExp[@@split] doesn't call the regex's exec method, but first creates
|
||||
// a new one. We need to return the patched regex when creating the new one.
|
||||
var constructor = {};
|
||||
// eslint-disable-next-line unicorn/no-immediate-mutation -- ES3 syntax limitation
|
||||
constructor[SPECIES] = function () { return re; };
|
||||
re = { constructor: constructor, flags: '' };
|
||||
// eslint-disable-next-line unicorn/no-immediate-mutation -- ES3 syntax limitation
|
||||
re[SYMBOL] = /./[SYMBOL];
|
||||
}
|
||||
|
||||
re.exec = function () {
|
||||
execCalled = true;
|
||||
return null;
|
||||
};
|
||||
|
||||
re[SYMBOL]('');
|
||||
return !execCalled;
|
||||
});
|
||||
|
||||
if (
|
||||
!DELEGATES_TO_SYMBOL ||
|
||||
!DELEGATES_TO_EXEC ||
|
||||
FORCED
|
||||
) {
|
||||
var nativeRegExpMethod = /./[SYMBOL];
|
||||
var methods = exec(SYMBOL, ''[KEY], function (nativeMethod, regexp, str, arg2, forceStringMethod) {
|
||||
var $exec = regexp.exec;
|
||||
if ($exec === regexpExec || $exec === RegExpPrototype.exec) {
|
||||
if (DELEGATES_TO_SYMBOL && !forceStringMethod) {
|
||||
// The native String method already delegates to @@method (this
|
||||
// polyfilled function), leasing to infinite recursion.
|
||||
// We avoid it by directly calling the native @@method method.
|
||||
return { done: true, value: call(nativeRegExpMethod, regexp, str, arg2) };
|
||||
}
|
||||
return { done: true, value: call(nativeMethod, str, regexp, arg2) };
|
||||
}
|
||||
return { done: false };
|
||||
});
|
||||
|
||||
defineBuiltIn(String.prototype, KEY, methods[0]);
|
||||
defineBuiltIn(RegExpPrototype, SYMBOL, methods[1]);
|
||||
}
|
||||
|
||||
if (SHAM) createNonEnumerableProperty(RegExpPrototype[SYMBOL], 'sham', true);
|
||||
};
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
'use strict';
|
||||
var isArray = require('../internals/is-array');
|
||||
var lengthOfArrayLike = require('../internals/length-of-array-like');
|
||||
var doesNotExceedSafeInteger = require('../internals/does-not-exceed-safe-integer');
|
||||
var bind = require('../internals/function-bind-context');
|
||||
var createProperty = require('../internals/create-property');
|
||||
|
||||
// `FlattenIntoArray` abstract operation
|
||||
// https://tc39.es/ecma262/#sec-flattenintoarray
|
||||
var flattenIntoArray = function (target, original, source, sourceLen, start, depth, mapper, thisArg) {
|
||||
var targetIndex = start;
|
||||
var sourceIndex = 0;
|
||||
var mapFn = mapper ? bind(mapper, thisArg) : false;
|
||||
var element, elementLen;
|
||||
|
||||
while (sourceIndex < sourceLen) {
|
||||
if (sourceIndex in source) {
|
||||
element = mapFn ? mapFn(source[sourceIndex], sourceIndex, original) : source[sourceIndex];
|
||||
|
||||
if (depth > 0 && isArray(element)) {
|
||||
elementLen = lengthOfArrayLike(element);
|
||||
targetIndex = flattenIntoArray(target, original, element, elementLen, targetIndex, depth - 1) - 1;
|
||||
} else {
|
||||
doesNotExceedSafeInteger(targetIndex + 1);
|
||||
createProperty(target, targetIndex, element);
|
||||
}
|
||||
|
||||
targetIndex++;
|
||||
}
|
||||
sourceIndex++;
|
||||
}
|
||||
return targetIndex;
|
||||
};
|
||||
|
||||
module.exports = flattenIntoArray;
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
'use strict';
|
||||
var fails = require('../internals/fails');
|
||||
|
||||
module.exports = !fails(function () {
|
||||
// eslint-disable-next-line es/no-object-isextensible, es/no-object-preventextensions -- required for testing
|
||||
return Object.isExtensible(Object.preventExtensions({}));
|
||||
});
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
'use strict';
|
||||
var NATIVE_BIND = require('../internals/function-bind-native');
|
||||
|
||||
var FunctionPrototype = Function.prototype;
|
||||
var apply = FunctionPrototype.apply;
|
||||
var call = FunctionPrototype.call;
|
||||
|
||||
// eslint-disable-next-line es/no-function-prototype-bind, es/no-reflect -- safe
|
||||
module.exports = typeof Reflect == 'object' && Reflect.apply || (NATIVE_BIND ? call.bind(apply) : function () {
|
||||
return call.apply(apply, arguments);
|
||||
});
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
'use strict';
|
||||
var uncurryThis = require('../internals/function-uncurry-this');
|
||||
var aCallable = require('../internals/a-callable');
|
||||
var isObject = require('../internals/is-object');
|
||||
var hasOwn = require('../internals/has-own-property');
|
||||
var arraySlice = require('../internals/array-slice');
|
||||
var NATIVE_BIND = require('../internals/function-bind-native');
|
||||
|
||||
var $Function = Function;
|
||||
var concat = uncurryThis([].concat);
|
||||
var join = uncurryThis([].join);
|
||||
var factories = {};
|
||||
|
||||
var construct = function (C, argsLength, args) {
|
||||
if (!hasOwn(factories, argsLength)) {
|
||||
var list = [];
|
||||
var i = 0;
|
||||
for (; i < argsLength; i++) list[i] = 'a[' + i + ']';
|
||||
factories[argsLength] = $Function('C,a', 'return new C(' + join(list, ',') + ')');
|
||||
} return factories[argsLength](C, args);
|
||||
};
|
||||
|
||||
// `Function.prototype.bind` method implementation
|
||||
// https://tc39.es/ecma262/#sec-function.prototype.bind
|
||||
// eslint-disable-next-line es/no-function-prototype-bind -- detection
|
||||
module.exports = NATIVE_BIND ? $Function.bind : function bind(that /* , ...args */) {
|
||||
var F = aCallable(this);
|
||||
var Prototype = F.prototype;
|
||||
var partArgs = arraySlice(arguments, 1);
|
||||
var boundFunction = function bound(/* args... */) {
|
||||
var args = concat(partArgs, arraySlice(arguments));
|
||||
return this instanceof boundFunction ? construct(F, args.length, args) : F.apply(that, args);
|
||||
};
|
||||
if (isObject(Prototype)) boundFunction.prototype = Prototype;
|
||||
return boundFunction;
|
||||
};
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
var NATIVE_BIND = require('../internals/function-bind-native');
|
||||
|
||||
var call = Function.prototype.call;
|
||||
|
||||
// eslint-disable-next-line es/no-function-prototype-bind -- safe
|
||||
module.exports = NATIVE_BIND ? call.bind(call) : function () {
|
||||
return call.apply(call, arguments);
|
||||
};
|
||||
|
||||
+1
@@ -3,6 +3,7 @@ var NATIVE_BIND = require('../internals/function-bind-native');
|
||||
|
||||
var FunctionPrototype = Function.prototype;
|
||||
var call = FunctionPrototype.call;
|
||||
// eslint-disable-next-line es/no-function-prototype-bind -- safe
|
||||
var uncurryThisWithBind = NATIVE_BIND && FunctionPrototype.bind.bind(call, call);
|
||||
|
||||
module.exports = NATIVE_BIND ? uncurryThisWithBind : function (fn) {
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
'use strict';
|
||||
var $TypeError = TypeError;
|
||||
|
||||
module.exports = function (options) {
|
||||
var alphabet = options && options.alphabet;
|
||||
if (alphabet === undefined || alphabet === 'base64' || alphabet === 'base64url') return alphabet || 'base64';
|
||||
throw new $TypeError('Incorrect `alphabet` option');
|
||||
};
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
'use strict';
|
||||
var call = require('../internals/function-call');
|
||||
var AsyncFromSyncIterator = require('../internals/async-from-sync-iterator');
|
||||
var anObject = require('../internals/an-object');
|
||||
var getIterator = require('../internals/get-iterator');
|
||||
var getIteratorDirect = require('../internals/get-iterator-direct');
|
||||
var getMethod = require('../internals/get-method');
|
||||
var wellKnownSymbol = require('../internals/well-known-symbol');
|
||||
|
||||
var ASYNC_ITERATOR = wellKnownSymbol('asyncIterator');
|
||||
|
||||
module.exports = function (it, usingIterator) {
|
||||
var method = arguments.length < 2 ? getMethod(it, ASYNC_ITERATOR) : usingIterator;
|
||||
return method ? anObject(call(method, it)) : new AsyncFromSyncIterator(getIteratorDirect(getIterator(it)));
|
||||
};
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
'use strict';
|
||||
var globalThis = require('../internals/global-this');
|
||||
var IS_NODE = require('../internals/environment-is-node');
|
||||
|
||||
module.exports = function (name) {
|
||||
if (IS_NODE) {
|
||||
try {
|
||||
return globalThis.process.getBuiltinModule(name);
|
||||
} catch (error) { /* empty */ }
|
||||
try {
|
||||
// eslint-disable-next-line no-new-func -- safe
|
||||
return Function('return require("' + name + '")')();
|
||||
} catch (error) { /* empty */ }
|
||||
}
|
||||
};
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
'use strict';
|
||||
var globalThis = require('../internals/global-this');
|
||||
|
||||
module.exports = function (CONSTRUCTOR, METHOD) {
|
||||
var Constructor = globalThis[CONSTRUCTOR];
|
||||
var Prototype = Constructor && Constructor.prototype;
|
||||
return Prototype && Prototype[METHOD];
|
||||
};
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
'use strict';
|
||||
var global = require('../internals/global');
|
||||
var globalThis = require('../internals/global-this');
|
||||
var isCallable = require('../internals/is-callable');
|
||||
|
||||
var aFunction = function (argument) {
|
||||
@@ -7,5 +7,5 @@ var aFunction = function (argument) {
|
||||
};
|
||||
|
||||
module.exports = function (namespace, method) {
|
||||
return arguments.length < 2 ? aFunction(global[namespace]) : global[namespace] && global[namespace][method];
|
||||
return arguments.length < 2 ? aFunction(globalThis[namespace]) : globalThis[namespace] && globalThis[namespace][method];
|
||||
};
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
'use strict';
|
||||
// `GetIteratorDirect(obj)` abstract operation
|
||||
// https://tc39.es/ecma262/#sec-getiteratordirect
|
||||
module.exports = function (obj) {
|
||||
return {
|
||||
iterator: obj,
|
||||
next: obj.next,
|
||||
done: false
|
||||
};
|
||||
};
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
'use strict';
|
||||
var call = require('../internals/function-call');
|
||||
var anObject = require('../internals/an-object');
|
||||
var getIteratorDirect = require('../internals/get-iterator-direct');
|
||||
var getIteratorMethod = require('../internals/get-iterator-method');
|
||||
|
||||
module.exports = function (obj, stringHandling) {
|
||||
if (!stringHandling || typeof obj !== 'string') anObject(obj);
|
||||
var method = getIteratorMethod(obj);
|
||||
return getIteratorDirect(anObject(method !== undefined ? call(method, obj) : obj));
|
||||
};
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
'use strict';
|
||||
var aCallable = require('../internals/a-callable');
|
||||
var anObject = require('../internals/an-object');
|
||||
var call = require('../internals/function-call');
|
||||
var toIntegerOrInfinity = require('../internals/to-integer-or-infinity');
|
||||
var getIteratorDirect = require('../internals/get-iterator-direct');
|
||||
|
||||
var INVALID_SIZE = 'Invalid size';
|
||||
var $RangeError = RangeError;
|
||||
var $TypeError = TypeError;
|
||||
var max = Math.max;
|
||||
|
||||
var SetRecord = function (set, intSize) {
|
||||
this.set = set;
|
||||
this.size = max(intSize, 0);
|
||||
this.has = aCallable(set.has);
|
||||
this.keys = aCallable(set.keys);
|
||||
};
|
||||
|
||||
SetRecord.prototype = {
|
||||
getIterator: function () {
|
||||
return getIteratorDirect(anObject(call(this.keys, this.set)));
|
||||
},
|
||||
includes: function (it) {
|
||||
return call(this.has, this.set, it);
|
||||
}
|
||||
};
|
||||
|
||||
// `GetSetRecord` abstract operation
|
||||
// https://tc39.es/proposal-set-methods/#sec-getsetrecord
|
||||
module.exports = function (obj) {
|
||||
anObject(obj);
|
||||
var numSize = +obj.size;
|
||||
// NOTE: If size is undefined, then numSize will be NaN
|
||||
// eslint-disable-next-line no-self-compare -- NaN check
|
||||
if (numSize !== numSize) throw new $TypeError(INVALID_SIZE);
|
||||
var intSize = toIntegerOrInfinity(numSize);
|
||||
if (intSize < 0) throw new $RangeError(INVALID_SIZE);
|
||||
return new SetRecord(obj, intSize);
|
||||
};
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
'use strict';
|
||||
var uncurryThis = require('../internals/function-uncurry-this');
|
||||
var toObject = require('../internals/to-object');
|
||||
|
||||
var floor = Math.floor;
|
||||
var charAt = uncurryThis(''.charAt);
|
||||
var replace = uncurryThis(''.replace);
|
||||
var stringSlice = uncurryThis(''.slice);
|
||||
// eslint-disable-next-line redos/no-vulnerable -- safe
|
||||
var SUBSTITUTION_SYMBOLS = /\$([$&'`]|\d{1,2}|<[^>]*>)/g;
|
||||
var SUBSTITUTION_SYMBOLS_NO_NAMED = /\$([$&'`]|\d{1,2})/g;
|
||||
|
||||
// `GetSubstitution` abstract operation
|
||||
// https://tc39.es/ecma262/#sec-getsubstitution
|
||||
module.exports = function (matched, str, position, captures, namedCaptures, replacement) {
|
||||
var tailPos = position + matched.length;
|
||||
var m = captures.length;
|
||||
var symbols = SUBSTITUTION_SYMBOLS_NO_NAMED;
|
||||
if (namedCaptures !== undefined) {
|
||||
namedCaptures = toObject(namedCaptures);
|
||||
symbols = SUBSTITUTION_SYMBOLS;
|
||||
}
|
||||
return replace(replacement, symbols, function (match, ch) {
|
||||
var capture;
|
||||
switch (charAt(ch, 0)) {
|
||||
case '$': return '$';
|
||||
case '&': return matched;
|
||||
case '`': return stringSlice(str, 0, position);
|
||||
case "'": return stringSlice(str, tailPos);
|
||||
case '<':
|
||||
capture = namedCaptures[stringSlice(ch, 1, -1)];
|
||||
break;
|
||||
default: // \d\d?
|
||||
var n = +ch;
|
||||
if (n === 0) return match;
|
||||
if (n > m) {
|
||||
var f = floor(n / 10);
|
||||
if (f === 0) return match;
|
||||
if (f <= m) return captures[f - 1] === undefined ? charAt(ch, 1) : captures[f - 1] + charAt(ch, 1);
|
||||
return match;
|
||||
}
|
||||
capture = captures[n - 1];
|
||||
}
|
||||
return capture === undefined ? '' : capture;
|
||||
});
|
||||
};
|
||||
Generated
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
'use strict';
|
||||
module.exports = function (a, b) {
|
||||
try {
|
||||
// eslint-disable-next-line no-console -- safe
|
||||
arguments.length === 1 ? console.error(a) : console.error(a, b);
|
||||
} catch (error) { /* empty */ }
|
||||
};
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
'use strict';
|
||||
// IEEE754 conversions based on https://github.com/feross/ieee754
|
||||
var $Array = Array;
|
||||
var abs = Math.abs;
|
||||
var pow = Math.pow;
|
||||
var floor = Math.floor;
|
||||
var log = Math.log;
|
||||
var LN2 = Math.LN2;
|
||||
|
||||
var pack = function (number, mantissaLength, bytes) {
|
||||
var buffer = $Array(bytes);
|
||||
var exponentLength = bytes * 8 - mantissaLength - 1;
|
||||
var eMax = (1 << exponentLength) - 1;
|
||||
var eBias = eMax >> 1;
|
||||
var rt = mantissaLength === 23 ? pow(2, -24) - pow(2, -77) : 0;
|
||||
var sign = number < 0 || number === 0 && 1 / number < 0 ? 1 : 0;
|
||||
var index = 0;
|
||||
var exponent, mantissa, c;
|
||||
number = abs(number);
|
||||
// eslint-disable-next-line no-self-compare -- NaN check
|
||||
if (number !== number || number === Infinity) {
|
||||
// eslint-disable-next-line no-self-compare -- NaN check
|
||||
mantissa = number !== number ? 1 : 0;
|
||||
exponent = eMax;
|
||||
} else {
|
||||
exponent = floor(log(number) / LN2);
|
||||
c = pow(2, -exponent);
|
||||
if (number * c < 1) {
|
||||
exponent--;
|
||||
c *= 2;
|
||||
}
|
||||
if (exponent + eBias >= 1) {
|
||||
number += rt / c;
|
||||
} else {
|
||||
number += rt * pow(2, 1 - eBias);
|
||||
}
|
||||
if (number * c >= 2) {
|
||||
exponent++;
|
||||
c /= 2;
|
||||
}
|
||||
if (exponent + eBias >= eMax) {
|
||||
mantissa = 0;
|
||||
exponent = eMax;
|
||||
} else if (exponent + eBias >= 1) {
|
||||
mantissa = (number * c - 1) * pow(2, mantissaLength);
|
||||
exponent += eBias;
|
||||
} else {
|
||||
mantissa = number * pow(2, eBias - 1) * pow(2, mantissaLength);
|
||||
exponent = 0;
|
||||
}
|
||||
}
|
||||
while (mantissaLength >= 8) {
|
||||
buffer[index++] = mantissa & 255;
|
||||
mantissa /= 256;
|
||||
mantissaLength -= 8;
|
||||
}
|
||||
exponent = exponent << mantissaLength | mantissa;
|
||||
exponentLength += mantissaLength;
|
||||
while (exponentLength > 0) {
|
||||
buffer[index++] = exponent & 255;
|
||||
exponent /= 256;
|
||||
exponentLength -= 8;
|
||||
}
|
||||
buffer[index - 1] |= sign * 128;
|
||||
return buffer;
|
||||
};
|
||||
|
||||
var unpack = function (buffer, mantissaLength) {
|
||||
var bytes = buffer.length;
|
||||
var exponentLength = bytes * 8 - mantissaLength - 1;
|
||||
var eMax = (1 << exponentLength) - 1;
|
||||
var eBias = eMax >> 1;
|
||||
var nBits = exponentLength - 7;
|
||||
var index = bytes - 1;
|
||||
var sign = buffer[index--];
|
||||
var exponent = sign & 127;
|
||||
var mantissa;
|
||||
sign >>= 7;
|
||||
while (nBits > 0) {
|
||||
exponent = exponent * 256 + buffer[index--];
|
||||
nBits -= 8;
|
||||
}
|
||||
mantissa = exponent & (1 << -nBits) - 1;
|
||||
exponent >>= -nBits;
|
||||
nBits += mantissaLength;
|
||||
while (nBits > 0) {
|
||||
mantissa = mantissa * 256 + buffer[index--];
|
||||
nBits -= 8;
|
||||
}
|
||||
if (exponent === 0) {
|
||||
exponent = 1 - eBias;
|
||||
} else if (exponent === eMax) {
|
||||
return mantissa ? NaN : sign ? -Infinity : Infinity;
|
||||
} else {
|
||||
mantissa += pow(2, mantissaLength);
|
||||
exponent -= eBias;
|
||||
} return (sign ? -1 : 1) * mantissa * pow(2, exponent - mantissaLength);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
pack: pack,
|
||||
unpack: unpack
|
||||
};
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
'use strict';
|
||||
var isCallable = require('../internals/is-callable');
|
||||
var isObject = require('../internals/is-object');
|
||||
var setPrototypeOf = require('../internals/object-set-prototype-of');
|
||||
|
||||
// makes subclassing work correct for wrapped built-ins
|
||||
module.exports = function ($this, dummy, Wrapper) {
|
||||
var NewTarget, NewTargetPrototype;
|
||||
if (
|
||||
// it can work only with native `setPrototypeOf`
|
||||
setPrototypeOf &&
|
||||
// we haven't completely correct pre-ES6 way for getting `new.target`, so use this
|
||||
isCallable(NewTarget = dummy.constructor) &&
|
||||
NewTarget !== Wrapper &&
|
||||
isObject(NewTargetPrototype = NewTarget.prototype) &&
|
||||
NewTargetPrototype !== Wrapper.prototype
|
||||
) setPrototypeOf($this, NewTargetPrototype);
|
||||
return $this;
|
||||
};
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
'use strict';
|
||||
var isObject = require('../internals/is-object');
|
||||
var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
|
||||
|
||||
// `InstallErrorCause` abstract operation
|
||||
// https://tc39.es/ecma262/#sec-installerrorcause
|
||||
module.exports = function (O, options) {
|
||||
if (isObject(options) && 'cause' in options) {
|
||||
createNonEnumerableProperty(O, 'cause', options.cause);
|
||||
}
|
||||
};
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
'use strict';
|
||||
var $ = require('../internals/export');
|
||||
var uncurryThis = require('../internals/function-uncurry-this');
|
||||
var hiddenKeys = require('../internals/hidden-keys');
|
||||
var isObject = require('../internals/is-object');
|
||||
var hasOwn = require('../internals/has-own-property');
|
||||
var defineProperty = require('../internals/object-define-property').f;
|
||||
var getOwnPropertyNamesModule = require('../internals/object-get-own-property-names');
|
||||
var getOwnPropertyNamesExternalModule = require('../internals/object-get-own-property-names-external');
|
||||
var isExtensible = require('../internals/object-is-extensible');
|
||||
var uid = require('../internals/uid');
|
||||
var FREEZING = require('../internals/freezing');
|
||||
|
||||
var REQUIRED = false;
|
||||
var METADATA = uid('meta');
|
||||
var id = 0;
|
||||
|
||||
var setMetadata = function (it) {
|
||||
defineProperty(it, METADATA, { value: {
|
||||
objectID: 'O' + id++, // object ID
|
||||
weakData: {} // weak collections IDs
|
||||
} });
|
||||
};
|
||||
|
||||
var fastKey = function (it, create) {
|
||||
// return a primitive with prefix
|
||||
if (!isObject(it)) return typeof it == 'symbol' ? it : (typeof it == 'string' ? 'S' : 'P') + it;
|
||||
if (!hasOwn(it, METADATA)) {
|
||||
// can't set metadata to uncaught frozen object
|
||||
if (!isExtensible(it)) return 'F';
|
||||
// not necessary to add metadata
|
||||
if (!create) return 'E';
|
||||
// add missing metadata
|
||||
setMetadata(it);
|
||||
// return object ID
|
||||
} return it[METADATA].objectID;
|
||||
};
|
||||
|
||||
var getWeakData = function (it, create) {
|
||||
if (!hasOwn(it, METADATA)) {
|
||||
// can't set metadata to uncaught frozen object
|
||||
if (!isExtensible(it)) return true;
|
||||
// not necessary to add metadata
|
||||
if (!create) return false;
|
||||
// add missing metadata
|
||||
setMetadata(it);
|
||||
// return the store of weak collections IDs
|
||||
} return it[METADATA].weakData;
|
||||
};
|
||||
|
||||
// add metadata on freeze-family methods calling
|
||||
var onFreeze = function (it) {
|
||||
if (FREEZING && REQUIRED && isExtensible(it) && !hasOwn(it, METADATA)) setMetadata(it);
|
||||
return it;
|
||||
};
|
||||
|
||||
var enable = function () {
|
||||
meta.enable = function () { /* empty */ };
|
||||
REQUIRED = true;
|
||||
var getOwnPropertyNames = getOwnPropertyNamesModule.f;
|
||||
var splice = uncurryThis([].splice);
|
||||
var test = {};
|
||||
// eslint-disable-next-line unicorn/no-immediate-mutation -- ES3 syntax limitation
|
||||
test[METADATA] = 1;
|
||||
|
||||
// prevent exposing of metadata key
|
||||
if (getOwnPropertyNames(test).length) {
|
||||
getOwnPropertyNamesModule.f = function (it) {
|
||||
var result = getOwnPropertyNames(it);
|
||||
for (var i = 0, length = result.length; i < length; i++) {
|
||||
if (result[i] === METADATA) {
|
||||
splice(result, i, 1);
|
||||
break;
|
||||
}
|
||||
} return result;
|
||||
};
|
||||
|
||||
$({ target: 'Object', stat: true, forced: true }, {
|
||||
getOwnPropertyNames: getOwnPropertyNamesExternalModule.f
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
var meta = module.exports = {
|
||||
enable: enable,
|
||||
fastKey: fastKey,
|
||||
getWeakData: getWeakData,
|
||||
onFreeze: onFreeze
|
||||
};
|
||||
|
||||
hiddenKeys[METADATA] = true;
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
var NATIVE_WEAK_MAP = require('../internals/weak-map-basic-detection');
|
||||
var global = require('../internals/global');
|
||||
var globalThis = require('../internals/global-this');
|
||||
var isObject = require('../internals/is-object');
|
||||
var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
|
||||
var hasOwn = require('../internals/has-own-property');
|
||||
@@ -9,8 +9,8 @@ var sharedKey = require('../internals/shared-key');
|
||||
var hiddenKeys = require('../internals/hidden-keys');
|
||||
|
||||
var OBJECT_ALREADY_INITIALIZED = 'Object already initialized';
|
||||
var TypeError = global.TypeError;
|
||||
var WeakMap = global.WeakMap;
|
||||
var TypeError = globalThis.TypeError;
|
||||
var WeakMap = globalThis.WeakMap;
|
||||
var set, get, has;
|
||||
|
||||
var enforce = function (it) {
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
var classof = require('../internals/classof-raw');
|
||||
|
||||
// `IsArray` abstract operation
|
||||
// https://tc39.es/ecma262/#sec-isarray
|
||||
// eslint-disable-next-line es/no-array-isarray -- safe
|
||||
module.exports = Array.isArray || function isArray(argument) {
|
||||
return classof(argument) === 'Array';
|
||||
};
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
'use strict';
|
||||
var classof = require('../internals/classof');
|
||||
|
||||
module.exports = function (it) {
|
||||
var klass = classof(it);
|
||||
return klass === 'BigInt64Array' || klass === 'BigUint64Array';
|
||||
};
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
'use strict';
|
||||
var hasOwn = require('../internals/has-own-property');
|
||||
|
||||
module.exports = function (descriptor) {
|
||||
return descriptor !== undefined && (hasOwn(descriptor, 'value') || hasOwn(descriptor, 'writable'));
|
||||
};
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
'use strict';
|
||||
var isObject = require('../internals/is-object');
|
||||
|
||||
var floor = Math.floor;
|
||||
|
||||
// `IsIntegralNumber` abstract operation
|
||||
// https://tc39.es/ecma262/#sec-isintegralnumber
|
||||
// eslint-disable-next-line es/no-number-isinteger -- safe
|
||||
module.exports = Number.isInteger || function isInteger(it) {
|
||||
return !isObject(it) && isFinite(it) && floor(it) === it;
|
||||
};
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
var isObject = require('../internals/is-object');
|
||||
var getInternalState = require('../internals/internal-state').get;
|
||||
|
||||
module.exports = function isRawJSON(O) {
|
||||
if (!isObject(O)) return false;
|
||||
var state = getInternalState(O);
|
||||
return !!state && state.type === 'RawJSON';
|
||||
};
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
'use strict';
|
||||
var isObject = require('../internals/is-object');
|
||||
var classof = require('../internals/classof-raw');
|
||||
var wellKnownSymbol = require('../internals/well-known-symbol');
|
||||
|
||||
var MATCH = wellKnownSymbol('match');
|
||||
|
||||
// `IsRegExp` abstract operation
|
||||
// https://tc39.es/ecma262/#sec-isregexp
|
||||
module.exports = function (it) {
|
||||
var isRegExp;
|
||||
return isObject(it) && ((isRegExp = it[MATCH]) !== undefined ? !!isRegExp : classof(it) === 'RegExp');
|
||||
};
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
'use strict';
|
||||
var call = require('../internals/function-call');
|
||||
|
||||
module.exports = function (record, fn, ITERATOR_INSTEAD_OF_RECORD) {
|
||||
var iterator = ITERATOR_INSTEAD_OF_RECORD ? record : record.iterator;
|
||||
var next = record.next;
|
||||
var step, result;
|
||||
while (!(step = call(next, iterator)).done) {
|
||||
result = fn(step.value);
|
||||
if (result !== undefined) return result;
|
||||
}
|
||||
};
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
'use strict';
|
||||
var bind = require('../internals/function-bind-context');
|
||||
var call = require('../internals/function-call');
|
||||
var anObject = require('../internals/an-object');
|
||||
var tryToString = require('../internals/try-to-string');
|
||||
var isArrayIteratorMethod = require('../internals/is-array-iterator-method');
|
||||
var lengthOfArrayLike = require('../internals/length-of-array-like');
|
||||
var isPrototypeOf = require('../internals/object-is-prototype-of');
|
||||
var getIterator = require('../internals/get-iterator');
|
||||
var getIteratorMethod = require('../internals/get-iterator-method');
|
||||
var iteratorClose = require('../internals/iterator-close');
|
||||
|
||||
var $TypeError = TypeError;
|
||||
|
||||
var Result = function (stopped, result) {
|
||||
this.stopped = stopped;
|
||||
this.result = result;
|
||||
};
|
||||
|
||||
var ResultPrototype = Result.prototype;
|
||||
|
||||
module.exports = function (iterable, unboundFunction, options) {
|
||||
var that = options && options.that;
|
||||
var AS_ENTRIES = !!(options && options.AS_ENTRIES);
|
||||
var IS_RECORD = !!(options && options.IS_RECORD);
|
||||
var IS_ITERATOR = !!(options && options.IS_ITERATOR);
|
||||
var INTERRUPTED = !!(options && options.INTERRUPTED);
|
||||
var fn = bind(unboundFunction, that);
|
||||
var iterator, iterFn, index, length, result, next, step;
|
||||
|
||||
var stop = function (condition) {
|
||||
if (iterator) iteratorClose(iterator, 'normal');
|
||||
return new Result(true, condition);
|
||||
};
|
||||
|
||||
var callFn = function (value) {
|
||||
if (AS_ENTRIES) {
|
||||
anObject(value);
|
||||
return INTERRUPTED ? fn(value[0], value[1], stop) : fn(value[0], value[1]);
|
||||
} return INTERRUPTED ? fn(value, stop) : fn(value);
|
||||
};
|
||||
|
||||
if (IS_RECORD) {
|
||||
iterator = iterable.iterator;
|
||||
} else if (IS_ITERATOR) {
|
||||
iterator = iterable;
|
||||
} else {
|
||||
iterFn = getIteratorMethod(iterable);
|
||||
if (!iterFn) throw new $TypeError(tryToString(iterable) + ' is not iterable');
|
||||
// optimisation for array iterators
|
||||
if (isArrayIteratorMethod(iterFn)) {
|
||||
for (index = 0, length = lengthOfArrayLike(iterable); length > index; index++) {
|
||||
result = callFn(iterable[index]);
|
||||
if (result && isPrototypeOf(ResultPrototype, result)) return result;
|
||||
} return new Result(false);
|
||||
}
|
||||
iterator = getIterator(iterable, iterFn);
|
||||
}
|
||||
|
||||
next = IS_RECORD ? iterable.next : iterator.next;
|
||||
while (!(step = call(next, iterator)).done) {
|
||||
try {
|
||||
result = callFn(step.value);
|
||||
} catch (error) {
|
||||
iteratorClose(iterator, 'throw', error);
|
||||
}
|
||||
if (typeof result == 'object' && result && isPrototypeOf(ResultPrototype, result)) return result;
|
||||
} return new Result(false);
|
||||
};
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user