]> Lady’s Gitweb - Pisces/commitdiff
Move isIntegerIndexString into value.js
authorLady <redacted>
Fri, 17 Nov 2023 02:09:38 +0000 (21:09 -0500)
committerLady <redacted>
Fri, 17 Nov 2023 02:24:03 +0000 (21:24 -0500)
While potentially relevant to collections, this function is actually
about classifying types of value.

collection.js
collection.test.js
value.js
value.test.js

index 4545321af94621bf4e7c35afde39f64b303c175a..d106ba436a839acc1673f226a2d56076ff311ea3 100644 (file)
@@ -8,10 +8,6 @@
 // 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,
@@ -277,20 +273,6 @@ export const isConcatSpreadable = ($) => {
   }
 };
 
-/** 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`.
index 544f454849a8dd4507eaa770ad1960db5798ac96..7c242cc987023ab23d35f01dbbf7c9809a6336b7 100644 (file)
@@ -22,7 +22,6 @@ import {
   isArraylikeObject,
   isCollection,
   isConcatSpreadable,
-  isIntegerIndexString,
 } from "./collection.js";
 
 describe("findIndexedEntry", () => {
@@ -261,46 +260,3 @@ describe("isConcatSpreadable", () => {
     );
   });
 });
-
-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);
-  });
-});
index dca20e83d190a4462fd11f88bd8a5bbe957e5a47..5e9f0524c9419291802716602f1080c518db1ad8 100644 (file)
--- a/value.js
+++ b/value.js
@@ -171,6 +171,9 @@ export const {
 })();
 
 export const {
+  /** Returns whether the provided value is an integer index string. */
+  isIntegerIndexString,
+
   /**
    * Returns whether the provided values are the same value.
    *
@@ -200,10 +203,25 @@ export const {
   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);
index cecafbbe88c5a5d8fd15bbb32a733011fac86f40..babd59d9a449972170a6d3d6b673f557826d72d0 100644 (file)
@@ -18,6 +18,7 @@ import {
   canonicalNumericIndexString,
   HAS_INSTANCE,
   IS_CONCAT_SPREADABLE,
+  isIntegerIndexString,
   ITERATOR,
   lengthOfArraylike,
   MATCH,
@@ -179,6 +180,49 @@ describe("canonicalNumericIndexString", () => {
   });
 });
 
+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(
This page took 0.030607 seconds and 4 git commands to generate.