es-toolkit 1.37.2-dev.1258 → 1.37.2-dev.1259

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Finds the index of the last occurrence of a value in a sorted array.
3
+ * This function is similar to `Array#lastIndexOf` but is specifically designed for sorted arrays.
4
+ *
5
+ * Make sure to provide a sorted array to this function, as it uses a binary search to quickly find the index.
6
+ *
7
+ * @param {ArrayLike<T> | null | undefined} array The sorted array to inspect.
8
+ * @param {T} value The value to search for.
9
+ * @returns {number} Returns the index of the last matched value, else -1.
10
+ *
11
+ * @example
12
+ * const numbers = [1, 2, 3, 4, 5];
13
+ * sortedLastIndexOf(numbers, 3); // Return value: 2
14
+ * sortedLastIndexOf(numbers, 6); // Return value: -1
15
+ *
16
+ * // If the value is duplicated, it returns the last index of the value.
17
+ * const duplicateNumbers = [1, 2, 2, 3, 3, 3, 4];
18
+ * sortedLastIndexOf(duplicateNumbers, 3); // Return value: 5
19
+ *
20
+ * // If the array is unsorted, it can return the wrong index.
21
+ * const unSortedArray = [55, 33, 22, 11, 44];
22
+ * sortedLastIndexOf(unSortedArray, 11); // Return value: -1
23
+ *
24
+ * // -0 and 0 are treated the same
25
+ * const mixedZeroArray = [-0, 0];
26
+ * sortedLastIndexOf(mixedZeroArray, 0); // Return value: 1
27
+ * sortedLastIndexOf(mixedZeroArray, -0); // Return value: 1
28
+ *
29
+ * // It works with array-like objects
30
+ * const arrayLike = { length: 3, 0: 10, 1: 20, 2: 20 };
31
+ * sortedLastIndexOf(arrayLike, 20); // Return value: 2
32
+ */
33
+ declare function sortedLastIndexOf<T>(array: ArrayLike<T> | null | undefined, value: T): number;
34
+
35
+ export { sortedLastIndexOf };
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Finds the index of the last occurrence of a value in a sorted array.
3
+ * This function is similar to `Array#lastIndexOf` but is specifically designed for sorted arrays.
4
+ *
5
+ * Make sure to provide a sorted array to this function, as it uses a binary search to quickly find the index.
6
+ *
7
+ * @param {ArrayLike<T> | null | undefined} array The sorted array to inspect.
8
+ * @param {T} value The value to search for.
9
+ * @returns {number} Returns the index of the last matched value, else -1.
10
+ *
11
+ * @example
12
+ * const numbers = [1, 2, 3, 4, 5];
13
+ * sortedLastIndexOf(numbers, 3); // Return value: 2
14
+ * sortedLastIndexOf(numbers, 6); // Return value: -1
15
+ *
16
+ * // If the value is duplicated, it returns the last index of the value.
17
+ * const duplicateNumbers = [1, 2, 2, 3, 3, 3, 4];
18
+ * sortedLastIndexOf(duplicateNumbers, 3); // Return value: 5
19
+ *
20
+ * // If the array is unsorted, it can return the wrong index.
21
+ * const unSortedArray = [55, 33, 22, 11, 44];
22
+ * sortedLastIndexOf(unSortedArray, 11); // Return value: -1
23
+ *
24
+ * // -0 and 0 are treated the same
25
+ * const mixedZeroArray = [-0, 0];
26
+ * sortedLastIndexOf(mixedZeroArray, 0); // Return value: 1
27
+ * sortedLastIndexOf(mixedZeroArray, -0); // Return value: 1
28
+ *
29
+ * // It works with array-like objects
30
+ * const arrayLike = { length: 3, 0: 10, 1: 20, 2: 20 };
31
+ * sortedLastIndexOf(arrayLike, 20); // Return value: 2
32
+ */
33
+ declare function sortedLastIndexOf<T>(array: ArrayLike<T> | null | undefined, value: T): number;
34
+
35
+ export { sortedLastIndexOf };
@@ -0,0 +1,15 @@
1
+ import { sortedLastIndex } from './sortedLastIndex.mjs';
2
+ import { eq } from '../util/eq.mjs';
3
+
4
+ function sortedLastIndexOf(array, value) {
5
+ if (!array?.length) {
6
+ return -1;
7
+ }
8
+ const index = sortedLastIndex(array, value) - 1;
9
+ if (index >= 0 && eq(array[index], value)) {
10
+ return index;
11
+ }
12
+ return -1;
13
+ }
14
+
15
+ export { sortedLastIndexOf };
@@ -61,6 +61,7 @@ export { sortedIndexBy } from './array/sortedIndexBy.mjs';
61
61
  export { sortedIndexOf } from './array/sortedIndexOf.mjs';
62
62
  export { sortedLastIndex } from './array/sortedLastIndex.mjs';
63
63
  export { sortedLastIndexBy } from './array/sortedLastIndexBy.mjs';
64
+ export { sortedLastIndexOf } from './array/sortedLastIndexOf.mjs';
64
65
  export { tail } from './array/tail.mjs';
65
66
  export { take } from './array/take.mjs';
66
67
  export { takeRight } from './array/takeRight.mjs';
@@ -61,6 +61,7 @@ export { sortedIndexBy } from './array/sortedIndexBy.js';
61
61
  export { sortedIndexOf } from './array/sortedIndexOf.js';
62
62
  export { sortedLastIndex } from './array/sortedLastIndex.js';
63
63
  export { sortedLastIndexBy } from './array/sortedLastIndexBy.js';
64
+ export { sortedLastIndexOf } from './array/sortedLastIndexOf.js';
64
65
  export { tail } from './array/tail.js';
65
66
  export { take } from './array/take.js';
66
67
  export { takeRight } from './array/takeRight.js';
@@ -61,6 +61,7 @@ export { sortedIndexBy } from './array/sortedIndexBy.mjs';
61
61
  export { sortedIndexOf } from './array/sortedIndexOf.mjs';
62
62
  export { sortedLastIndex } from './array/sortedLastIndex.mjs';
63
63
  export { sortedLastIndexBy } from './array/sortedLastIndexBy.mjs';
64
+ export { sortedLastIndexOf } from './array/sortedLastIndexOf.mjs';
64
65
  export { tail } from './array/tail.mjs';
65
66
  export { take } from './array/take.mjs';
66
67
  export { takeRight } from './array/takeRight.mjs';
@@ -61,6 +61,7 @@ export { sortedIndexBy } from './array/sortedIndexBy.mjs';
61
61
  export { sortedIndexOf } from './array/sortedIndexOf.mjs';
62
62
  export { sortedLastIndex } from './array/sortedLastIndex.mjs';
63
63
  export { sortedLastIndexBy } from './array/sortedLastIndexBy.mjs';
64
+ export { sortedLastIndexOf } from './array/sortedLastIndexOf.mjs';
64
65
  export { tail } from './array/tail.mjs';
65
66
  export { take } from './array/take.mjs';
66
67
  export { takeRight } from './array/takeRight.mjs';
@@ -61,6 +61,7 @@ export { sortedIndexBy } from './array/sortedIndexBy.js';
61
61
  export { sortedIndexOf } from './array/sortedIndexOf.js';
62
62
  export { sortedLastIndex } from './array/sortedLastIndex.js';
63
63
  export { sortedLastIndexBy } from './array/sortedLastIndexBy.js';
64
+ export { sortedLastIndexOf } from './array/sortedLastIndexOf.js';
64
65
  export { tail } from './array/tail.js';
65
66
  export { take } from './array/take.js';
66
67
  export { takeRight } from './array/takeRight.js';
@@ -1825,6 +1825,17 @@ function sortedLastIndex(array, value) {
1825
1825
  return high;
1826
1826
  }
1827
1827
 
1828
+ function sortedLastIndexOf(array, value) {
1829
+ if (!array?.length) {
1830
+ return -1;
1831
+ }
1832
+ const index = sortedLastIndex(array, value) - 1;
1833
+ if (index >= 0 && isWeakSet$1.eq(array[index], value)) {
1834
+ return index;
1835
+ }
1836
+ return -1;
1837
+ }
1838
+
1828
1839
  function tail(arr) {
1829
1840
  if (!isArrayLike(arr)) {
1830
1841
  return [];
@@ -4403,6 +4414,7 @@ const compat = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
4403
4414
  sortedIndexOf,
4404
4415
  sortedLastIndex,
4405
4416
  sortedLastIndexBy,
4417
+ sortedLastIndexOf,
4406
4418
  split,
4407
4419
  spread,
4408
4420
  startCase,
@@ -4702,6 +4714,7 @@ exports.sortedIndexBy = sortedIndexBy;
4702
4714
  exports.sortedIndexOf = sortedIndexOf;
4703
4715
  exports.sortedLastIndex = sortedLastIndex;
4704
4716
  exports.sortedLastIndexBy = sortedLastIndexBy;
4717
+ exports.sortedLastIndexOf = sortedLastIndexOf;
4705
4718
  exports.split = split;
4706
4719
  exports.spread = spread;
4707
4720
  exports.startCase = startCase;
@@ -61,6 +61,7 @@ export { sortedIndexBy } from './array/sortedIndexBy.mjs';
61
61
  export { sortedIndexOf } from './array/sortedIndexOf.mjs';
62
62
  export { sortedLastIndex } from './array/sortedLastIndex.mjs';
63
63
  export { sortedLastIndexBy } from './array/sortedLastIndexBy.mjs';
64
+ export { sortedLastIndexOf } from './array/sortedLastIndexOf.mjs';
64
65
  export { tail } from './array/tail.mjs';
65
66
  export { take } from './array/take.mjs';
66
67
  export { takeRight } from './array/takeRight.mjs';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "es-toolkit",
3
3
  "description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.",
4
- "version": "1.37.2-dev.1258+28a1f69a",
4
+ "version": "1.37.2-dev.1259+81f34d80",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {