X-Git-Url: https://git.ladys.computer/Pisces/blobdiff_plain/00a99e780024dae2f15b5def2064f9d29d738e9f..beab7268e7673b036222e64aac924f850e2b976e:/collection.js?ds=sidebyside diff --git a/collection.js b/collection.js index 4545321..d340709 100644 --- a/collection.js +++ b/collection.js @@ -8,18 +8,8 @@ // file, You can obtain one at . import { call, createCallableFunction } from "./function.js"; -import { - isIntegralNumber, - MAXIMUM_SAFE_INTEGRAL_NUMBER, -} from "./numeric.js"; -import { - canonicalNumericIndexString, - lengthOfArraylike, - sameValue, - toIndex, - toLength, - type, -} from "./value.js"; +import { isConcatSpreadableObject } from "./object.js"; +import { toIndex, type } from "./value.js"; const { prototype: arrayPrototype } = Array; @@ -204,33 +194,6 @@ export const indices = createCallableFunction( "indices", ); -/** Returns whether the provided value is an array index string. */ -export const isArrayIndexString = ($) => { - const value = canonicalNumericIndexString($); - if (value !== undefined) { - // The provided value is a canonical numeric index string. - return sameValue(value, 0) || value > 0 && value < -1 >>> 0 && - value === toLength(value); - } else { - // The provided value is not a canonical numeric index string. - return false; - } -}; - -/** Returns whether the provided value is arraylike. */ -export const isArraylikeObject = ($) => { - if (type($) !== "object") { - return false; - } else { - try { - lengthOfArraylike($); // throws if not arraylike - return true; - } catch { - return false; - } - } -}; - /** * Returns whether the provided object is a collection. * @@ -252,45 +215,13 @@ export const isCollection = ($) => { } else { try { toIndex($.length); // will throw if `length` is not an index - return isConcatSpreadable($); + return isConcatSpreadableObject($); } catch { return false; } } }; -/** - * Returns whether the provided value is spreadable during array - * concatenation. - * - * This is also used to determine which things should be treated as - * collections. - */ -export const isConcatSpreadable = ($) => { - if (type($) !== "object") { - // The provided value is not an object. - return false; - } else { - // The provided value is an object. - const spreadable = $[Symbol.isConcatSpreadable]; - return spreadable !== undefined ? !!spreadable : isArray($); - } -}; - -/** Returns whether the provided value is an integer index string. */ -export const isIntegerIndexString = ($) => { - const value = canonicalNumericIndexString($); - if (value !== undefined && isIntegralNumber(value)) { - // The provided value is a canonical numeric index string. - return sameValue(value, 0) || - value > 0 && value <= MAXIMUM_SAFE_INTEGRAL_NUMBER && - value === toLength(value); - } else { - // The provided value is not a canonical numeric index string. - return false; - } -}; - /** * Returns an iterator over the items in the provided value according * to the algorithm of `Array::values`.