es-toolkit 1.9.0-dev.194 → 1.9.0-dev.196

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,27 @@
1
+ // src/object/clone.ts
2
+ function clone(obj) {
3
+ if (isPrimitive(obj)) {
4
+ return obj;
5
+ }
6
+ if (Array.isArray(obj)) {
7
+ return obj.slice();
8
+ }
9
+ if (obj instanceof Date) {
10
+ return new Date(obj.getTime());
11
+ }
12
+ if (obj instanceof RegExp) {
13
+ return new RegExp(obj.source, obj.flags);
14
+ }
15
+ if (typeof obj === "object") {
16
+ return Object.assign({}, obj);
17
+ }
18
+ return obj;
19
+ }
20
+ function isPrimitive(value) {
21
+ return value == null || typeof value !== "object" && typeof value !== "function";
22
+ }
23
+
24
+ export {
25
+ clone
26
+ };
27
+ //# sourceMappingURL=chunk-NY33CVEY.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/object/clone.ts"],"sourcesContent":["/**\n * Creates a shallow clone of the given object.\n *\n * @template T - The type of the object.\n * @param {T} obj - The object to clone.\n * @returns {T} - A shallow clone of the given object.\n *\n * @example\n * // Clone a primitive values\n * const num = 29;\n * const clonedNum = clone(num);\n * console.log(clonedNum); // 29\n * console.log(clonedNum === num) ; // true\n *\n * @example\n * // Clone an array\n * const arr = [1, 2, 3];\n * const clonedArr = clone(arr);\n * console.log(clonedArr); // [1, 2, 3]\n * console.log(clonedArr === arr); // false\n *\n * @example\n * // Clone an object\n * const obj = { a: 1, b: 'es-toolkit', c: [1, 2, 3] };\n * const clonedObj = clone(obj);\n * console.log(clonedObj); // { a: 1, b: 'es-toolkit', c: [1, 2, 3] }\n * console.log(clonedObj === obj); // false\n */\nexport function clone<T>(obj: T): T {\n if (isPrimitive(obj)) {\n return obj;\n }\n if (Array.isArray(obj)) {\n return obj.slice() as T;\n }\n if (obj instanceof Date) {\n return new Date(obj.getTime()) as T;\n }\n if (obj instanceof RegExp) {\n return new RegExp(obj.source, obj.flags) as T;\n }\n if (typeof obj === 'object') {\n return Object.assign({}, obj) as T;\n }\n return obj;\n}\n\ntype Primitive = null | undefined | string | number | boolean | symbol | bigint;\n\nfunction isPrimitive(value: unknown): value is Primitive {\n return value == null || (typeof value !== 'object' && typeof value !== 'function');\n}\n"],"mappings":";AA4BO,SAAS,MAAS,KAAW;AAClC,MAAI,YAAY,GAAG,GAAG;AACpB,WAAO;AAAA,EACT;AACA,MAAI,MAAM,QAAQ,GAAG,GAAG;AACtB,WAAO,IAAI,MAAM;AAAA,EACnB;AACA,MAAI,eAAe,MAAM;AACvB,WAAO,IAAI,KAAK,IAAI,QAAQ,CAAC;AAAA,EAC/B;AACA,MAAI,eAAe,QAAQ;AACzB,WAAO,IAAI,OAAO,IAAI,QAAQ,IAAI,KAAK;AAAA,EACzC;AACA,MAAI,OAAO,QAAQ,UAAU;AAC3B,WAAO,OAAO,OAAO,CAAC,GAAG,GAAG;AAAA,EAC9B;AACA,SAAO;AACT;AAIA,SAAS,YAAY,OAAoC;AACvD,SAAO,SAAS,QAAS,OAAO,UAAU,YAAY,OAAO,UAAU;AACzE;","names":[]}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=chunk-OSOLEQLZ.mjs.map
package/dist/index.d.mts CHANGED
@@ -67,6 +67,7 @@ export { omitBy } from './object/omitBy.mjs';
67
67
  export { pick } from './object/pick.mjs';
68
68
  export { pickBy } from './object/pickBy.mjs';
69
69
  export { invert } from './object/invert.mjs';
70
+ export { clone } from './object/clone.mjs';
70
71
  export { isNil } from './predicate/isNil.mjs';
71
72
  export { isNotNil } from './predicate/isNotNil.mjs';
72
73
  export { isNull } from './predicate/isNull.mjs';
package/dist/index.d.ts CHANGED
@@ -67,6 +67,7 @@ export { omitBy } from './object/omitBy.js';
67
67
  export { pick } from './object/pick.js';
68
68
  export { pickBy } from './object/pickBy.js';
69
69
  export { invert } from './object/invert.js';
70
+ export { clone } from './object/clone.js';
70
71
  export { isNil } from './predicate/isNil.js';
71
72
  export { isNotNil } from './predicate/isNotNil.js';
72
73
  export { isNull } from './predicate/isNull.js';
package/dist/index.js CHANGED
@@ -3619,15 +3619,15 @@ var require_lodash = __commonJS({
3619
3619
  function wrapperPlant(value) {
3620
3620
  var result2, parent2 = this;
3621
3621
  while (parent2 instanceof baseLodash) {
3622
- var clone2 = wrapperClone(parent2);
3623
- clone2.__index__ = 0;
3624
- clone2.__values__ = undefined2;
3622
+ var clone3 = wrapperClone(parent2);
3623
+ clone3.__index__ = 0;
3624
+ clone3.__values__ = undefined2;
3625
3625
  if (result2) {
3626
- previous.__wrapped__ = clone2;
3626
+ previous.__wrapped__ = clone3;
3627
3627
  } else {
3628
- result2 = clone2;
3628
+ result2 = clone3;
3629
3629
  }
3630
- var previous = clone2;
3630
+ var previous = clone3;
3631
3631
  parent2 = parent2.__wrapped__;
3632
3632
  }
3633
3633
  previous.__wrapped__ = value;
@@ -4062,7 +4062,7 @@ var require_lodash = __commonJS({
4062
4062
  var value = arguments[0];
4063
4063
  return isArray(value) ? value : [value];
4064
4064
  }
4065
- function clone(value) {
4065
+ function clone2(value) {
4066
4066
  return baseClone(value, CLONE_SYMBOLS_FLAG);
4067
4067
  }
4068
4068
  function cloneWith(value, customizer) {
@@ -5194,7 +5194,7 @@ var require_lodash = __commonJS({
5194
5194
  lodash.capitalize = capitalize3;
5195
5195
  lodash.ceil = ceil;
5196
5196
  lodash.clamp = clamp2;
5197
- lodash.clone = clone;
5197
+ lodash.clone = clone2;
5198
5198
  lodash.cloneDeep = cloneDeep;
5199
5199
  lodash.cloneDeepWith = cloneDeepWith;
5200
5200
  lodash.cloneWith = cloneWith;
@@ -5533,6 +5533,7 @@ __export(src_exports, {
5533
5533
  capitalize: () => capitalize2,
5534
5534
  chunk: () => chunk,
5535
5535
  clamp: () => clamp,
5536
+ clone: () => clone,
5536
5537
  compact: () => compact,
5537
5538
  countBy: () => countBy,
5538
5539
  debounce: () => debounce,
@@ -6311,6 +6312,29 @@ function invert(obj) {
6311
6312
  return result;
6312
6313
  }
6313
6314
 
6315
+ // src/object/clone.ts
6316
+ function clone(obj) {
6317
+ if (isPrimitive(obj)) {
6318
+ return obj;
6319
+ }
6320
+ if (Array.isArray(obj)) {
6321
+ return obj.slice();
6322
+ }
6323
+ if (obj instanceof Date) {
6324
+ return new Date(obj.getTime());
6325
+ }
6326
+ if (obj instanceof RegExp) {
6327
+ return new RegExp(obj.source, obj.flags);
6328
+ }
6329
+ if (typeof obj === "object") {
6330
+ return Object.assign({}, obj);
6331
+ }
6332
+ return obj;
6333
+ }
6334
+ function isPrimitive(value) {
6335
+ return value == null || typeof value !== "object" && typeof value !== "function";
6336
+ }
6337
+
6314
6338
  // src/predicate/isNil.ts
6315
6339
  function isNil(x) {
6316
6340
  return x == null;
@@ -6398,6 +6422,7 @@ var capitalize2 = (str) => {
6398
6422
  capitalize,
6399
6423
  chunk,
6400
6424
  clamp,
6425
+ clone,
6401
6426
  compact,
6402
6427
  countBy,
6403
6428
  debounce,