es-toolkit 1.18.0-dev.596 → 1.18.0-dev.600

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.
@@ -16,6 +16,6 @@
16
16
  * indexOf(array, 3); // => 2
17
17
  * indexOf(array, NaN); // => 3
18
18
  */
19
- declare function indexOf<T>(array: T[] | null | undefined, searchElement: T, fromIndex?: number): number;
19
+ declare function indexOf<T>(array: readonly T[] | null | undefined, searchElement: T, fromIndex?: number): number;
20
20
 
21
21
  export { indexOf };
@@ -16,6 +16,6 @@
16
16
  * indexOf(array, 3); // => 2
17
17
  * indexOf(array, NaN); // => 3
18
18
  */
19
- declare function indexOf<T>(array: T[] | null | undefined, searchElement: T, fromIndex?: number): number;
19
+ declare function indexOf<T>(array: readonly T[] | null | undefined, searchElement: T, fromIndex?: number): number;
20
20
 
21
21
  export { indexOf };
@@ -1,6 +1,6 @@
1
1
  import { compareValues } from '../_internal/compareValues.mjs';
2
2
  import { isKey } from '../_internal/isKey.mjs';
3
- import { toPath } from '../_internal/toPath.mjs';
3
+ import { toPath } from '../util/toPath.mjs';
4
4
 
5
5
  function orderBy(collection, criteria, orders) {
6
6
  if (collection == null || typeof collection === 'number') {
@@ -135,6 +135,7 @@ export { mapValues } from './object/mapValues.mjs';
135
135
  export { merge } from './object/merge.mjs';
136
136
  export { mergeWith } from './object/mergeWith.mjs';
137
137
  export { fromPairs } from './object/fromPairs.mjs';
138
+ export { unset } from './object/unset.mjs';
138
139
  export { isPlainObject } from './predicate/isPlainObject.mjs';
139
140
  export { isArray } from './predicate/isArray.mjs';
140
141
  export { isArguments } from './predicate/isArguments.mjs';
@@ -165,7 +166,6 @@ export { endsWith } from './string/endsWith.mjs';
165
166
  export { padStart } from './string/padStart.mjs';
166
167
  export { padEnd } from './string/padEnd.mjs';
167
168
  export { repeat } from './string/repeat.mjs';
168
- export { toString } from './string/toString.mjs';
169
169
  export { trim } from './string/trim.mjs';
170
170
  export { trimStart } from './string/trimStart.mjs';
171
171
  export { trimEnd } from './string/trimEnd.mjs';
@@ -175,3 +175,5 @@ export { ceil } from './math/ceil.mjs';
175
175
  export { floor } from './math/floor.mjs';
176
176
  export { round } from './math/round.mjs';
177
177
  export { parseInt } from './math/parseInt.mjs';
178
+ export { toPath } from './util/toPath.mjs';
179
+ export { toString } from './util/toString.mjs';
@@ -135,6 +135,7 @@ export { mapValues } from './object/mapValues.js';
135
135
  export { merge } from './object/merge.js';
136
136
  export { mergeWith } from './object/mergeWith.js';
137
137
  export { fromPairs } from './object/fromPairs.js';
138
+ export { unset } from './object/unset.js';
138
139
  export { isPlainObject } from './predicate/isPlainObject.js';
139
140
  export { isArray } from './predicate/isArray.js';
140
141
  export { isArguments } from './predicate/isArguments.js';
@@ -165,7 +166,6 @@ export { endsWith } from './string/endsWith.js';
165
166
  export { padStart } from './string/padStart.js';
166
167
  export { padEnd } from './string/padEnd.js';
167
168
  export { repeat } from './string/repeat.js';
168
- export { toString } from './string/toString.js';
169
169
  export { trim } from './string/trim.js';
170
170
  export { trimStart } from './string/trimStart.js';
171
171
  export { trimEnd } from './string/trimEnd.js';
@@ -175,3 +175,5 @@ export { ceil } from './math/ceil.js';
175
175
  export { floor } from './math/floor.js';
176
176
  export { round } from './math/round.js';
177
177
  export { parseInt } from './math/parseInt.js';
178
+ export { toPath } from './util/toPath.js';
179
+ export { toString } from './util/toString.js';
@@ -972,6 +972,24 @@ function fromPairs(pairs) {
972
972
  return result;
973
973
  }
974
974
 
975
+ function unset(obj, path) {
976
+ if (obj == null) {
977
+ return true;
978
+ }
979
+ const resolvedPath = Array.isArray(path) ? path : typeof path === 'string' ? toPath(path) : [path];
980
+ const parent = get(obj, resolvedPath.slice(0, -1), obj);
981
+ const lastKey = toKey(resolvedPath[resolvedPath.length - 1]);
982
+ if (typeof parent !== 'object' || parent == null || !Object.prototype.hasOwnProperty.call(parent, lastKey)) {
983
+ return true;
984
+ }
985
+ const isDeletable = Object.getOwnPropertyDescriptor(parent, lastKey)?.configurable;
986
+ if (!isDeletable) {
987
+ return false;
988
+ }
989
+ delete parent[lastKey];
990
+ return true;
991
+ }
992
+
975
993
  function isArray(value) {
976
994
  return Array.isArray(value);
977
995
  }
@@ -1092,20 +1110,6 @@ function repeat(str, n) {
1092
1110
  return str.repeat(n);
1093
1111
  }
1094
1112
 
1095
- function toString(value) {
1096
- if (value == null) {
1097
- return '';
1098
- }
1099
- if (Array.isArray(value)) {
1100
- return value.map(toString).join(',');
1101
- }
1102
- const result = String(value);
1103
- if (result === '0' && Object.is(Number(value), -0)) {
1104
- return '-0';
1105
- }
1106
- return result;
1107
- }
1108
-
1109
1113
  function trim(str, chars, guard) {
1110
1114
  if (str == null) {
1111
1115
  return '';
@@ -1233,6 +1237,20 @@ function parseInt(string, radix = 0, guard) {
1233
1237
  return Number.parseInt(string, radix);
1234
1238
  }
1235
1239
 
1240
+ function toString(value) {
1241
+ if (value == null) {
1242
+ return '';
1243
+ }
1244
+ if (Array.isArray(value)) {
1245
+ return value.map(toString).join(',');
1246
+ }
1247
+ const result = String(value);
1248
+ if (result === '0' && Object.is(Number(value), -0)) {
1249
+ return '-0';
1250
+ }
1251
+ return result;
1252
+ }
1253
+
1236
1254
  exports.at = zipWith.at;
1237
1255
  exports.compact = zipWith.compact;
1238
1256
  exports.countBy = zipWith.countBy;
@@ -1406,8 +1424,10 @@ exports.sortBy = sortBy;
1406
1424
  exports.spread = spread;
1407
1425
  exports.startCase = startCase;
1408
1426
  exports.startsWith = startsWith;
1427
+ exports.toPath = toPath;
1409
1428
  exports.toString = toString;
1410
1429
  exports.trim = trim;
1411
1430
  exports.trimEnd = trimEnd;
1412
1431
  exports.trimStart = trimStart;
1432
+ exports.unset = unset;
1413
1433
  exports.zipObjectDeep = zipObjectDeep;
@@ -136,6 +136,7 @@ export { mapValues } from './object/mapValues.mjs';
136
136
  export { merge } from './object/merge.mjs';
137
137
  export { mergeWith } from './object/mergeWith.mjs';
138
138
  export { fromPairs } from './object/fromPairs.mjs';
139
+ export { unset } from './object/unset.mjs';
139
140
  export { isPlainObject } from './predicate/isPlainObject.mjs';
140
141
  export { isArray } from './predicate/isArray.mjs';
141
142
  export { isArguments } from './predicate/isArguments.mjs';
@@ -165,7 +166,6 @@ export { endsWith } from './string/endsWith.mjs';
165
166
  export { padStart } from './string/padStart.mjs';
166
167
  export { padEnd } from './string/padEnd.mjs';
167
168
  export { repeat } from './string/repeat.mjs';
168
- export { toString } from './string/toString.mjs';
169
169
  export { trim } from './string/trim.mjs';
170
170
  export { trimStart } from './string/trimStart.mjs';
171
171
  export { trimEnd } from './string/trimEnd.mjs';
@@ -175,3 +175,5 @@ export { ceil } from './math/ceil.mjs';
175
175
  export { floor } from './math/floor.mjs';
176
176
  export { round } from './math/round.mjs';
177
177
  export { parseInt } from './math/parseInt.mjs';
178
+ export { toPath } from './util/toPath.mjs';
179
+ export { toString } from './util/toString.mjs';
@@ -1,6 +1,6 @@
1
1
  import { isDeepKey } from '../_internal/isDeepKey.mjs';
2
2
  import { toKey } from '../_internal/toKey.mjs';
3
- import { toPath } from '../_internal/toPath.mjs';
3
+ import { toPath } from '../util/toPath.mjs';
4
4
 
5
5
  function get(object, path, defaultValue) {
6
6
  let resolvedPath;
@@ -1,6 +1,6 @@
1
1
  import { isDeepKey } from '../_internal/isDeepKey.mjs';
2
2
  import { isIndex } from '../_internal/isIndex.mjs';
3
- import { toPath } from '../_internal/toPath.mjs';
3
+ import { toPath } from '../util/toPath.mjs';
4
4
  import { isArguments } from '../predicate/isArguments.mjs';
5
5
 
6
6
  function has(object, path) {
@@ -1,5 +1,5 @@
1
1
  import { isIndex } from '../_internal/isIndex.mjs';
2
- import { toPath } from '../_internal/toPath.mjs';
2
+ import { toPath } from '../util/toPath.mjs';
3
3
 
4
4
  function set(obj, path, value) {
5
5
  const resolvedPath = Array.isArray(path) ? path : typeof path === 'string' ? toPath(path) : [path];
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Removes the property at the given path of the object.
3
+ *
4
+ * @param {unknown} obj - The object to modify.
5
+ * @param {PropertyKey | readonly PropertyKey[]} path - The path of the property to unset.
6
+ * @returns {boolean} - Returns true if the property is deleted, else false.
7
+ *
8
+ * @example
9
+ * const obj = { a: { b: { c: 42 } } };
10
+ * unset(obj, 'a.b.c'); // true
11
+ * console.log(obj); // { a: { b: {} } }
12
+ *
13
+ * @example
14
+ * const obj = { a: { b: { c: 42 } } };
15
+ * unset(obj, ['a', 'b', 'c']); // true
16
+ * console.log(obj); // { a: { b: {} } }
17
+ */
18
+ declare function unset(obj: unknown, path: PropertyKey | readonly PropertyKey[]): boolean;
19
+
20
+ export { unset };
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Removes the property at the given path of the object.
3
+ *
4
+ * @param {unknown} obj - The object to modify.
5
+ * @param {PropertyKey | readonly PropertyKey[]} path - The path of the property to unset.
6
+ * @returns {boolean} - Returns true if the property is deleted, else false.
7
+ *
8
+ * @example
9
+ * const obj = { a: { b: { c: 42 } } };
10
+ * unset(obj, 'a.b.c'); // true
11
+ * console.log(obj); // { a: { b: {} } }
12
+ *
13
+ * @example
14
+ * const obj = { a: { b: { c: 42 } } };
15
+ * unset(obj, ['a', 'b', 'c']); // true
16
+ * console.log(obj); // { a: { b: {} } }
17
+ */
18
+ declare function unset(obj: unknown, path: PropertyKey | readonly PropertyKey[]): boolean;
19
+
20
+ export { unset };
@@ -0,0 +1,23 @@
1
+ import { toKey } from '../_internal/toKey.mjs';
2
+ import { toPath } from '../util/toPath.mjs';
3
+ import { get } from './get.mjs';
4
+
5
+ function unset(obj, path) {
6
+ if (obj == null) {
7
+ return true;
8
+ }
9
+ const resolvedPath = Array.isArray(path) ? path : typeof path === 'string' ? toPath(path) : [path];
10
+ const parent = get(obj, resolvedPath.slice(0, -1), obj);
11
+ const lastKey = toKey(resolvedPath[resolvedPath.length - 1]);
12
+ if (typeof parent !== 'object' || parent == null || !Object.prototype.hasOwnProperty.call(parent, lastKey)) {
13
+ return true;
14
+ }
15
+ const isDeletable = Object.getOwnPropertyDescriptor(parent, lastKey)?.configurable;
16
+ if (!isDeletable) {
17
+ return false;
18
+ }
19
+ delete parent[lastKey];
20
+ return true;
21
+ }
22
+
23
+ export { unset };
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Converts a deep key string into an array of path segments.
3
+ *
4
+ * This function takes a string representing a deep key (e.g., 'a.b.c' or 'a[b][c]') and breaks it down into an array of strings, each representing a segment of the path.
5
+ *
6
+ * @param {string} deepKey - The deep key string to convert.
7
+ * @returns {string[]} An array of strings, each representing a segment of the path.
8
+ *
9
+ * Examples:
10
+ *
11
+ * toPath('a.b.c') // Returns ['a', 'b', 'c']
12
+ * toPath('a[b][c]') // Returns ['a', 'b', 'c']
13
+ * toPath('.a.b.c') // Returns ['', 'a', 'b', 'c']
14
+ * toPath('a["b.c"].d') // Returns ['a', 'b.c', 'd']
15
+ * toPath('') // Returns []
16
+ * toPath('.a[b].c.d[e]["f.g"].h') // Returns ['', 'a', 'b', 'c', 'd', 'e', 'f.g', 'h']
17
+ */
18
+ declare function toPath(deepKey: string): string[];
19
+
20
+ export { toPath };
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Converts a deep key string into an array of path segments.
3
+ *
4
+ * This function takes a string representing a deep key (e.g., 'a.b.c' or 'a[b][c]') and breaks it down into an array of strings, each representing a segment of the path.
5
+ *
6
+ * @param {string} deepKey - The deep key string to convert.
7
+ * @returns {string[]} An array of strings, each representing a segment of the path.
8
+ *
9
+ * Examples:
10
+ *
11
+ * toPath('a.b.c') // Returns ['a', 'b', 'c']
12
+ * toPath('a[b][c]') // Returns ['a', 'b', 'c']
13
+ * toPath('.a.b.c') // Returns ['', 'a', 'b', 'c']
14
+ * toPath('a["b.c"].d') // Returns ['a', 'b.c', 'd']
15
+ * toPath('') // Returns []
16
+ * toPath('.a[b].c.d[e]["f.g"].h') // Returns ['', 'a', 'b', 'c', 'd', 'e', 'f.g', 'h']
17
+ */
18
+ declare function toPath(deepKey: string): string[];
19
+
20
+ export { toPath };
@@ -70,7 +70,7 @@ function pascalCase(str) {
70
70
  }
71
71
 
72
72
  function trimStart(str, chars) {
73
- if (chars == null) {
73
+ if (chars === undefined) {
74
74
  return str.trimStart();
75
75
  }
76
76
  let startIndex = 0;
@@ -91,7 +91,7 @@ function trimStart(str, chars) {
91
91
  }
92
92
 
93
93
  function trimEnd(str, chars) {
94
- if (chars == null) {
94
+ if (chars === undefined) {
95
95
  return str.trimEnd();
96
96
  }
97
97
  let endIndex = str.length;
@@ -112,7 +112,7 @@ function trimEnd(str, chars) {
112
112
  }
113
113
 
114
114
  function trim(str, chars) {
115
- if (chars == null) {
115
+ if (chars === undefined) {
116
116
  return str.trim();
117
117
  }
118
118
  return trimStart(trimEnd(str, chars), chars);
@@ -2,7 +2,7 @@ import { trimStart } from './trimStart.mjs';
2
2
  import { trimEnd } from './trimEnd.mjs';
3
3
 
4
4
  function trim(str, chars) {
5
- if (chars == null) {
5
+ if (chars === undefined) {
6
6
  return str.trim();
7
7
  }
8
8
  return trimStart(trimEnd(str, chars), chars);
@@ -1,5 +1,5 @@
1
1
  function trimEnd(str, chars) {
2
- if (chars == null) {
2
+ if (chars === undefined) {
3
3
  return str.trimEnd();
4
4
  }
5
5
  let endIndex = str.length;
@@ -1,5 +1,5 @@
1
1
  function trimStart(str, chars) {
2
- if (chars == null) {
2
+ if (chars === undefined) {
3
3
  return str.trimStart();
4
4
  }
5
5
  let startIndex = 0;
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.18.0-dev.596+6e071573",
4
+ "version": "1.18.0-dev.600+f2f4b8ec",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {
File without changes
File without changes
File without changes
File without changes