X-Git-Url: https://git.ladys.computer/Pisces/blobdiff_plain/f1283dfa8f4f1482dac6325fbcb66f8778af1002..6e6d4e3261c1c943fe44fa9e381bcf8bf1441fd6:/collection.js?ds=inline diff --git a/collection.js b/collection.js index 20b6fef..7319b73 100644 --- a/collection.js +++ b/collection.js @@ -35,7 +35,7 @@ export const { * numeric index string; otherwise, returns undefined. * * There is no clamping of the numeric index, but note that numbers - * above 2^53 − 1 are not safe nor valid integer indices. + * above 2^53 − 1 are not safe nor valid integer indices. */ export const canonicalNumericIndexString = ($) => { if (typeof $ !== "string") { @@ -188,12 +188,26 @@ export const isArrayIndexString = ($) => { } }; +/** 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. * * The definition of “collection” used by Piscēs is similar to * Ecmascript’s definition of an arraylike object, but it differs in - * a few ways :— + * a few ways :— * * - It requires the provided value to be a proper object. * @@ -262,7 +276,7 @@ export const items = makeCallable(Array.prototype.values); * This can produce larger lengths than can actually be stored in * arrays, because no such restrictions exist on arraylike methods. */ -export const lengthOfArrayLike = ({ length }) => toLength(length); +export const lengthOfArraylike = ({ length }) => toLength(length); /** * Returns the result of mapping the provided value with the provided