es-toolkit 1.28.0-dev.913 → 1.28.0-dev.915

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,20 @@
1
+ /**
2
+ * Finds the index of the last occurrence of a value in an array.
3
+ *
4
+ * This method is similar to `Array.prototype.lastIndexOf`, but it also finds `NaN` values.
5
+ * It uses strict equality (`===`) to compare elements.
6
+ *
7
+ * @template T - The type of elements in the array.
8
+ * @param {ArrayLike<T> | null | undefined} array - The array to search.
9
+ * @param {T} searchElement - The value to search for.
10
+ * @param {number} [fromIndex] - The index to start the search at.
11
+ * @returns {number} The index (zero-based) of the last occurrence of the value in the array, or `-1` if the value is not found.
12
+ *
13
+ * @example
14
+ * const array = [1, 2, 3, NaN, 1];
15
+ * lastIndexOf(array, 3); // => 4
16
+ * lastIndexOf(array, NaN); // => 3
17
+ */
18
+ declare function lastIndexOf<T>(array: ArrayLike<T> | null | undefined, searchElement: T, fromIndex?: number): number;
19
+
20
+ export { lastIndexOf };
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Finds the index of the last occurrence of a value in an array.
3
+ *
4
+ * This method is similar to `Array.prototype.lastIndexOf`, but it also finds `NaN` values.
5
+ * It uses strict equality (`===`) to compare elements.
6
+ *
7
+ * @template T - The type of elements in the array.
8
+ * @param {ArrayLike<T> | null | undefined} array - The array to search.
9
+ * @param {T} searchElement - The value to search for.
10
+ * @param {number} [fromIndex] - The index to start the search at.
11
+ * @returns {number} The index (zero-based) of the last occurrence of the value in the array, or `-1` if the value is not found.
12
+ *
13
+ * @example
14
+ * const array = [1, 2, 3, NaN, 1];
15
+ * lastIndexOf(array, 3); // => 4
16
+ * lastIndexOf(array, NaN); // => 3
17
+ */
18
+ declare function lastIndexOf<T>(array: ArrayLike<T> | null | undefined, searchElement: T, fromIndex?: number): number;
19
+
20
+ export { lastIndexOf };
@@ -0,0 +1,22 @@
1
+ import { isArrayLike } from '../predicate/isArrayLike.mjs';
2
+
3
+ function lastIndexOf(array, searchElement, fromIndex) {
4
+ if (!isArrayLike(array) || array.length === 0) {
5
+ return -1;
6
+ }
7
+ const length = array.length;
8
+ let index = fromIndex ?? length - 1;
9
+ if (fromIndex != null) {
10
+ index = index < 0 ? Math.max(length + index, 0) : Math.min(index, length - 1);
11
+ }
12
+ if (Number.isNaN(searchElement)) {
13
+ for (let i = index; i >= 0; i--) {
14
+ if (Number.isNaN(array[i])) {
15
+ return i;
16
+ }
17
+ }
18
+ }
19
+ return Array.from(array).lastIndexOf(searchElement, index);
20
+ }
21
+
22
+ export { lastIndexOf };
@@ -104,6 +104,7 @@ export { intersection } from './array/intersection.mjs';
104
104
  export { intersectionBy } from './array/intersectionBy.mjs';
105
105
  export { join } from './array/join.mjs';
106
106
  export { last } from './array/last.mjs';
107
+ export { lastIndexOf } from './array/lastIndexOf.mjs';
107
108
  export { orderBy } from './array/orderBy.mjs';
108
109
  export { sample } from './array/sample.mjs';
109
110
  export { size } from './array/size.mjs';
@@ -104,6 +104,7 @@ export { intersection } from './array/intersection.js';
104
104
  export { intersectionBy } from './array/intersectionBy.js';
105
105
  export { join } from './array/join.js';
106
106
  export { last } from './array/last.js';
107
+ export { lastIndexOf } from './array/lastIndexOf.js';
107
108
  export { orderBy } from './array/orderBy.js';
108
109
  export { sample } from './array/sample.js';
109
110
  export { size } from './array/size.js';
@@ -8,7 +8,7 @@ const unary = require('../_chunk/unary-CcTNuC.js');
8
8
  const noop = require('../_chunk/noop-2IwLUk.js');
9
9
  const rangeRight = require('../_chunk/rangeRight-w3WrXN.js');
10
10
  const randomInt = require('../_chunk/randomInt-CF7bZK.js');
11
- const toMerged = require('../_chunk/toMerged-AV73JV.js');
11
+ const toMerged = require('../_chunk/toMerged-DGFrN7.js');
12
12
  const isPlainObject$1 = require('../_chunk/isPlainObject-octpoD.js');
13
13
  const isWeakSet$1 = require('../_chunk/isWeakSet-CvIdTA.js');
14
14
  const upperFirst = require('../_chunk/upperFirst-CorAVn.js');
@@ -989,6 +989,25 @@ function join(array, separator = ',') {
989
989
  return Array.from(array).join(separator);
990
990
  }
991
991
 
992
+ function lastIndexOf(array, searchElement, fromIndex) {
993
+ if (!isArrayLike(array) || array.length === 0) {
994
+ return -1;
995
+ }
996
+ const length = array.length;
997
+ let index = fromIndex ?? length - 1;
998
+ if (fromIndex != null) {
999
+ index = index < 0 ? Math.max(length + index, 0) : Math.min(index, length - 1);
1000
+ }
1001
+ if (Number.isNaN(searchElement)) {
1002
+ for (let i = index; i >= 0; i--) {
1003
+ if (Number.isNaN(array[i])) {
1004
+ return i;
1005
+ }
1006
+ }
1007
+ }
1008
+ return Array.from(array).lastIndexOf(searchElement, index);
1009
+ }
1010
+
992
1011
  function getPriority(a) {
993
1012
  if (typeof a === 'symbol') {
994
1013
  return 1;
@@ -2870,6 +2889,7 @@ exports.join = join;
2870
2889
  exports.kebabCase = kebabCase;
2871
2890
  exports.keysIn = keysIn;
2872
2891
  exports.last = last;
2892
+ exports.lastIndexOf = lastIndexOf;
2873
2893
  exports.lowerCase = lowerCase;
2874
2894
  exports.mapKeys = mapKeys;
2875
2895
  exports.mapValues = mapValues;
@@ -105,6 +105,7 @@ export { intersection } from './array/intersection.mjs';
105
105
  export { intersectionBy } from './array/intersectionBy.mjs';
106
106
  export { join } from './array/join.mjs';
107
107
  export { last } from './array/last.mjs';
108
+ export { lastIndexOf } from './array/lastIndexOf.mjs';
108
109
  export { orderBy } from './array/orderBy.mjs';
109
110
  export { sample } from './array/sample.mjs';
110
111
  export { size } from './array/size.mjs';
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ const noop = require('./_chunk/noop-2IwLUk.js');
11
11
  const rangeRight = require('./_chunk/rangeRight-w3WrXN.js');
12
12
  const randomInt = require('./_chunk/randomInt-CF7bZK.js');
13
13
  const math_index = require('./math/index.js');
14
- const toMerged = require('./_chunk/toMerged-AV73JV.js');
14
+ const toMerged = require('./_chunk/toMerged-DGFrN7.js');
15
15
  const object_index = require('./object/index.js');
16
16
  const isWeakSet = require('./_chunk/isWeakSet-CvIdTA.js');
17
17
  const predicate_index = require('./predicate/index.js');
@@ -15,9 +15,7 @@ function flattenObjectImpl(object, prefix = '') {
15
15
  continue;
16
16
  }
17
17
  if (Array.isArray(value)) {
18
- for (let index = 0; index < value.length; index++) {
19
- result[`${prefixedKey}.${index}`] = value[index];
20
- }
18
+ Object.assign(result, flattenObjectImpl(value, prefixedKey));
21
19
  continue;
22
20
  }
23
21
  result[prefixedKey] = value;
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const toMerged = require('../_chunk/toMerged-AV73JV.js');
5
+ const toMerged = require('../_chunk/toMerged-DGFrN7.js');
6
6
 
7
7
  function mergeWith(target, source, merge) {
8
8
  const sourceKeys = Object.keys(source);
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.28.0-dev.913+3393707a",
4
+ "version": "1.28.0-dev.915+7d9b11d9",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {