es-toolkit 1.23.0-dev.718 → 1.23.0-dev.719

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,25 @@
1
+ /**
2
+ * Returns a new array containing the first `count` elements from the input array `arr`.
3
+ * If `count` is greater than the length of `arr`, the entire array is returned.
4
+ *
5
+ * @template T - Type of elements in the input array.
6
+ *
7
+ * @param {T[]} arr - The array to take elements from.
8
+ * @param {number} count - The number of elements to take.
9
+ * @returns {T[]} A new array containing the first `count` elements from `arr`.
10
+ *
11
+ * @example
12
+ * // Returns [1, 2, 3]
13
+ * take([1, 2, 3, 4, 5], 3);
14
+ *
15
+ * @example
16
+ * // Returns ['a', 'b']
17
+ * take(['a', 'b', 'c'], 2);
18
+ *
19
+ * @example
20
+ * // Returns [1, 2, 3]
21
+ * take([1, 2, 3], 5);
22
+ */
23
+ declare function take<T>(arr: readonly T[], count: number): T[];
24
+
25
+ export { take };
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Returns a new array containing the first `count` elements from the input array `arr`.
3
+ * If `count` is greater than the length of `arr`, the entire array is returned.
4
+ *
5
+ * @template T - Type of elements in the input array.
6
+ *
7
+ * @param {T[]} arr - The array to take elements from.
8
+ * @param {number} count - The number of elements to take.
9
+ * @returns {T[]} A new array containing the first `count` elements from `arr`.
10
+ *
11
+ * @example
12
+ * // Returns [1, 2, 3]
13
+ * take([1, 2, 3, 4, 5], 3);
14
+ *
15
+ * @example
16
+ * // Returns ['a', 'b']
17
+ * take(['a', 'b', 'c'], 2);
18
+ *
19
+ * @example
20
+ * // Returns [1, 2, 3]
21
+ * take([1, 2, 3], 5);
22
+ */
23
+ declare function take<T>(arr: readonly T[], count: number): T[];
24
+
25
+ export { take };
@@ -0,0 +1,10 @@
1
+ import { take as take$1 } from '../../array/take.mjs';
2
+
3
+ function take(arr, count) {
4
+ if (count < 1) {
5
+ return [];
6
+ }
7
+ return take$1(arr, count);
8
+ }
9
+
10
+ export { take };
@@ -25,7 +25,6 @@ export { sample } from '../array/sample.mjs';
25
25
  export { sampleSize } from '../array/sampleSize.mjs';
26
26
  export { shuffle } from '../array/shuffle.mjs';
27
27
  export { tail } from '../array/tail.mjs';
28
- export { take } from '../array/take.mjs';
29
28
  export { takeRight } from '../array/takeRight.mjs';
30
29
  export { takeRightWhile } from '../array/takeRightWhile.mjs';
31
30
  export { takeWhile } from '../array/takeWhile.mjs';
@@ -72,7 +71,6 @@ export { toMerged } from '../object/toMerged.mjs';
72
71
  export { isArrayBuffer } from '../predicate/isArrayBuffer.mjs';
73
72
  export { isDate } from '../predicate/isDate.mjs';
74
73
  export { isEqual } from '../predicate/isEqual.mjs';
75
- export { isEqualWith } from '../predicate/isEqualWith.mjs';
76
74
  export { isMap } from '../predicate/isMap.mjs';
77
75
  export { isNotNil } from '../predicate/isNotNil.mjs';
78
76
  export { isNull } from '../predicate/isNull.mjs';
@@ -117,6 +115,7 @@ export { orderBy } from './array/orderBy.mjs';
117
115
  export { sortBy } from './array/sortBy.mjs';
118
116
  export { size } from './array/size.mjs';
119
117
  export { some } from './array/some.mjs';
118
+ export { take } from './array/take.mjs';
120
119
  export { zipObjectDeep } from './array/zipObjectDeep.mjs';
121
120
  export { filter } from './array/filter.mjs';
122
121
  export { ary } from './function/ary.mjs';
@@ -173,6 +172,7 @@ export { isNumber } from './predicate/isNumber.mjs';
173
172
  export { isNaN } from './predicate/isNaN.mjs';
174
173
  export { isArrayLikeObject } from './predicate/isArrayLikeObject.mjs';
175
174
  export { isNil } from './predicate/isNil.mjs';
175
+ export { isEqualWith } from './predicate/isEqualWith.mjs';
176
176
  export { camelCase } from './string/camelCase.mjs';
177
177
  export { kebabCase } from './string/kebabCase.mjs';
178
178
  export { snakeCase } from './string/snakeCase.mjs';
@@ -25,7 +25,6 @@ export { sample } from '../array/sample.js';
25
25
  export { sampleSize } from '../array/sampleSize.js';
26
26
  export { shuffle } from '../array/shuffle.js';
27
27
  export { tail } from '../array/tail.js';
28
- export { take } from '../array/take.js';
29
28
  export { takeRight } from '../array/takeRight.js';
30
29
  export { takeRightWhile } from '../array/takeRightWhile.js';
31
30
  export { takeWhile } from '../array/takeWhile.js';
@@ -72,7 +71,6 @@ export { toMerged } from '../object/toMerged.js';
72
71
  export { isArrayBuffer } from '../predicate/isArrayBuffer.js';
73
72
  export { isDate } from '../predicate/isDate.js';
74
73
  export { isEqual } from '../predicate/isEqual.js';
75
- export { isEqualWith } from '../predicate/isEqualWith.js';
76
74
  export { isMap } from '../predicate/isMap.js';
77
75
  export { isNotNil } from '../predicate/isNotNil.js';
78
76
  export { isNull } from '../predicate/isNull.js';
@@ -117,6 +115,7 @@ export { orderBy } from './array/orderBy.js';
117
115
  export { sortBy } from './array/sortBy.js';
118
116
  export { size } from './array/size.js';
119
117
  export { some } from './array/some.js';
118
+ export { take } from './array/take.js';
120
119
  export { zipObjectDeep } from './array/zipObjectDeep.js';
121
120
  export { filter } from './array/filter.js';
122
121
  export { ary } from './function/ary.js';
@@ -173,6 +172,7 @@ export { isNumber } from './predicate/isNumber.js';
173
172
  export { isNaN } from './predicate/isNaN.js';
174
173
  export { isArrayLikeObject } from './predicate/isArrayLikeObject.js';
175
174
  export { isNil } from './predicate/isNil.js';
175
+ export { isEqualWith } from './predicate/isEqualWith.js';
176
176
  export { camelCase } from './string/camelCase.js';
177
177
  export { kebabCase } from './string/kebabCase.js';
178
178
  export { snakeCase } from './string/snakeCase.js';
@@ -831,6 +831,13 @@ function some(arr, predicate, guard) {
831
831
  }
832
832
  }
833
833
 
834
+ function take(arr, count) {
835
+ if (count < 1) {
836
+ return [];
837
+ }
838
+ return zipWith.take(arr, count);
839
+ }
840
+
834
841
  function set(obj, path, value) {
835
842
  const resolvedPath = Array.isArray(path) ? path : typeof path === 'string' ? toPath(path) : [path];
836
843
  let current = obj;
@@ -1517,6 +1524,24 @@ function isArrayLikeObject(value) {
1517
1524
  return isObjectLike.isObjectLike(value) && isArrayLike(value);
1518
1525
  }
1519
1526
 
1527
+ function isEqualWith(a, b, areValuesEqual = noop.noop) {
1528
+ if (typeof areValuesEqual !== 'function') {
1529
+ areValuesEqual = noop.noop;
1530
+ }
1531
+ return isWeakSet$1.isEqualWith(a, b, (...args) => {
1532
+ const result = areValuesEqual(...args);
1533
+ if (result !== undefined) {
1534
+ return !!result;
1535
+ }
1536
+ if (a instanceof Map && b instanceof Map) {
1537
+ return isEqualWith(Array.from(a), Array.from(b), flowRight$1.after(2, areValuesEqual));
1538
+ }
1539
+ if (a instanceof Set && b instanceof Set) {
1540
+ return isEqualWith(Array.from(a), Array.from(b), flowRight$1.after(2, areValuesEqual));
1541
+ }
1542
+ });
1543
+ }
1544
+
1520
1545
  function toString(value) {
1521
1546
  if (value == null) {
1522
1547
  return '';
@@ -1857,7 +1882,6 @@ exports.sample = zipWith.sample;
1857
1882
  exports.sampleSize = zipWith.sampleSize;
1858
1883
  exports.shuffle = zipWith.shuffle;
1859
1884
  exports.tail = zipWith.tail;
1860
- exports.take = zipWith.take;
1861
1885
  exports.takeRight = zipWith.takeRight;
1862
1886
  exports.takeRightWhile = zipWith.takeRightWhile;
1863
1887
  exports.takeWhile = zipWith.takeWhile;
@@ -1909,7 +1933,6 @@ exports.isPrimitive = isPlainObject$1.isPrimitive;
1909
1933
  exports.isArrayBuffer = isWeakSet$1.isArrayBuffer;
1910
1934
  exports.isDate = isWeakSet$1.isDate;
1911
1935
  exports.isEqual = isWeakSet$1.isEqual;
1912
- exports.isEqualWith = isWeakSet$1.isEqualWith;
1913
1936
  exports.isFunction = isWeakSet$1.isFunction;
1914
1937
  exports.isJSONArray = isWeakSet$1.isJSONArray;
1915
1938
  exports.isJSONObject = isWeakSet$1.isJSONObject;
@@ -1974,6 +1997,7 @@ exports.isArray = isArray;
1974
1997
  exports.isArrayLike = isArrayLike;
1975
1998
  exports.isArrayLikeObject = isArrayLikeObject;
1976
1999
  exports.isBoolean = isBoolean;
2000
+ exports.isEqualWith = isEqualWith;
1977
2001
  exports.isError = isError;
1978
2002
  exports.isFinite = isFinite;
1979
2003
  exports.isInteger = isInteger;
@@ -2022,6 +2046,7 @@ exports.sortBy = sortBy;
2022
2046
  exports.spread = spread;
2023
2047
  exports.startCase = startCase;
2024
2048
  exports.startsWith = startsWith;
2049
+ exports.take = take;
2025
2050
  exports.throttle = throttle;
2026
2051
  exports.toFinite = toFinite;
2027
2052
  exports.toInteger = toInteger;
@@ -25,7 +25,6 @@ export { sample } from '../array/sample.mjs';
25
25
  export { sampleSize } from '../array/sampleSize.mjs';
26
26
  export { shuffle } from '../array/shuffle.mjs';
27
27
  export { tail } from '../array/tail.mjs';
28
- export { take } from '../array/take.mjs';
29
28
  export { takeRight } from '../array/takeRight.mjs';
30
29
  export { takeRightWhile } from '../array/takeRightWhile.mjs';
31
30
  export { takeWhile } from '../array/takeWhile.mjs';
@@ -74,7 +73,6 @@ export { isObjectLike } from './predicate/isObjectLike.mjs';
74
73
  export { isArrayBuffer } from '../predicate/isArrayBuffer.mjs';
75
74
  export { isDate } from '../predicate/isDate.mjs';
76
75
  export { isEqual } from '../predicate/isEqual.mjs';
77
- export { isEqualWith } from '../predicate/isEqualWith.mjs';
78
76
  export { isMap } from '../predicate/isMap.mjs';
79
77
  export { isNotNil } from '../predicate/isNotNil.mjs';
80
78
  export { isNull } from '../predicate/isNull.mjs';
@@ -118,6 +116,7 @@ export { orderBy } from './array/orderBy.mjs';
118
116
  export { sortBy } from './array/sortBy.mjs';
119
117
  export { size } from './array/size.mjs';
120
118
  export { some } from './array/some.mjs';
119
+ export { take } from './array/take.mjs';
121
120
  export { zipObjectDeep } from './array/zipObjectDeep.mjs';
122
121
  export { filter } from './array/filter.mjs';
123
122
  export { ary } from './function/ary.mjs';
@@ -173,6 +172,7 @@ export { isNumber } from './predicate/isNumber.mjs';
173
172
  export { isNaN } from './predicate/isNaN.mjs';
174
173
  export { isArrayLikeObject } from './predicate/isArrayLikeObject.mjs';
175
174
  export { isNil } from './predicate/isNil.mjs';
175
+ export { isEqualWith } from './predicate/isEqualWith.mjs';
176
176
  export { camelCase } from './string/camelCase.mjs';
177
177
  export { kebabCase } from './string/kebabCase.mjs';
178
178
  export { snakeCase } from './string/snakeCase.mjs';
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Compares two values for equality using a custom comparison function.
3
+ *
4
+ * The custom function allows for fine-tuned control over the comparison process. If it returns a boolean, that result determines the equality. If it returns undefined, the function falls back to the default equality comparison.
5
+ *
6
+ * This function also uses the custom equality function to compare values inside objects,
7
+ * arrays, maps, sets, and other complex structures, ensuring a deep comparison.
8
+ *
9
+ * This approach provides flexibility in handling complex comparisons while maintaining efficient default behavior for simpler cases.
10
+ *
11
+ * The custom comparison function can take up to six parameters:
12
+ * - `x`: The value from the first object `a`.
13
+ * - `y`: The value from the second object `b`.
14
+ * - `property`: The property key used to get `x` and `y`.
15
+ * - `xParent`: The parent of the first value `x`.
16
+ * - `yParent`: The parent of the second value `y`.
17
+ * - `stack`: An internal stack (Map) to handle circular references.
18
+ *
19
+ * @param {unknown} a - The first value to compare.
20
+ * @param {unknown} b - The second value to compare.
21
+ * @param {(x: any, y: any, property?: PropertyKey, xParent?: any, yParent?: any, stack?: Map<any, any>) => boolean | void} [areValuesEqual=noop] - A function to customize the comparison.
22
+ * If it returns a boolean, that result will be used. If it returns undefined,
23
+ * the default equality comparison will be used.
24
+ * @returns {boolean} `true` if the values are equal according to the customizer, otherwise `false`.
25
+ *
26
+ * @example
27
+ * const customizer = (a, b) => {
28
+ * if (typeof a === 'string' && typeof b === 'string') {
29
+ * return a.toLowerCase() === b.toLowerCase();
30
+ * }
31
+ * };
32
+ * isEqualWith('Hello', 'hello', customizer); // true
33
+ * isEqualWith({ a: 'Hello' }, { a: 'hello' }, customizer); // true
34
+ * isEqualWith([1, 2, 3], [1, 2, 3], customizer); // true
35
+ */
36
+ declare function isEqualWith(a: any, b: any, areValuesEqual?: (a: any, b: any, property?: PropertyKey, aParent?: any, bParent?: any, stack?: Map<any, any>) => boolean | void): boolean;
37
+
38
+ export { isEqualWith };
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Compares two values for equality using a custom comparison function.
3
+ *
4
+ * The custom function allows for fine-tuned control over the comparison process. If it returns a boolean, that result determines the equality. If it returns undefined, the function falls back to the default equality comparison.
5
+ *
6
+ * This function also uses the custom equality function to compare values inside objects,
7
+ * arrays, maps, sets, and other complex structures, ensuring a deep comparison.
8
+ *
9
+ * This approach provides flexibility in handling complex comparisons while maintaining efficient default behavior for simpler cases.
10
+ *
11
+ * The custom comparison function can take up to six parameters:
12
+ * - `x`: The value from the first object `a`.
13
+ * - `y`: The value from the second object `b`.
14
+ * - `property`: The property key used to get `x` and `y`.
15
+ * - `xParent`: The parent of the first value `x`.
16
+ * - `yParent`: The parent of the second value `y`.
17
+ * - `stack`: An internal stack (Map) to handle circular references.
18
+ *
19
+ * @param {unknown} a - The first value to compare.
20
+ * @param {unknown} b - The second value to compare.
21
+ * @param {(x: any, y: any, property?: PropertyKey, xParent?: any, yParent?: any, stack?: Map<any, any>) => boolean | void} [areValuesEqual=noop] - A function to customize the comparison.
22
+ * If it returns a boolean, that result will be used. If it returns undefined,
23
+ * the default equality comparison will be used.
24
+ * @returns {boolean} `true` if the values are equal according to the customizer, otherwise `false`.
25
+ *
26
+ * @example
27
+ * const customizer = (a, b) => {
28
+ * if (typeof a === 'string' && typeof b === 'string') {
29
+ * return a.toLowerCase() === b.toLowerCase();
30
+ * }
31
+ * };
32
+ * isEqualWith('Hello', 'hello', customizer); // true
33
+ * isEqualWith({ a: 'Hello' }, { a: 'hello' }, customizer); // true
34
+ * isEqualWith([1, 2, 3], [1, 2, 3], customizer); // true
35
+ */
36
+ declare function isEqualWith(a: any, b: any, areValuesEqual?: (a: any, b: any, property?: PropertyKey, aParent?: any, bParent?: any, stack?: Map<any, any>) => boolean | void): boolean;
37
+
38
+ export { isEqualWith };
@@ -0,0 +1,23 @@
1
+ import { after } from '../../function/after.mjs';
2
+ import { noop } from '../../function/noop.mjs';
3
+ import { isEqualWith as isEqualWith$1 } from '../../predicate/isEqualWith.mjs';
4
+
5
+ function isEqualWith(a, b, areValuesEqual = noop) {
6
+ if (typeof areValuesEqual !== 'function') {
7
+ areValuesEqual = noop;
8
+ }
9
+ return isEqualWith$1(a, b, (...args) => {
10
+ const result = areValuesEqual(...args);
11
+ if (result !== undefined) {
12
+ return !!result;
13
+ }
14
+ if (a instanceof Map && b instanceof Map) {
15
+ return isEqualWith(Array.from(a), Array.from(b), after(2, areValuesEqual));
16
+ }
17
+ if (a instanceof Set && b instanceof Set) {
18
+ return isEqualWith(Array.from(a), Array.from(b), after(2, areValuesEqual));
19
+ }
20
+ });
21
+ }
22
+
23
+ export { isEqualWith };
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.23.0-dev.718+8a34bc47",
4
+ "version": "1.23.0-dev.719+35aa0bfe",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {