es-toolkit 1.32.0-dev.1018 → 1.32.0-dev.1020

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.
@@ -8,7 +8,6 @@ export { initial } from '../array/initial.mjs';
8
8
  export { isSubset } from '../array/isSubset.mjs';
9
9
  export { isSubsetWith } from '../array/isSubsetWith.mjs';
10
10
  export { keyBy } from '../array/keyBy.mjs';
11
- export { maxBy } from '../array/maxBy.mjs';
12
11
  export { minBy } from '../array/minBy.mjs';
13
12
  export { partition } from '../array/partition.mjs';
14
13
  export { pullAt } from '../array/pullAt.mjs';
@@ -53,6 +52,7 @@ export { isBlob } from '../predicate/isBlob.mjs';
53
52
  export { isEqual } from '../predicate/isEqual.mjs';
54
53
  export { isFile } from '../predicate/isFile.mjs';
55
54
  export { isFunction } from '../predicate/isFunction.mjs';
55
+ export { isJSON } from '../predicate/isJSON.mjs';
56
56
  export { isJSONArray, isJSONObject, isJSONValue } from '../predicate/isJSONValue.mjs';
57
57
  export { isLength } from '../predicate/isLength.mjs';
58
58
  export { isNotNil } from '../predicate/isNotNil.mjs';
@@ -155,6 +155,7 @@ export { divide } from './math/divide.mjs';
155
155
  export { floor } from './math/floor.mjs';
156
156
  export { inRange } from './math/inRange.mjs';
157
157
  export { max } from './math/max.mjs';
158
+ export { maxBy } from './math/maxBy.mjs';
158
159
  export { min } from './math/min.mjs';
159
160
  export { multiply } from './math/multiply.mjs';
160
161
  export { parseInt } from './math/parseInt.mjs';
@@ -8,7 +8,6 @@ export { initial } from '../array/initial.js';
8
8
  export { isSubset } from '../array/isSubset.js';
9
9
  export { isSubsetWith } from '../array/isSubsetWith.js';
10
10
  export { keyBy } from '../array/keyBy.js';
11
- export { maxBy } from '../array/maxBy.js';
12
11
  export { minBy } from '../array/minBy.js';
13
12
  export { partition } from '../array/partition.js';
14
13
  export { pullAt } from '../array/pullAt.js';
@@ -53,6 +52,7 @@ export { isBlob } from '../predicate/isBlob.js';
53
52
  export { isEqual } from '../predicate/isEqual.js';
54
53
  export { isFile } from '../predicate/isFile.js';
55
54
  export { isFunction } from '../predicate/isFunction.js';
55
+ export { isJSON } from '../predicate/isJSON.js';
56
56
  export { isJSONArray, isJSONObject, isJSONValue } from '../predicate/isJSONValue.js';
57
57
  export { isLength } from '../predicate/isLength.js';
58
58
  export { isNotNil } from '../predicate/isNotNil.js';
@@ -155,6 +155,7 @@ export { divide } from './math/divide.js';
155
155
  export { floor } from './math/floor.js';
156
156
  export { inRange } from './math/inRange.js';
157
157
  export { max } from './math/max.js';
158
+ export { maxBy } from './math/maxBy.js';
158
159
  export { min } from './math/min.js';
159
160
  export { multiply } from './math/multiply.js';
160
161
  export { parseInt } from './math/parseInt.js';
@@ -11,7 +11,7 @@ const range$1 = require('../_chunk/range-HnEIT7.js');
11
11
  const randomInt = require('../_chunk/randomInt-CF7bZK.js');
12
12
  const toMerged = require('../_chunk/toMerged-BQTfB8.js');
13
13
  const isPlainObject$1 = require('../_chunk/isPlainObject-Xaozpc.js');
14
- const isWeakSet$1 = require('../_chunk/isWeakSet-DoHqUM.js');
14
+ const isWeakSet$1 = require('../_chunk/isWeakSet-TIM260.js');
15
15
  const promise_index = require('../promise/index.js');
16
16
  const upperFirst$1 = require('../_chunk/upperFirst-nA5L7X.js');
17
17
  const util_index = require('../util/index.js');
@@ -2092,6 +2092,13 @@ function max(items = []) {
2092
2092
  return maxElement;
2093
2093
  }
2094
2094
 
2095
+ function maxBy(items, iteratee$1) {
2096
+ if (items == null) {
2097
+ return undefined;
2098
+ }
2099
+ return zipWith.maxBy(Array.from(items), iteratee(iteratee$1));
2100
+ }
2101
+
2095
2102
  function min(items = []) {
2096
2103
  let minElement = items[0];
2097
2104
  let min = undefined;
@@ -3323,7 +3330,6 @@ exports.initial = zipWith.initial;
3323
3330
  exports.isSubset = zipWith.isSubset;
3324
3331
  exports.isSubsetWith = zipWith.isSubsetWith;
3325
3332
  exports.keyBy = zipWith.keyBy;
3326
- exports.maxBy = zipWith.maxBy;
3327
3333
  exports.minBy = zipWith.minBy;
3328
3334
  exports.partition = zipWith.partition;
3329
3335
  exports.pullAt = zipWith.pullAt;
@@ -3370,6 +3376,7 @@ exports.isBlob = isWeakSet$1.isBlob;
3370
3376
  exports.isEqual = isWeakSet$1.isEqual;
3371
3377
  exports.isFile = isWeakSet$1.isFile;
3372
3378
  exports.isFunction = isWeakSet$1.isFunction;
3379
+ exports.isJSON = isWeakSet$1.isJSON;
3373
3380
  exports.isJSONArray = isWeakSet$1.isJSONArray;
3374
3381
  exports.isJSONObject = isWeakSet$1.isJSONObject;
3375
3382
  exports.isJSONValue = isWeakSet$1.isJSONValue;
@@ -3505,6 +3512,7 @@ exports.mapValues = mapValues;
3505
3512
  exports.matches = matches;
3506
3513
  exports.matchesProperty = matchesProperty;
3507
3514
  exports.max = max;
3515
+ exports.maxBy = maxBy;
3508
3516
  exports.merge = merge;
3509
3517
  exports.mergeWith = mergeWith;
3510
3518
  exports.method = method;
@@ -8,7 +8,6 @@ export { initial } from '../array/initial.mjs';
8
8
  export { isSubset } from '../array/isSubset.mjs';
9
9
  export { isSubsetWith } from '../array/isSubsetWith.mjs';
10
10
  export { keyBy } from '../array/keyBy.mjs';
11
- export { maxBy } from '../array/maxBy.mjs';
12
11
  export { minBy } from '../array/minBy.mjs';
13
12
  export { partition } from '../array/partition.mjs';
14
13
  export { pullAt } from '../array/pullAt.mjs';
@@ -55,6 +54,7 @@ export { isEqual } from '../predicate/isEqual.mjs';
55
54
  export { eq } from './util/eq.mjs';
56
55
  export { isFile } from '../predicate/isFile.mjs';
57
56
  export { isFunction } from '../predicate/isFunction.mjs';
57
+ export { isJSON } from '../predicate/isJSON.mjs';
58
58
  export { isJSONArray, isJSONObject, isJSONValue } from '../predicate/isJSONValue.mjs';
59
59
  export { isLength } from '../predicate/isLength.mjs';
60
60
  export { isNotNil } from '../predicate/isNotNil.mjs';
@@ -157,6 +157,7 @@ export { divide } from './math/divide.mjs';
157
157
  export { floor } from './math/floor.mjs';
158
158
  export { inRange } from './math/inRange.mjs';
159
159
  export { max } from './math/max.mjs';
160
+ export { maxBy } from './math/maxBy.mjs';
160
161
  export { min } from './math/min.mjs';
161
162
  export { multiply } from './math/multiply.mjs';
162
163
  export { parseInt } from './math/parseInt.mjs';
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Finds the element in an array that has the maximum value when applying
3
+ * the `iteratee` to each element.
4
+ *
5
+ * @template T - The type of elements in the array.
6
+ * @param {T[]} items The array of elements to search.
7
+ * @param {((element: T) => number) | keyof T | [keyof T, unknown] | Partial<T>} iteratee
8
+ * The criteria used to determine the maximum value.
9
+ * - If a **function** is provided, it extracts a numeric value from each element.
10
+ * - If a **string** is provided, it is treated as a key to extract values from the objects.
11
+ * - If a **[key, value]** pair is provided, it matches elements with the specified key-value pair.
12
+ * - If an **object** is provided, it matches elements that contain the specified properties.
13
+ * @returns {T | undefined} The element with the maximum value as determined by the `iteratee`.
14
+ * @example
15
+ * maxBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 3 }
16
+ * maxBy([], x => x.a); // Returns: undefined
17
+ * maxBy(
18
+ * [
19
+ * { name: 'john', age: 30 },
20
+ * { name: 'jane', age: 28 },
21
+ * { name: 'joe', age: 26 },
22
+ * ],
23
+ * x => x.age
24
+ * ); // Returns: { name: 'john', age: 30 }
25
+ * maxBy([{ a: 1 }, { a: 2 }], 'a'); // Returns: { a: 2 }
26
+ * maxBy([{ a: 1 }, { a: 2 }], ['a', 1]); // Returns: { a: 1 }
27
+ * maxBy([{ a: 1 }, { a: 2 }], { a: 1 }); // Returns: { a: 1 }
28
+ */
29
+ declare function maxBy<T>(items: ArrayLike<T> | null | undefined, iteratee: ((element: T) => number) | keyof T | [keyof T, unknown] | Partial<T>): T | undefined;
30
+
31
+ export { maxBy };
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Finds the element in an array that has the maximum value when applying
3
+ * the `iteratee` to each element.
4
+ *
5
+ * @template T - The type of elements in the array.
6
+ * @param {T[]} items The array of elements to search.
7
+ * @param {((element: T) => number) | keyof T | [keyof T, unknown] | Partial<T>} iteratee
8
+ * The criteria used to determine the maximum value.
9
+ * - If a **function** is provided, it extracts a numeric value from each element.
10
+ * - If a **string** is provided, it is treated as a key to extract values from the objects.
11
+ * - If a **[key, value]** pair is provided, it matches elements with the specified key-value pair.
12
+ * - If an **object** is provided, it matches elements that contain the specified properties.
13
+ * @returns {T | undefined} The element with the maximum value as determined by the `iteratee`.
14
+ * @example
15
+ * maxBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 3 }
16
+ * maxBy([], x => x.a); // Returns: undefined
17
+ * maxBy(
18
+ * [
19
+ * { name: 'john', age: 30 },
20
+ * { name: 'jane', age: 28 },
21
+ * { name: 'joe', age: 26 },
22
+ * ],
23
+ * x => x.age
24
+ * ); // Returns: { name: 'john', age: 30 }
25
+ * maxBy([{ a: 1 }, { a: 2 }], 'a'); // Returns: { a: 2 }
26
+ * maxBy([{ a: 1 }, { a: 2 }], ['a', 1]); // Returns: { a: 1 }
27
+ * maxBy([{ a: 1 }, { a: 2 }], { a: 1 }); // Returns: { a: 1 }
28
+ */
29
+ declare function maxBy<T>(items: ArrayLike<T> | null | undefined, iteratee: ((element: T) => number) | keyof T | [keyof T, unknown] | Partial<T>): T | undefined;
30
+
31
+ export { maxBy };
@@ -0,0 +1,11 @@
1
+ import { maxBy as maxBy$1 } from '../../array/maxBy.mjs';
2
+ import { iteratee } from '../util/iteratee.mjs';
3
+
4
+ function maxBy(items, iteratee$1) {
5
+ if (items == null) {
6
+ return undefined;
7
+ }
8
+ return maxBy$1(Array.from(items), iteratee(iteratee$1));
9
+ }
10
+
11
+ export { maxBy };
package/dist/index.d.mts CHANGED
@@ -119,6 +119,7 @@ export { isEqualWith } from './predicate/isEqualWith.mjs';
119
119
  export { isError } from './predicate/isError.mjs';
120
120
  export { isFile } from './predicate/isFile.mjs';
121
121
  export { isFunction } from './predicate/isFunction.mjs';
122
+ export { isJSON } from './predicate/isJSON.mjs';
122
123
  export { isJSONArray, isJSONObject, isJSONValue } from './predicate/isJSONValue.mjs';
123
124
  export { isLength } from './predicate/isLength.mjs';
124
125
  export { isMap } from './predicate/isMap.mjs';
package/dist/index.d.ts CHANGED
@@ -119,6 +119,7 @@ export { isEqualWith } from './predicate/isEqualWith.js';
119
119
  export { isError } from './predicate/isError.js';
120
120
  export { isFile } from './predicate/isFile.js';
121
121
  export { isFunction } from './predicate/isFunction.js';
122
+ export { isJSON } from './predicate/isJSON.js';
122
123
  export { isJSONArray, isJSONObject, isJSONValue } from './predicate/isJSONValue.js';
123
124
  export { isLength } from './predicate/isLength.js';
124
125
  export { isMap } from './predicate/isMap.js';
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ const randomInt = require('./_chunk/randomInt-CF7bZK.js');
14
14
  const math_index = require('./math/index.js');
15
15
  const toMerged = require('./_chunk/toMerged-BQTfB8.js');
16
16
  const object_index = require('./object/index.js');
17
- const isWeakSet = require('./_chunk/isWeakSet-DoHqUM.js');
17
+ const isWeakSet = require('./_chunk/isWeakSet-TIM260.js');
18
18
  const predicate_index = require('./predicate/index.js');
19
19
  const isPlainObject = require('./_chunk/isPlainObject-Xaozpc.js');
20
20
  const delay = require('./_chunk/delay-_VMfFa.js');
@@ -144,6 +144,7 @@ exports.isEqual = isWeakSet.isEqual;
144
144
  exports.isEqualWith = isWeakSet.isEqualWith;
145
145
  exports.isFile = isWeakSet.isFile;
146
146
  exports.isFunction = isWeakSet.isFunction;
147
+ exports.isJSON = isWeakSet.isJSON;
147
148
  exports.isJSONArray = isWeakSet.isJSONArray;
148
149
  exports.isJSONObject = isWeakSet.isJSONObject;
149
150
  exports.isJSONValue = isWeakSet.isJSONValue;
package/dist/index.mjs CHANGED
@@ -119,6 +119,7 @@ export { isEqualWith } from './predicate/isEqualWith.mjs';
119
119
  export { isError } from './predicate/isError.mjs';
120
120
  export { isFile } from './predicate/isFile.mjs';
121
121
  export { isFunction } from './predicate/isFunction.mjs';
122
+ export { isJSON } from './predicate/isJSON.mjs';
122
123
  export { isJSONArray, isJSONObject, isJSONValue } from './predicate/isJSONValue.mjs';
123
124
  export { isLength } from './predicate/isLength.mjs';
124
125
  export { isMap } from './predicate/isMap.mjs';
@@ -8,6 +8,7 @@ export { isEqualWith } from './isEqualWith.mjs';
8
8
  export { isError } from './isError.mjs';
9
9
  export { isFile } from './isFile.mjs';
10
10
  export { isFunction } from './isFunction.mjs';
11
+ export { isJSON } from './isJSON.mjs';
11
12
  export { isJSONArray, isJSONObject, isJSONValue } from './isJSONValue.mjs';
12
13
  export { isLength } from './isLength.mjs';
13
14
  export { isMap } from './isMap.mjs';
@@ -8,6 +8,7 @@ export { isEqualWith } from './isEqualWith.js';
8
8
  export { isError } from './isError.js';
9
9
  export { isFile } from './isFile.js';
10
10
  export { isFunction } from './isFunction.js';
11
+ export { isJSON } from './isJSON.js';
11
12
  export { isJSONArray, isJSONObject, isJSONValue } from './isJSONValue.js';
12
13
  export { isLength } from './isLength.js';
13
14
  export { isMap } from './isMap.js';
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const isWeakSet = require('../_chunk/isWeakSet-DoHqUM.js');
5
+ const isWeakSet = require('../_chunk/isWeakSet-TIM260.js');
6
6
  const isPlainObject = require('../_chunk/isPlainObject-Xaozpc.js');
7
7
 
8
8
  function isBoolean(x) {
@@ -25,6 +25,7 @@ exports.isEqual = isWeakSet.isEqual;
25
25
  exports.isEqualWith = isWeakSet.isEqualWith;
26
26
  exports.isFile = isWeakSet.isFile;
27
27
  exports.isFunction = isWeakSet.isFunction;
28
+ exports.isJSON = isWeakSet.isJSON;
28
29
  exports.isJSONArray = isWeakSet.isJSONArray;
29
30
  exports.isJSONObject = isWeakSet.isJSONObject;
30
31
  exports.isJSONValue = isWeakSet.isJSONValue;
@@ -8,6 +8,7 @@ export { isEqualWith } from './isEqualWith.mjs';
8
8
  export { isError } from './isError.mjs';
9
9
  export { isFile } from './isFile.mjs';
10
10
  export { isFunction } from './isFunction.mjs';
11
+ export { isJSON } from './isJSON.mjs';
11
12
  export { isJSONArray, isJSONObject, isJSONValue } from './isJSONValue.mjs';
12
13
  export { isLength } from './isLength.mjs';
13
14
  export { isMap } from './isMap.mjs';
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Checks if a given value is a valid JSON string.
3
+ *
4
+ * A valid JSON string is one that can be successfully parsed using `JSON.parse()`. According to JSON
5
+ * specifications, valid JSON can represent:
6
+ * - Objects (with string keys and valid JSON values)
7
+ * - Arrays (containing valid JSON values)
8
+ * - Strings
9
+ * - Numbers
10
+ * - Booleans
11
+ * - null
12
+ *
13
+ * String values like `"null"`, `"true"`, `"false"`, and numeric strings (e.g., `"42"`) are considered
14
+ * valid JSON and will return true.
15
+ *
16
+ * This function serves as a type guard in TypeScript, narrowing the type of the argument to `string`.
17
+ *
18
+ * @param {unknown} value The value to check.
19
+ * @returns {boolean} Returns `true` if `value` is a valid JSON string, else `false`.
20
+ *
21
+ * @example
22
+ * isJSON('{"name":"John","age":30}'); // true
23
+ * isJSON('[1,2,3]'); // true
24
+ * isJSON('true'); // true
25
+ * isJSON('invalid json'); // false
26
+ * isJSON({ name: 'John' }); // false (not a string)
27
+ * isJSON(null); // false (not a string)
28
+ */
29
+ declare function isJSON(value: unknown): value is string;
30
+
31
+ export { isJSON };
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Checks if a given value is a valid JSON string.
3
+ *
4
+ * A valid JSON string is one that can be successfully parsed using `JSON.parse()`. According to JSON
5
+ * specifications, valid JSON can represent:
6
+ * - Objects (with string keys and valid JSON values)
7
+ * - Arrays (containing valid JSON values)
8
+ * - Strings
9
+ * - Numbers
10
+ * - Booleans
11
+ * - null
12
+ *
13
+ * String values like `"null"`, `"true"`, `"false"`, and numeric strings (e.g., `"42"`) are considered
14
+ * valid JSON and will return true.
15
+ *
16
+ * This function serves as a type guard in TypeScript, narrowing the type of the argument to `string`.
17
+ *
18
+ * @param {unknown} value The value to check.
19
+ * @returns {boolean} Returns `true` if `value` is a valid JSON string, else `false`.
20
+ *
21
+ * @example
22
+ * isJSON('{"name":"John","age":30}'); // true
23
+ * isJSON('[1,2,3]'); // true
24
+ * isJSON('true'); // true
25
+ * isJSON('invalid json'); // false
26
+ * isJSON({ name: 'John' }); // false (not a string)
27
+ * isJSON(null); // false (not a string)
28
+ */
29
+ declare function isJSON(value: unknown): value is string;
30
+
31
+ export { isJSON };
@@ -0,0 +1,14 @@
1
+ function isJSON(value) {
2
+ if (typeof value !== 'string') {
3
+ return false;
4
+ }
5
+ try {
6
+ JSON.parse(value);
7
+ return true;
8
+ }
9
+ catch {
10
+ return false;
11
+ }
12
+ }
13
+
14
+ export { isJSON };
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.32.0-dev.1018+e9e57e9c",
4
+ "version": "1.32.0-dev.1020+a1334be2",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {