es-toolkit 1.29.0-dev.930 → 1.29.0-dev.931

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,14 @@
1
+ /**
2
+ * Gets the element at index `n` of `array`. If `n` is negative, the nth element from the end is returned.
3
+ *
4
+ * @param {ArrayLike<T> | null | undefined} array - The array to query.
5
+ * @param {number} [n=0] - The index of the element to return.
6
+ * @return {T | undefined} Returns the nth element of `array`.
7
+ *
8
+ * @example
9
+ * nth([1, 2, 3], 1); // => 2
10
+ * nth([1, 2, 3], -1); // => 3
11
+ */
12
+ declare function nth<T>(array: ArrayLike<T> | null | undefined, n?: number): T | undefined;
13
+
14
+ export { nth };
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Gets the element at index `n` of `array`. If `n` is negative, the nth element from the end is returned.
3
+ *
4
+ * @param {ArrayLike<T> | null | undefined} array - The array to query.
5
+ * @param {number} [n=0] - The index of the element to return.
6
+ * @return {T | undefined} Returns the nth element of `array`.
7
+ *
8
+ * @example
9
+ * nth([1, 2, 3], 1); // => 2
10
+ * nth([1, 2, 3], -1); // => 3
11
+ */
12
+ declare function nth<T>(array: ArrayLike<T> | null | undefined, n?: number): T | undefined;
13
+
14
+ export { nth };
@@ -0,0 +1,15 @@
1
+ import { isArrayLikeObject } from '../predicate/isArrayLikeObject.mjs';
2
+ import { toInteger } from '../util/toInteger.mjs';
3
+
4
+ function nth(array, n = 0) {
5
+ if (!isArrayLikeObject(array) || array.length === 0) {
6
+ return undefined;
7
+ }
8
+ n = toInteger(n);
9
+ if (n < 0) {
10
+ n += array.length;
11
+ }
12
+ return array[n];
13
+ }
14
+
15
+ export { nth };
@@ -104,6 +104,7 @@ export { intersectionBy } from './array/intersectionBy.mjs';
104
104
  export { join } from './array/join.mjs';
105
105
  export { last } from './array/last.mjs';
106
106
  export { lastIndexOf } from './array/lastIndexOf.mjs';
107
+ export { nth } from './array/nth.mjs';
107
108
  export { orderBy } from './array/orderBy.mjs';
108
109
  export { pull } from './array/pull.mjs';
109
110
  export { sample } from './array/sample.mjs';
@@ -104,6 +104,7 @@ export { intersectionBy } from './array/intersectionBy.js';
104
104
  export { join } from './array/join.js';
105
105
  export { last } from './array/last.js';
106
106
  export { lastIndexOf } from './array/lastIndexOf.js';
107
+ export { nth } from './array/nth.js';
107
108
  export { orderBy } from './array/orderBy.js';
108
109
  export { pull } from './array/pull.js';
109
110
  export { sample } from './array/sample.js';
@@ -1008,6 +1008,17 @@ function lastIndexOf(array, searchElement, fromIndex) {
1008
1008
  return Array.from(array).lastIndexOf(searchElement, index);
1009
1009
  }
1010
1010
 
1011
+ function nth(array, n = 0) {
1012
+ if (!isArrayLikeObject(array) || array.length === 0) {
1013
+ return undefined;
1014
+ }
1015
+ n = toInteger(n);
1016
+ if (n < 0) {
1017
+ n += array.length;
1018
+ }
1019
+ return array[n];
1020
+ }
1021
+
1011
1022
  function getPriority(a) {
1012
1023
  if (typeof a === 'symbol') {
1013
1024
  return 1;
@@ -2968,6 +2979,7 @@ exports.merge = merge;
2968
2979
  exports.mergeWith = mergeWith;
2969
2980
  exports.min = min;
2970
2981
  exports.now = now;
2982
+ exports.nth = nth;
2971
2983
  exports.omit = omit;
2972
2984
  exports.orderBy = orderBy;
2973
2985
  exports.pad = pad;
@@ -105,6 +105,7 @@ export { intersectionBy } from './array/intersectionBy.mjs';
105
105
  export { join } from './array/join.mjs';
106
106
  export { last } from './array/last.mjs';
107
107
  export { lastIndexOf } from './array/lastIndexOf.mjs';
108
+ export { nth } from './array/nth.mjs';
108
109
  export { orderBy } from './array/orderBy.mjs';
109
110
  export { pull } from './array/pull.mjs';
110
111
  export { sample } from './array/sample.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.29.0-dev.930+c93ff843",
4
+ "version": "1.29.0-dev.931+f7abb57d",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {