@ptolemy2002/list-object-utils 2.1.1 → 3.0.0

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.
package/README.md CHANGED
@@ -160,27 +160,6 @@ A simple implementation of `JSON.stringify` that converts undefined values to `n
160
160
  #### Returns
161
161
  `string` - The string representation of the object.
162
162
 
163
- ### listClone<T>
164
- #### Description
165
- Clones a list. Uses recursion to clone nested lists and the `objectClone` function to clone nested objects.
166
-
167
- #### Parameters
168
- - `list` (`T[]`): The list to be cloned.
169
- - `maxDepth` (`number`): The maximum depth to which the list should be cloned. Default is `Infinity`.
170
- - `currentDepth` (`number`): The current depth of the list. This should not be specified on the initial call, and is only used for recursion purposes. Default is `0`.
171
-
172
- #### Returns
173
- `T[]` - The cloned list.
174
-
175
- ### objectClone<T>
176
- #### Description
177
- Clones an object. Uses recursion to clone nested objects and the `listClone` function to clone nested lists.
178
-
179
- #### Parameters
180
- - `obj` (`T`): The object to be cloned.
181
- - `maxDepth` (`number`): The maximum depth to which the object should be cloned. Default is `Infinity`.
182
- - `currentDepth` (`number`): The current depth of the object. This should not be specified on the initial call, and is only used for recursion purposes. Default is `0`.
183
-
184
163
  #### Returns
185
164
  `T` - The cloned object.
186
165
 
package/dist/index.d.ts CHANGED
@@ -17,5 +17,3 @@ export declare function flattenKeys<T>(obj: T, prefix?: string): Record<string,
17
17
  export type SortCallback = (a: number, b: number) => number;
18
18
  export declare function sortWithIndeces<T>(toSort: T[], sort?: SortCallback, descending?: boolean): T[];
19
19
  export declare function objectToString(obj: Object): string;
20
- export declare function listClone<T>(list: T[], maxDepth?: number, depth?: number): T[];
21
- export declare function objectClone<T>(obj: T, maxDepth?: number, depth?: number): T;
package/dist/index.js CHANGED
@@ -1,7 +1,4 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.listsEqual = listsEqual;
7
4
  exports.objectsEqual = objectsEqual;
@@ -15,9 +12,6 @@ exports.objectDifference = objectDifference;
15
12
  exports.flattenKeys = flattenKeys;
16
13
  exports.sortWithIndeces = sortWithIndeces;
17
14
  exports.objectToString = objectToString;
18
- exports.listClone = listClone;
19
- exports.objectClone = objectClone;
20
- const is_callable_1 = __importDefault(require("is-callable"));
21
15
  function listsEqual(a, b) {
22
16
  if (a === b)
23
17
  return true;
@@ -190,36 +184,3 @@ function sortWithIndeces(toSort, sort = () => 0, descending = false) {
190
184
  function objectToString(obj) {
191
185
  return JSON.stringify(obj, (_, v) => v === undefined ? null : v);
192
186
  }
193
- function listClone(list, maxDepth = Infinity, depth = 0) {
194
- if (depth >= maxDepth)
195
- return list;
196
- return list.map((item) => {
197
- if (Array.isArray(item))
198
- return listClone(item, maxDepth, depth + 1);
199
- if (typeof item === "object")
200
- return objectClone(item, maxDepth, depth + 1);
201
- return item;
202
- });
203
- }
204
- function objectClone(obj, maxDepth = Infinity, depth = 0) {
205
- if (depth >= maxDepth)
206
- return obj;
207
- if (obj instanceof Date)
208
- return new Date(obj.getTime());
209
- return Object.keys(obj).reduce((acc, key) => {
210
- const value = obj[key];
211
- if (Array.isArray(value)) {
212
- acc[key] = listClone(value, maxDepth, depth + 1);
213
- }
214
- else if ((0, is_callable_1.default)(value.clone)) {
215
- acc[key] = value.clone();
216
- }
217
- else if (typeof value === "object") {
218
- acc[key] = objectClone(value, maxDepth, depth + 1);
219
- }
220
- else {
221
- acc[key] = value;
222
- }
223
- return acc;
224
- }, {});
225
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ptolemy2002/list-object-utils",
3
- "version": "2.1.1",
3
+ "version": "3.0.0",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",