es-toolkit 1.18.0-dev.601 → 1.18.0-dev.602

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.
@@ -1,3 +1,4 @@
1
+ import { isDeepKey } from '../_internal/isDeepKey.mjs';
1
2
  import { toKey } from '../_internal/toKey.mjs';
2
3
  import { toPath } from '../util/toPath.mjs';
3
4
  import { get } from './get.mjs';
@@ -6,18 +7,62 @@ function unset(obj, path) {
6
7
  if (obj == null) {
7
8
  return true;
8
9
  }
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)) {
10
+ switch (typeof path) {
11
+ case 'symbol':
12
+ case 'number':
13
+ case 'object': {
14
+ if (Array.isArray(path)) {
15
+ return unsetWithPath(obj, path);
16
+ }
17
+ if (typeof path === 'number') {
18
+ path = toKey(path);
19
+ }
20
+ else if (typeof path === 'object') {
21
+ if (Object.is(path?.valueOf(), -0)) {
22
+ path = '-0';
23
+ }
24
+ else {
25
+ path = String(path);
26
+ }
27
+ }
28
+ if (obj?.[path] === undefined) {
29
+ return true;
30
+ }
31
+ try {
32
+ delete obj[path];
33
+ return true;
34
+ }
35
+ catch {
36
+ return false;
37
+ }
38
+ }
39
+ case 'string': {
40
+ if (obj?.[path] === undefined && isDeepKey(path)) {
41
+ return unsetWithPath(obj, toPath(path));
42
+ }
43
+ try {
44
+ delete obj[path];
45
+ return true;
46
+ }
47
+ catch {
48
+ return false;
49
+ }
50
+ }
51
+ }
52
+ }
53
+ function unsetWithPath(obj, path) {
54
+ const parent = get(obj, path.slice(0, -1), obj);
55
+ const lastKey = path[path.length - 1];
56
+ if (parent?.[lastKey] === undefined) {
57
+ return true;
58
+ }
59
+ try {
60
+ delete parent[lastKey];
13
61
  return true;
14
62
  }
15
- const isDeletable = Object.getOwnPropertyDescriptor(parent, lastKey)?.configurable;
16
- if (!isDeletable) {
63
+ catch {
17
64
  return false;
18
65
  }
19
- delete parent[lastKey];
20
- return true;
21
66
  }
22
67
 
23
68
  export { unset };
@@ -5,7 +5,18 @@ import { has } from '../object/has.mjs';
5
5
  import { isMatch } from './isMatch.mjs';
6
6
 
7
7
  function matchesProperty(property, source) {
8
- property = Array.isArray(property) ? property : toKey(property);
8
+ switch (typeof property) {
9
+ case 'object': {
10
+ if (Object.is(property?.valueOf(), -0)) {
11
+ property = '-0';
12
+ }
13
+ break;
14
+ }
15
+ case 'number': {
16
+ property = toKey(property);
17
+ break;
18
+ }
19
+ }
9
20
  source = cloneDeep(source);
10
21
  return function (target) {
11
22
  const result = get(target, property);
@@ -3,6 +3,7 @@
3
3
  *
4
4
  * @param {string} str - The string from which leading and trailing characters will be trimmed.
5
5
  * @param {string | string[]} chars - The character(s) to remove from the end of the string. Defaults to `" "`.
6
+ * @param guard
6
7
  * @returns {string} - The resulting string after the specified leading and trailing characters have been removed.
7
8
  *
8
9
  * @example
@@ -3,6 +3,7 @@
3
3
  *
4
4
  * @param {string} str - The string from which leading and trailing characters will be trimmed.
5
5
  * @param {string | string[]} chars - The character(s) to remove from the end of the string. Defaults to `" "`.
6
+ * @param guard
6
7
  * @returns {string} - The resulting string after the specified leading and trailing characters have been removed.
7
8
  *
8
9
  * @example
@@ -3,6 +3,7 @@
3
3
  *
4
4
  * @param {string} str - The string from which trailing characters will be trimmed.
5
5
  * @param {string | string[]} chars - The character(s) to remove from the end of the string. Defaults to `" "`.
6
+ * @param guard
6
7
  * @returns {string} - The resulting string after the specified trailing character has been removed.
7
8
  *
8
9
  * @example
@@ -3,6 +3,7 @@
3
3
  *
4
4
  * @param {string} str - The string from which trailing characters will be trimmed.
5
5
  * @param {string | string[]} chars - The character(s) to remove from the end of the string. Defaults to `" "`.
6
+ * @param guard
6
7
  * @returns {string} - The resulting string after the specified trailing character has been removed.
7
8
  *
8
9
  * @example
@@ -3,6 +3,7 @@
3
3
  *
4
4
  * @param {string} str - The string from which leading characters will be trimmed.
5
5
  * @param {string | string[]} chars - The character(s) to remove from the end of the string. Defaults to `" "`.
6
+ * @param guard
6
7
  * @returns {string} - The resulting string after the specified leading character has been removed.
7
8
  *
8
9
  * @example
@@ -3,6 +3,7 @@
3
3
  *
4
4
  * @param {string} str - The string from which leading characters will be trimmed.
5
5
  * @param {string | string[]} chars - The character(s) to remove from the end of the string. Defaults to `" "`.
6
+ * @param guard
6
7
  * @returns {string} - The resulting string after the specified leading character has been removed.
7
8
  *
8
9
  * @example
@@ -1,3 +1,4 @@
1
+ const DOTS_KEY = /^[\w.]+$/g;
1
2
  const ESCAPE_REGEXP = /\\(\\)?/g;
2
3
  const PROPERTY_REGEXP = RegExp('[^.[\\]]+' +
3
4
  '|' +
@@ -9,13 +10,15 @@ const PROPERTY_REGEXP = RegExp('[^.[\\]]+' +
9
10
  '|' +
10
11
  '(?=(?:\\.|\\[\\])(?:\\.|\\[\\]|$))', 'g');
11
12
  function toPath(deepKey) {
13
+ if (DOTS_KEY.test(deepKey)) {
14
+ return deepKey.split('.');
15
+ }
12
16
  const result = [];
13
17
  if (deepKey[0] === '.') {
14
18
  result.push('');
15
19
  }
16
- let match;
17
- let lastIndex = 0;
18
- while ((match = PROPERTY_REGEXP.exec(deepKey)) !== null) {
20
+ const matches = deepKey.matchAll(PROPERTY_REGEXP);
21
+ for (const match of matches) {
19
22
  let key = match[0];
20
23
  const expr = match[1];
21
24
  const quote = match[2];
@@ -27,12 +30,6 @@ function toPath(deepKey) {
27
30
  key = expr;
28
31
  }
29
32
  result.push(key);
30
- if (PROPERTY_REGEXP.lastIndex === lastIndex) {
31
- PROPERTY_REGEXP.lastIndex++;
32
- }
33
- else {
34
- lastIndex = PROPERTY_REGEXP.lastIndex;
35
- }
36
33
  }
37
34
  return result;
38
35
  }
package/dist/index.js CHANGED
@@ -10,8 +10,8 @@ const function_index = require('./function/index.js');
10
10
  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
- const toMerged = require('./_chunk/toMerged-LBvzaK.js');
14
13
  const object_index = require('./object/index.js');
14
+ const toMerged = require('./_chunk/toMerged-Bzkqyz.js');
15
15
  const isWeakSet = require('./_chunk/isWeakSet-E_VMwB.js');
16
16
  const isPlainObject = require('./_chunk/isPlainObject-BIekvL.js');
17
17
  const predicate_index = require('./predicate/index.js');
@@ -105,6 +105,9 @@ exports.sumBy = range.sumBy;
105
105
  exports.random = randomInt.random;
106
106
  exports.randomInt = randomInt.randomInt;
107
107
  exports.round = math_index.round;
108
+ exports.mergeWith = object_index.mergeWith;
109
+ exports.omit = object_index.omit;
110
+ exports.pick = object_index.pick;
108
111
  exports.clone = toMerged.clone;
109
112
  exports.cloneDeep = toMerged.cloneDeep;
110
113
  exports.flattenObject = toMerged.flattenObject;
@@ -112,12 +115,9 @@ exports.invert = toMerged.invert;
112
115
  exports.mapKeys = toMerged.mapKeys;
113
116
  exports.mapValues = toMerged.mapValues;
114
117
  exports.merge = toMerged.merge;
115
- exports.omit = toMerged.omit;
116
118
  exports.omitBy = toMerged.omitBy;
117
119
  exports.pickBy = toMerged.pickBy;
118
120
  exports.toMerged = toMerged.toMerged;
119
- exports.mergeWith = object_index.mergeWith;
120
- exports.pick = object_index.pick;
121
121
  exports.isDate = isWeakSet.isDate;
122
122
  exports.isEqual = isWeakSet.isEqual;
123
123
  exports.isFunction = isWeakSet.isFunction;
@@ -2,7 +2,15 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const toMerged = require('../_chunk/toMerged-LBvzaK.js');
5
+ const toMerged = require('../_chunk/toMerged-Bzkqyz.js');
6
+
7
+ function omit(obj, keys) {
8
+ const result = { ...obj };
9
+ for (const key of keys) {
10
+ delete result[key];
11
+ }
12
+ return result;
13
+ }
6
14
 
7
15
  function pick(obj, keys) {
8
16
  const result = {};
@@ -42,9 +50,9 @@ exports.invert = toMerged.invert;
42
50
  exports.mapKeys = toMerged.mapKeys;
43
51
  exports.mapValues = toMerged.mapValues;
44
52
  exports.merge = toMerged.merge;
45
- exports.omit = toMerged.omit;
46
53
  exports.omitBy = toMerged.omitBy;
47
54
  exports.pickBy = toMerged.pickBy;
48
55
  exports.toMerged = toMerged.toMerged;
49
56
  exports.mergeWith = mergeWith;
57
+ exports.omit = omit;
50
58
  exports.pick = pick;
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.601+30f8633f",
4
+ "version": "1.18.0-dev.602+a010748f",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {