// file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
import { call, createCallableFunction } from "./function.js";
-import {
- isIntegralNumber,
- MAXIMUM_SAFE_INTEGRAL_NUMBER,
-} from "./numeric.js";
import {
canonicalNumericIndexString,
lengthOfArraylike,
}
};
-/** 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`.
isArraylikeObject,
isCollection,
isConcatSpreadable,
- isIntegerIndexString,
} from "./collection.js";
describe("findIndexedEntry", () => {
);
});
});
-
-describe("isIntegerIndexString", () => {
- it("[[Call]] returns false for nonstrings", () => {
- assertStrictEquals(isIntegerIndexString(1), false);
- });
-
- it("[[Call]] returns false for noncanonical strings", () => {
- assertStrictEquals(isIntegerIndexString(""), false);
- assertStrictEquals(isIntegerIndexString("01"), false);
- assertStrictEquals(
- isIntegerIndexString("9007199254740993"),
- false,
- );
- });
-
- it("[[Call]] returns false for nonfinite numbers", () => {
- assertStrictEquals(isIntegerIndexString("NaN"), false);
- assertStrictEquals(isIntegerIndexString("Infinity"), false);
- assertStrictEquals(isIntegerIndexString("-Infinity"), false);
- });
-
- it("[[Call]] returns false for negative numbers", () => {
- assertStrictEquals(isIntegerIndexString("-0"), false);
- assertStrictEquals(isIntegerIndexString("-1"), false);
- });
-
- it("[[Call]] returns false for nonintegers", () => {
- assertStrictEquals(isIntegerIndexString("0.25"), false);
- assertStrictEquals(isIntegerIndexString("1.1"), false);
- });
-
- it("[[Call]] returns false for numbers greater than or equal to 2 ** 53", () => {
- assertStrictEquals(
- isIntegerIndexString("9007199254740992"),
- false,
- );
- });
-
- it("[[Call]] returns true for safe canonical integer strings", () => {
- assertStrictEquals(isIntegerIndexString("0"), true);
- assertStrictEquals(isIntegerIndexString("9007199254740991"), true);
- });
-});
})();
export const {
+ /** Returns whether the provided value is an integer index string. */
+ isIntegerIndexString,
+
/**
* Returns whether the provided values are the same value.
*
const { floor, max, min } = Math;
const {
MAX_SAFE_INTEGER: MAXIMUM_SAFE_INTEGRAL_NUMBER,
+ isInteger: isIntegralNumber,
isNaN: isNan,
} = Number;
const { is } = Object;
return {
+ isIntegerIndexString: ($) => {
+ const value = canonicalNumericIndexString($);
+ if (value !== undefined && isIntegralNumber(value)) {
+ // The provided value is an integral canonical numeric index
+ // string.
+ return sameValue(value, 0) ||
+ value > 0 && value <= MAXIMUM_SAFE_INTEGRAL_NUMBER &&
+ value === toLength(value);
+ } else {
+ // The provided value is not an integral canonical numeric
+ // index string.
+ return false;
+ }
+ },
sameValue: (a, b) => is(a, b),
sameValueZero: ($1, $2) => {
const type1 = type($1);
canonicalNumericIndexString,
HAS_INSTANCE,
IS_CONCAT_SPREADABLE,
+ isIntegerIndexString,
ITERATOR,
lengthOfArraylike,
MATCH,
});
});
+describe("isIntegerIndexString", () => {
+ it("[[Call]] returns false for nonstrings", () => {
+ assertStrictEquals(isIntegerIndexString(1), false);
+ });
+
+ it("[[Call]] returns false for noncanonical strings", () => {
+ assertStrictEquals(isIntegerIndexString(""), false);
+ assertStrictEquals(isIntegerIndexString("01"), false);
+ assertStrictEquals(
+ isIntegerIndexString("9007199254740993"),
+ false,
+ );
+ });
+
+ it("[[Call]] returns false for nonfinite numbers", () => {
+ assertStrictEquals(isIntegerIndexString("NaN"), false);
+ assertStrictEquals(isIntegerIndexString("Infinity"), false);
+ assertStrictEquals(isIntegerIndexString("-Infinity"), false);
+ });
+
+ it("[[Call]] returns false for negative numbers", () => {
+ assertStrictEquals(isIntegerIndexString("-0"), false);
+ assertStrictEquals(isIntegerIndexString("-1"), false);
+ });
+
+ it("[[Call]] returns false for nonintegers", () => {
+ assertStrictEquals(isIntegerIndexString("0.25"), false);
+ assertStrictEquals(isIntegerIndexString("1.1"), false);
+ });
+
+ it("[[Call]] returns false for numbers greater than or equal to 2 ** 53", () => {
+ assertStrictEquals(
+ isIntegerIndexString("9007199254740992"),
+ false,
+ );
+ });
+
+ it("[[Call]] returns true for safe canonical integer strings", () => {
+ assertStrictEquals(isIntegerIndexString("0"), true);
+ assertStrictEquals(isIntegerIndexString("9007199254740991"), true);
+ });
+});
+
describe("lengthOfArraylike", () => {
it("[[Call]] returns the length", () => {
assertStrictEquals(