es-toolkit 1.22.0-dev.694 → 1.22.0-dev.696

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.
@@ -5,7 +5,6 @@
5
5
  * @param {T[]} arr - The array to iterate over.
6
6
  * @param {(item: T, index: number, arr: T[]) => unknown} doesMatch - The function invoked per iteration.
7
7
  * @returns {T[]} - Returns a new array of elements that satisfy the given doesMatch function.
8
-
9
8
  *
10
9
  * @example
11
10
  * filter([1, 2, 3], n => n % 2 === 0)
@@ -30,7 +29,7 @@ declare function filter<T>(arr: readonly T[], doesMatch: Partial<T>): T[];
30
29
  * Filters elements in a arr that match the given key-value pair.
31
30
  *
32
31
  * @template T
33
- * @param {readonly T[]} arr - The array to iterate over.
32
+ * @param {T[]} arr - The array to iterate over.
34
33
  * @param {[keyof T, unknown]} doesMatchProperty - The key-value pair to match.
35
34
  * @returns {T[]} - Returns a new array of elements that match the given key-value pair.
36
35
  *
@@ -44,7 +43,7 @@ declare function filter<T>(arr: readonly T[], doesMatchProperty: [keyof T, unkno
44
43
  * Filters the arr, returning elements that contain the given property name.
45
44
  *
46
45
  * @template T
47
- * @param {readonly T[]} arr - The array to iterate over.
46
+ * @param {T[]} arr - The array to iterate over.
48
47
  * @param {string} propertyToCheck - The property name to check.
49
48
  * @returns {T[]} - Returns a new array of elements that match the given property name.
50
49
  *
@@ -58,25 +57,25 @@ declare function filter<T>(arr: readonly T[], propertyToCheck: string): T[];
58
57
  * Filters items from a object and returns an array of elements that match the given predicate function.
59
58
  *
60
59
  * @template T
61
- * @param {T extends Record<string, unknown> ? T : never} object - The object to iterate over.
62
- * @param {(item: T[keyof T], index: number, arr: T) => unknown} doesMatch - The function invoked per iteration.
60
+ * @param {T} object - The object to iterate over.
61
+ * @param {(value: T[keyof T], key: keyof T, object: T) => unknown} doesMatch - The function invoked per iteration.
63
62
  * @returns {T[]} - Returns a new array of elements that satisfy the given predicate function.
64
63
  *
65
64
  * @example
66
65
  * const obj = { item1: { a: 0 }, item2: { a: 1 }, item3: { a: 0 } }
67
- * filter(obj, items => items.a)
66
+ * filter(obj, value => value.a)
68
67
  * // => [{ a: 1 }]
69
68
  *
70
69
  * const obj = { a: 1, b: 2, c: 3 };
71
- * filter(obj, item => item > 2)
70
+ * filter(obj, value => value > 2)
72
71
  * // => [3]
73
72
  */
74
- declare function filter<T extends Record<string, unknown>>(object: T, doesMatch: (item: T[keyof T], index: number, object: T) => unknown): T[];
73
+ declare function filter<T extends Record<string, unknown>>(object: T, doesMatch: (value: T[keyof T], key: keyof T, object: T) => unknown): T[];
75
74
  /**
76
75
  * Filters elements in a object that match the properties of the given partial object.
77
76
  *
78
77
  * @template T
79
- * @param {T extends Record<string, unknown> ? T : never} object - The object to iterate over.
78
+ * @param {T} object - The object to iterate over.
80
79
  * @param {Partial<T[keyof T]>} doesMatch - The partial object to match
81
80
  * @returns {T[]} - Returns a new array of elements that match the given properties.pair.
82
81
  *
@@ -90,7 +89,7 @@ declare function filter<T extends Record<string, unknown>>(object: T, doesMatch:
90
89
  * Filters elements in a arr that match the given key-value pair.
91
90
  *
92
91
  * @template T
93
- * @param {T extends Record<string, unknown> ? T : never} object - The object to iterate over.
92
+ * @param {T} object - The object to iterate over.
94
93
  * @param {[keyof T, unknown]} doesMatchProperty - The key-value pair to match.
95
94
  * @returns {T[]} - Returns a new array of elements that match the given key-value pair.
96
95
  *
@@ -104,7 +103,7 @@ declare function filter<T extends Record<string, unknown>>(object: T, doesMatchP
104
103
  * Filters the object, returning elements that contain the given property name.
105
104
  *
106
105
  * @template T
107
- * @param {T extends Record<string, unknown> ? T : never} object - The object to iterate over.
106
+ * @param {T} object - The object to iterate over.
108
107
  * @param {string} propertyToCheck - The property name to check.
109
108
  * @returns {T[]} - Returns a new array of elements that match the given property name.
110
109
  *
@@ -5,7 +5,6 @@
5
5
  * @param {T[]} arr - The array to iterate over.
6
6
  * @param {(item: T, index: number, arr: T[]) => unknown} doesMatch - The function invoked per iteration.
7
7
  * @returns {T[]} - Returns a new array of elements that satisfy the given doesMatch function.
8
-
9
8
  *
10
9
  * @example
11
10
  * filter([1, 2, 3], n => n % 2 === 0)
@@ -30,7 +29,7 @@ declare function filter<T>(arr: readonly T[], doesMatch: Partial<T>): T[];
30
29
  * Filters elements in a arr that match the given key-value pair.
31
30
  *
32
31
  * @template T
33
- * @param {readonly T[]} arr - The array to iterate over.
32
+ * @param {T[]} arr - The array to iterate over.
34
33
  * @param {[keyof T, unknown]} doesMatchProperty - The key-value pair to match.
35
34
  * @returns {T[]} - Returns a new array of elements that match the given key-value pair.
36
35
  *
@@ -44,7 +43,7 @@ declare function filter<T>(arr: readonly T[], doesMatchProperty: [keyof T, unkno
44
43
  * Filters the arr, returning elements that contain the given property name.
45
44
  *
46
45
  * @template T
47
- * @param {readonly T[]} arr - The array to iterate over.
46
+ * @param {T[]} arr - The array to iterate over.
48
47
  * @param {string} propertyToCheck - The property name to check.
49
48
  * @returns {T[]} - Returns a new array of elements that match the given property name.
50
49
  *
@@ -58,25 +57,25 @@ declare function filter<T>(arr: readonly T[], propertyToCheck: string): T[];
58
57
  * Filters items from a object and returns an array of elements that match the given predicate function.
59
58
  *
60
59
  * @template T
61
- * @param {T extends Record<string, unknown> ? T : never} object - The object to iterate over.
62
- * @param {(item: T[keyof T], index: number, arr: T) => unknown} doesMatch - The function invoked per iteration.
60
+ * @param {T} object - The object to iterate over.
61
+ * @param {(value: T[keyof T], key: keyof T, object: T) => unknown} doesMatch - The function invoked per iteration.
63
62
  * @returns {T[]} - Returns a new array of elements that satisfy the given predicate function.
64
63
  *
65
64
  * @example
66
65
  * const obj = { item1: { a: 0 }, item2: { a: 1 }, item3: { a: 0 } }
67
- * filter(obj, items => items.a)
66
+ * filter(obj, value => value.a)
68
67
  * // => [{ a: 1 }]
69
68
  *
70
69
  * const obj = { a: 1, b: 2, c: 3 };
71
- * filter(obj, item => item > 2)
70
+ * filter(obj, value => value > 2)
72
71
  * // => [3]
73
72
  */
74
- declare function filter<T extends Record<string, unknown>>(object: T, doesMatch: (item: T[keyof T], index: number, object: T) => unknown): T[];
73
+ declare function filter<T extends Record<string, unknown>>(object: T, doesMatch: (value: T[keyof T], key: keyof T, object: T) => unknown): T[];
75
74
  /**
76
75
  * Filters elements in a object that match the properties of the given partial object.
77
76
  *
78
77
  * @template T
79
- * @param {T extends Record<string, unknown> ? T : never} object - The object to iterate over.
78
+ * @param {T} object - The object to iterate over.
80
79
  * @param {Partial<T[keyof T]>} doesMatch - The partial object to match
81
80
  * @returns {T[]} - Returns a new array of elements that match the given properties.pair.
82
81
  *
@@ -90,7 +89,7 @@ declare function filter<T extends Record<string, unknown>>(object: T, doesMatch:
90
89
  * Filters elements in a arr that match the given key-value pair.
91
90
  *
92
91
  * @template T
93
- * @param {T extends Record<string, unknown> ? T : never} object - The object to iterate over.
92
+ * @param {T} object - The object to iterate over.
94
93
  * @param {[keyof T, unknown]} doesMatchProperty - The key-value pair to match.
95
94
  * @returns {T[]} - Returns a new array of elements that match the given key-value pair.
96
95
  *
@@ -104,7 +103,7 @@ declare function filter<T extends Record<string, unknown>>(object: T, doesMatchP
104
103
  * Filters the object, returning elements that contain the given property name.
105
104
  *
106
105
  * @template T
107
- * @param {T extends Record<string, unknown> ? T : never} object - The object to iterate over.
106
+ * @param {T} object - The object to iterate over.
108
107
  * @param {string} propertyToCheck - The property name to check.
109
108
  * @returns {T[]} - Returns a new array of elements that match the given property name.
110
109
  *
@@ -11,6 +11,19 @@ function filter(source, predicate) {
11
11
  const collection = isArray(source) ? source : Object.values(source);
12
12
  switch (typeof predicate) {
13
13
  case 'function': {
14
+ if (!Array.isArray(source)) {
15
+ const result = [];
16
+ const entries = Object.entries(source);
17
+ for (let i = 0; i < entries.length; i++) {
18
+ const entry = entries[i];
19
+ const key = entry[0];
20
+ const value = entry[1];
21
+ if (predicate(value, key, source)) {
22
+ result.push(value);
23
+ }
24
+ }
25
+ return result;
26
+ }
14
27
  return collection.filter(predicate);
15
28
  }
16
29
  case 'object': {
@@ -7,9 +7,9 @@ const promise_index = require('../_chunk/index-BGZDR9.js');
7
7
  const flowRight = require('../_chunk/flowRight-BzdOZX.js');
8
8
  const range = require('../_chunk/range-BXlMmn.js');
9
9
  const randomInt = require('../_chunk/randomInt-CF7bZK.js');
10
- const toMerged = require('../_chunk/toMerged-2WPeoI.js');
10
+ const toMerged = require('../_chunk/toMerged-BEa9JI.js');
11
11
  const isPlainObject$1 = require('../_chunk/isPlainObject-BIekvL.js');
12
- const isWeakSet$1 = require('../_chunk/isWeakSet-clQklw.js');
12
+ const isWeakSet$1 = require('../_chunk/isWeakSet-CkNwsM.js');
13
13
  const pad$1 = require('../_chunk/pad-Cw2pvt.js');
14
14
 
15
15
  function castArray(value) {
@@ -338,7 +338,7 @@ function has(object, path) {
338
338
  let current = object;
339
339
  for (let i = 0; i < resolvedPath.length; i++) {
340
340
  const key = resolvedPath[i];
341
- if (current == null || !Object.prototype.hasOwnProperty.call(current, key)) {
341
+ if (current == null || !Object.hasOwn(current, key)) {
342
342
  const isSparseIndex = (Array.isArray(current) || isArguments(current)) && isIndex(key) && key < current.length;
343
343
  if (!isSparseIndex) {
344
344
  return false;
@@ -872,6 +872,19 @@ function filter(source, predicate) {
872
872
  const collection = isArray(source) ? source : Object.values(source);
873
873
  switch (typeof predicate) {
874
874
  case 'function': {
875
+ if (!Array.isArray(source)) {
876
+ const result = [];
877
+ const entries = Object.entries(source);
878
+ for (let i = 0; i < entries.length; i++) {
879
+ const entry = entries[i];
880
+ const key = entry[0];
881
+ const value = entry[1];
882
+ if (predicate(value, key, source)) {
883
+ result.push(value);
884
+ }
885
+ }
886
+ return result;
887
+ }
875
888
  return collection.filter(predicate);
876
889
  }
877
890
  case 'object': {
@@ -1139,7 +1152,7 @@ function pick(obj, ...keysArr) {
1139
1152
  }
1140
1153
  for (const key of keys) {
1141
1154
  const value = get(obj, key);
1142
- if (typeof key === 'string' && Object.prototype.hasOwnProperty.call(obj, key)) {
1155
+ if (typeof key === 'string' && Object.hasOwn(obj, key)) {
1143
1156
  result[key] = value;
1144
1157
  }
1145
1158
  else {
@@ -20,7 +20,7 @@ function has(object, path) {
20
20
  let current = object;
21
21
  for (let i = 0; i < resolvedPath.length; i++) {
22
22
  const key = resolvedPath[i];
23
- if (current == null || !Object.prototype.hasOwnProperty.call(current, key)) {
23
+ if (current == null || !Object.hasOwn(current, key)) {
24
24
  const isSparseIndex = (Array.isArray(current) || isArguments(current)) && isIndex(key) && key < current.length;
25
25
  if (!isSparseIndex) {
26
26
  return false;
@@ -25,7 +25,7 @@ function pick(obj, ...keysArr) {
25
25
  }
26
26
  for (const key of keys) {
27
27
  const value = get(obj, key);
28
- if (typeof key === 'string' && Object.prototype.hasOwnProperty.call(obj, key)) {
28
+ if (typeof key === 'string' && Object.hasOwn(obj, key)) {
29
29
  result[key] = value;
30
30
  }
31
31
  else {
package/dist/index.js CHANGED
@@ -11,8 +11,8 @@ const range = require('./_chunk/range-BXlMmn.js');
11
11
  const randomInt = require('./_chunk/randomInt-CF7bZK.js');
12
12
  const math_index = require('./math/index.js');
13
13
  const object_index = require('./object/index.js');
14
- const toMerged = require('./_chunk/toMerged-2WPeoI.js');
15
- const isWeakSet = require('./_chunk/isWeakSet-clQklw.js');
14
+ const toMerged = require('./_chunk/toMerged-BEa9JI.js');
15
+ const isWeakSet = require('./_chunk/isWeakSet-CkNwsM.js');
16
16
  const predicate_index = require('./predicate/index.js');
17
17
  const isPlainObject = require('./_chunk/isPlainObject-BIekvL.js');
18
18
  const pad = require('./_chunk/pad-Cw2pvt.js');
@@ -17,10 +17,10 @@ function cloneDeepImpl(obj, stack = new Map()) {
17
17
  for (let i = 0; i < obj.length; i++) {
18
18
  result[i] = cloneDeepImpl(obj[i], stack);
19
19
  }
20
- if (Object.prototype.hasOwnProperty.call(obj, 'index')) {
20
+ if (Object.hasOwn(obj, 'index')) {
21
21
  result.index = obj.index;
22
22
  }
23
- if (Object.prototype.hasOwnProperty.call(obj, 'input')) {
23
+ if (Object.hasOwn(obj, 'input')) {
24
24
  result.input = obj.input;
25
25
  }
26
26
  return result;
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const toMerged = require('../_chunk/toMerged-2WPeoI.js');
5
+ const toMerged = require('../_chunk/toMerged-BEa9JI.js');
6
6
 
7
7
  function omit(obj, keys) {
8
8
  const result = { ...obj };
@@ -17,7 +17,7 @@ function pick(obj, keys) {
17
17
  const result = {};
18
18
  for (let i = 0; i < keys.length; i++) {
19
19
  const key = keys[i];
20
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
20
+ if (Object.hasOwn(obj, key)) {
21
21
  result[key] = obj[key];
22
22
  }
23
23
  }
@@ -2,7 +2,7 @@ function pick(obj, keys) {
2
2
  const result = {};
3
3
  for (let i = 0; i < keys.length; i++) {
4
4
  const key = keys[i];
5
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
5
+ if (Object.hasOwn(obj, key)) {
6
6
  result[key] = obj[key];
7
7
  }
8
8
  }
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const isWeakSet = require('../_chunk/isWeakSet-clQklw.js');
5
+ const isWeakSet = require('../_chunk/isWeakSet-CkNwsM.js');
6
6
  const isPlainObject = require('../_chunk/isPlainObject-BIekvL.js');
7
7
 
8
8
  function isError(value) {
@@ -152,7 +152,7 @@ function areObjectsEqual(a, b, stack) {
152
152
  for (let i = 0; i < aKeys.length; i++) {
153
153
  const propKey = aKeys[i];
154
154
  const aProp = a[propKey];
155
- if (!Object.prototype.hasOwnProperty.call(b, propKey)) {
155
+ if (!Object.hasOwn(b, propKey)) {
156
156
  return false;
157
157
  }
158
158
  const bProp = b[propKey];
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.22.0-dev.694+e9123bea",
4
+ "version": "1.22.0-dev.696+0c7d8897",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {