@helpers4/object 2.0.0-alpha.10 → 2.0.0-alpha.11
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 +3 -0
- package/lib/index.d.ts +51 -1
- package/lib/index.js +87 -2
- package/lib/index.js.map +1 -1
- package/meta/api.json +145 -1
- package/meta/examples.json +45 -0
- package/meta/licenses.json +1 -8
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -12,10 +12,13 @@ A set of helpers for working with URLs.
|
|
|
12
12
|
[https://helpers4.dev/typescript/categories/object/](https://helpers4.dev/typescript/categories/object/)
|
|
13
13
|
|
|
14
14
|
<!-- AUTOMATIC-METHODS -->
|
|
15
|
+
- compact
|
|
15
16
|
- deepClone
|
|
16
17
|
- deepCompare
|
|
17
18
|
- deepMerge
|
|
18
19
|
- get
|
|
20
|
+
- omit
|
|
21
|
+
- pick
|
|
19
22
|
- removeUndefinedNull
|
|
20
23
|
- set
|
|
21
24
|
- shallowEquals
|
package/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of helpers4.
|
|
3
|
+
* Copyright (C) 2025 baxyz
|
|
4
|
+
* SPDX-License-Identifier: LGPL-3.0-or-later
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Removes all entries with falsy values (`false`, `null`, `undefined`, `0`, `""`, `NaN`) from an object.
|
|
8
|
+
* @param obj - The source object
|
|
9
|
+
* @returns A new object containing only entries with truthy values
|
|
10
|
+
* @example
|
|
11
|
+
* compact({ a: 1, b: null, c: '', d: 0, e: 'hello' })
|
|
12
|
+
* // => { a: 1, e: 'hello' }
|
|
13
|
+
* @since 2.0.0
|
|
14
|
+
*/
|
|
15
|
+
declare function compact<T extends Record<string, unknown>>(obj: T): Partial<T>;
|
|
16
|
+
|
|
1
17
|
/**
|
|
2
18
|
* This file is part of helpers4.
|
|
3
19
|
* Copyright (C) 2025 baxyz
|
|
@@ -62,6 +78,40 @@ declare function deepMerge<T extends Record<string, any>>(target: T, ...sources:
|
|
|
62
78
|
*/
|
|
63
79
|
declare function get<T = any>(obj: any, path: string, defaultValue?: T): T | undefined;
|
|
64
80
|
|
|
81
|
+
/**
|
|
82
|
+
* This file is part of helpers4.
|
|
83
|
+
* Copyright (C) 2025 baxyz
|
|
84
|
+
* SPDX-License-Identifier: LGPL-3.0-or-later
|
|
85
|
+
*/
|
|
86
|
+
/**
|
|
87
|
+
* Creates a new object without the specified keys.
|
|
88
|
+
* @param obj - The source object
|
|
89
|
+
* @param keys - The keys to omit
|
|
90
|
+
* @returns A new object without the omitted keys
|
|
91
|
+
* @example
|
|
92
|
+
* omit({ a: 1, b: 2, c: 3 }, ['b'])
|
|
93
|
+
* // => { a: 1, c: 3 }
|
|
94
|
+
* @since 2.0.0
|
|
95
|
+
*/
|
|
96
|
+
declare function omit<T extends Record<string, unknown>, K extends keyof T>(obj: T, keys: readonly K[]): Omit<T, K>;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* This file is part of helpers4.
|
|
100
|
+
* Copyright (C) 2025 baxyz
|
|
101
|
+
* SPDX-License-Identifier: LGPL-3.0-or-later
|
|
102
|
+
*/
|
|
103
|
+
/**
|
|
104
|
+
* Creates a new object with only the specified keys.
|
|
105
|
+
* @param obj - The source object
|
|
106
|
+
* @param keys - The keys to pick
|
|
107
|
+
* @returns A new object with only the picked keys
|
|
108
|
+
* @example
|
|
109
|
+
* pick({ a: 1, b: 2, c: 3 }, ['a', 'c'])
|
|
110
|
+
* // => { a: 1, c: 3 }
|
|
111
|
+
* @since 2.0.0
|
|
112
|
+
*/
|
|
113
|
+
declare function pick<T extends Record<string, unknown>, K extends keyof T>(obj: T, keys: readonly K[]): Pick<T, K>;
|
|
114
|
+
|
|
65
115
|
/**
|
|
66
116
|
* This file is part of helpers4.
|
|
67
117
|
* Copyright (C) 2025 baxyz
|
|
@@ -123,5 +173,5 @@ declare function set(obj: Record<string, any>, path: string, value: any): Record
|
|
|
123
173
|
*/
|
|
124
174
|
declare function shallowEquals(objA: unknown, objB: unknown): boolean;
|
|
125
175
|
|
|
126
|
-
export { deepClone, deepCompare, deepMerge, get, removeUndefinedNull, set, shallowEquals };
|
|
176
|
+
export { compact, deepClone, deepCompare, deepMerge, get, omit, pick, removeUndefinedNull, set, shallowEquals };
|
|
127
177
|
export type { DeepCompareResult };
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,24 @@
|
|
|
1
|
-
|
|
1
|
+
//#region helpers/object/compact.ts
|
|
2
|
+
/**
|
|
3
|
+
* This file is part of helpers4.
|
|
4
|
+
* Copyright (C) 2025 baxyz
|
|
5
|
+
* SPDX-License-Identifier: LGPL-3.0-or-later
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Removes all entries with falsy values (`false`, `null`, `undefined`, `0`, `""`, `NaN`) from an object.
|
|
9
|
+
* @param obj - The source object
|
|
10
|
+
* @returns A new object containing only entries with truthy values
|
|
11
|
+
* @example
|
|
12
|
+
* compact({ a: 1, b: null, c: '', d: 0, e: 'hello' })
|
|
13
|
+
* // => { a: 1, e: 'hello' }
|
|
14
|
+
* @since 2.0.0
|
|
15
|
+
*/
|
|
16
|
+
function compact(obj) {
|
|
17
|
+
const result = {};
|
|
18
|
+
for (const key of Object.keys(obj)) if (obj[key]) result[key] = obj[key];
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
2
22
|
//#region helpers/object/deepClone.ts
|
|
3
23
|
/**
|
|
4
24
|
* This file is part of helpers4.
|
|
@@ -204,6 +224,71 @@ function get(obj, path, defaultValue) {
|
|
|
204
224
|
return result !== void 0 ? result : defaultValue;
|
|
205
225
|
}
|
|
206
226
|
//#endregion
|
|
227
|
+
//#region helpers/object/omit.ts
|
|
228
|
+
/**
|
|
229
|
+
* This file is part of helpers4.
|
|
230
|
+
* Copyright (C) 2025 baxyz
|
|
231
|
+
* SPDX-License-Identifier: LGPL-3.0-or-later
|
|
232
|
+
*/
|
|
233
|
+
/**
|
|
234
|
+
* Creates a new object without the specified keys.
|
|
235
|
+
* @param obj - The source object
|
|
236
|
+
* @param keys - The keys to omit
|
|
237
|
+
* @returns A new object without the omitted keys
|
|
238
|
+
* @example
|
|
239
|
+
* omit({ a: 1, b: 2, c: 3 }, ['b'])
|
|
240
|
+
* // => { a: 1, c: 3 }
|
|
241
|
+
* @since 2.0.0
|
|
242
|
+
*/
|
|
243
|
+
function omit(obj, keys) {
|
|
244
|
+
const result = { ...obj };
|
|
245
|
+
for (const key of keys) delete result[key];
|
|
246
|
+
return result;
|
|
247
|
+
}
|
|
248
|
+
//#endregion
|
|
249
|
+
//#region helpers/object/pick.ts
|
|
250
|
+
/**
|
|
251
|
+
* This file is part of helpers4.
|
|
252
|
+
* Copyright (C) 2025 baxyz
|
|
253
|
+
* SPDX-License-Identifier: LGPL-3.0-or-later
|
|
254
|
+
*/
|
|
255
|
+
/**
|
|
256
|
+
* Creates a new object with only the specified keys.
|
|
257
|
+
* @param obj - The source object
|
|
258
|
+
* @param keys - The keys to pick
|
|
259
|
+
* @returns A new object with only the picked keys
|
|
260
|
+
* @example
|
|
261
|
+
* pick({ a: 1, b: 2, c: 3 }, ['a', 'c'])
|
|
262
|
+
* // => { a: 1, c: 3 }
|
|
263
|
+
* @since 2.0.0
|
|
264
|
+
*/
|
|
265
|
+
function pick(obj, keys) {
|
|
266
|
+
const result = {};
|
|
267
|
+
for (const key of keys) if (Object.prototype.hasOwnProperty.call(obj, key)) result[key] = obj[key];
|
|
268
|
+
return result;
|
|
269
|
+
}
|
|
270
|
+
//#endregion
|
|
271
|
+
//#region helpers/type/isNullish.ts
|
|
272
|
+
/**
|
|
273
|
+
* This file is part of helpers4.
|
|
274
|
+
* Copyright (C) 2025 baxyz
|
|
275
|
+
* SPDX-License-Identifier: LGPL-3.0-or-later
|
|
276
|
+
*/
|
|
277
|
+
/**
|
|
278
|
+
* Checks if a value is null or undefined (nullish).
|
|
279
|
+
* @param value - The value to check
|
|
280
|
+
* @returns True if value is null or undefined
|
|
281
|
+
* @example
|
|
282
|
+
* isNullish(null) // => true
|
|
283
|
+
* isNullish(undefined) // => true
|
|
284
|
+
* isNullish(0) // => false
|
|
285
|
+
* isNullish('') // => false
|
|
286
|
+
* @since 2.0.0
|
|
287
|
+
*/
|
|
288
|
+
function isNullish(value) {
|
|
289
|
+
return value === null || value === void 0;
|
|
290
|
+
}
|
|
291
|
+
//#endregion
|
|
207
292
|
//#region helpers/object/removeUndefinedNull.ts
|
|
208
293
|
/**
|
|
209
294
|
* This file is part of helpers4.
|
|
@@ -275,6 +360,6 @@ function shallowEquals(objA, objB) {
|
|
|
275
360
|
}
|
|
276
361
|
}
|
|
277
362
|
//#endregion
|
|
278
|
-
export { deepClone, deepCompare, deepMerge, get, removeUndefinedNull, set, shallowEquals };
|
|
363
|
+
export { compact, deepClone, deepCompare, deepMerge, get, omit, pick, removeUndefinedNull, set, shallowEquals };
|
|
279
364
|
|
|
280
365
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../helpers/object/deepClone.ts","../../../helpers/array/shallowEquals.ts","../../../helpers/date/compare.ts","../../../helpers/type/isSpecialObject.ts","../../../helpers/object/deepCompare.ts","../../../helpers/object/deepMerge.ts","../../../helpers/object/get.ts","../../../helpers/object/removeUndefinedNull.ts","../../../helpers/object/set.ts","../../../helpers/object/shallowEquals.ts"],"sourcesContent":["/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Creates a deep copy of an object or array\n * @param obj - The object to clone\n * @returns Deep cloned object\n * @since 1.9.0\n */\nexport function deepClone<T>(obj: T): T {\n if (obj === null || typeof obj !== \"object\") {\n return obj;\n }\n\n if (obj instanceof Date) {\n return new Date(obj.getTime()) as T;\n }\n\n if (Array.isArray(obj)) {\n return obj.map(item => deepClone(item)) as T;\n }\n\n const cloned = {} as T;\n for (const key in obj) {\n if (obj.hasOwnProperty(key)) {\n cloned[key] = deepClone(obj[key]);\n }\n }\n\n return cloned;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Quick comparison of two arrays using JSON.stringify.\n * This is a fast but simple comparison that may not work for all edge cases.\n *\n * @param arrA - First array to compare\n * @param arrB - Second array to compare\n * @returns `true` if arrays are identical according to JSON.stringify, `false` otherwise\n * @since 2.0.0\n */\nexport function shallowEquals<T>(arrA: T[], arrB: T[]): boolean {\n try {\n return JSON.stringify(arrA) === JSON.stringify(arrB);\n } catch {\n // If JSON.stringify fails (e.g., circular references), fall back to reference equality\n return arrA === arrB;\n }\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Options for date comparison\n * @since 2.0.0\n */\nexport interface DateCompareOptions {\n /** \n * Comparison precision\n * - 'milliseconds': Compare all including milliseconds (default)\n * - 'seconds': Ignore milliseconds, compare to the second\n * - 'minutes': Ignore seconds and milliseconds, compare to the minute\n * - 'hours': Ignore minutes, seconds and milliseconds, compare to the hour\n * - 'days': Compare only the date part (ignore time completely)\n */\n precision?: 'milliseconds' | 'seconds' | 'minutes' | 'hours' | 'days';\n}\n\n/**\n * Comparison of two dates.\n * \n * @param dateA - First date to compare\n * @param dateB - Second date to compare\n * @param options - Comparison options\n * @returns `true` if dates are identical according to the specified precision, `false` otherwise\n * @since 2.0.0\n */\nexport function compare(dateA: Date, dateB: Date, options: DateCompareOptions = {}): boolean {\n const { precision = 'milliseconds' } = options;\n\n if (!(dateA instanceof Date) || !(dateB instanceof Date)) {\n return dateA === dateB;\n }\n\n // Handle invalid dates\n if (isNaN(dateA.getTime()) || isNaN(dateB.getTime())) {\n return isNaN(dateA.getTime()) && isNaN(dateB.getTime());\n }\n\n switch (precision) {\n case 'days':\n return dateA.toDateString() === dateB.toDateString();\n\n case 'hours':\n const hoursA = Math.floor(dateA.getTime() / (1000 * 60 * 60));\n const hoursB = Math.floor(dateB.getTime() / (1000 * 60 * 60));\n return hoursA === hoursB;\n\n case 'minutes':\n const minutesA = Math.floor(dateA.getTime() / (1000 * 60));\n const minutesB = Math.floor(dateB.getTime() / (1000 * 60));\n return minutesA === minutesB;\n\n case 'seconds':\n const secondsA = Math.floor(dateA.getTime() / 1000);\n const secondsB = Math.floor(dateB.getTime() / 1000);\n return secondsA === secondsB;\n\n case 'milliseconds':\n default:\n return dateA.getTime() === dateB.getTime();\n }\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Determines if a value is a special object that should not have its properties compared deeply.\n * Special objects include: Date, Function, Promise, Observable, RegExp, Error, Map, Set, WeakMap, WeakSet, etc.\n * \n * @param value - The value to check\n * @returns `true` if the value is a special object, `false` otherwise\n * @since 2.0.0\n */\nexport function isSpecialObject(value: unknown): boolean {\n if (value === null || value === undefined) {\n return false;\n }\n\n // Functions are special objects\n if (typeof value === 'function') {\n return true;\n }\n\n // Non-objects are not special\n if (typeof value !== 'object') {\n return false;\n }\n\n // Arrays are not considered special objects for our purposes\n if (Array.isArray(value)) {\n return false;\n }\n\n // Check for built-in special objects\n if (\n value instanceof Date ||\n value instanceof Promise ||\n value instanceof RegExp ||\n value instanceof Error ||\n value instanceof Map ||\n value instanceof Set ||\n value instanceof WeakMap ||\n value instanceof WeakSet ||\n value instanceof ArrayBuffer ||\n value instanceof DataView\n ) {\n return true;\n }\n\n // Check for Observable (RxJS or similar)\n if (value.constructor?.name === 'Observable') {\n return true;\n }\n\n // Check for DOM elements (if in browser environment)\n if (typeof HTMLElement !== 'undefined' && value instanceof HTMLElement) {\n return true;\n }\n\n // Check for other built-in types by constructor name\n const constructorName = value.constructor?.name;\n if (constructorName && [\n 'Buffer', // Node.js Buffer\n 'URL', // Web URL API\n 'URLSearchParams',\n 'File', // Web File API\n 'Blob', // Web Blob API\n 'FormData', // Web FormData API\n 'Headers', // Web Headers API\n 'Request', // Web Request API\n 'Response', // Web Response API\n 'EventTarget', // Web EventTarget API\n 'Symbol' // Symbol objects\n ].includes(constructorName)) {\n return true;\n }\n\n return false;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\nimport { shallowEquals as shallowEqualsArray } from '../array/shallowEquals';\nimport { compare as compareDate } from '../date/compare';\nimport { isSpecialObject } from '../type/isSpecialObject';\n\n/**\n * Result type for deep comparison when objects are not identical\n * @since 2.0.0\n */\nexport interface DeepCompareResult {\n [key: string]: \"onlyA\" | \"onlyB\" | false | DeepCompareResult;\n}\n\n/**\n * Deep comparison of two objects that returns detailed information about differences.\n *\n * @param objA - First object to compare (can be object, undefined, or null)\n * @param objB - Second object to compare (can be object, undefined, or null)\n * @returns `true` if objects are identical, `false` if incompatible types, or a `DeepCompareResult` object detailing differences\n * @since 2.0.0\n */\nexport function deepCompare(objA: object | undefined | null, objB: object | undefined | null): true | false | DeepCompareResult {\n // Quick reference equality check\n if (objA === objB) {\n return true;\n }\n\n // Handle null/undefined cases\n if (objA == null || objB == null) {\n return false;\n }\n\n // Handle Date objects\n if (objA instanceof Date && objB instanceof Date) {\n return compareDate(objA, objB);\n }\n\n // Handle Arrays at root level - use shallowEquals\n if (Array.isArray(objA) && Array.isArray(objB)) {\n return shallowEqualsArray(objA, objB);\n }\n\n // If one is array and other is not\n if (Array.isArray(objA) || Array.isArray(objB)) {\n return false;\n }\n\n // Handle special objects - compare by reference only\n if (isSpecialObject(objA) || isSpecialObject(objB)) {\n return objA === objB;\n }\n\n // Handle objects - detailed comparison\n const keys = Array.from(new Set([...Object.keys(objA), ...Object.keys(objB)]));\n\n const differences: DeepCompareResult = {};\n\n for (const key of keys) {\n const hasA = key in objA;\n const hasB = key in objB;\n\n if (!hasA && hasB) {\n differences[key] = \"onlyB\";\n } else if (hasA && !hasB) {\n differences[key] = \"onlyA\";\n } else {\n // Both objects have this key - compare values\n const valueA = (objA as any)[key];\n const valueB = (objB as any)[key];\n\n // For arrays, use shallowEquals\n if (Array.isArray(valueA) && Array.isArray(valueB)) {\n if (!shallowEqualsArray(valueA, valueB)) {\n differences[key] = false;\n }\n }\n // For dates, use compareDate\n else if (valueA instanceof Date && valueB instanceof Date) {\n if (!compareDate(valueA, valueB)) {\n differences[key] = false;\n }\n }\n // For special objects, compare by reference only\n else if (isSpecialObject(valueA) || isSpecialObject(valueB)) {\n if (valueA !== valueB) {\n differences[key] = false;\n }\n }\n // For objects, recurse (only plain objects now)\n else if (\n valueA !== null && valueB !== null &&\n valueA !== undefined && valueB !== undefined &&\n typeof valueA === 'object' && typeof valueB === 'object' &&\n !isSpecialObject(valueA) && !isSpecialObject(valueB)\n ) {\n const nestedResult = deepCompare(valueA, valueB);\n if (nestedResult !== true) {\n differences[key] = nestedResult === false ? false : nestedResult;\n }\n }\n // For primitives and other types, check equality\n else if (valueA !== valueB) {\n differences[key] = false;\n }\n }\n }\n\n return Object.keys(differences).length > 0 ? differences : true;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Merges two or more objects deeply\n * @param target - The target object\n * @param sources - The source objects to merge\n * @returns The merged object\n * @since 1.9.0\n */\nexport function deepMerge<T extends Record<string, any>>(target: T, ...sources: Record<string, any>[]): T {\n if (!sources.length) return target;\n const source = sources.shift();\n\n if (!source) return deepMerge(target, ...sources);\n\n for (const key in source) {\n const targetValue = target[key];\n const sourceValue = source[key];\n\n if (isObject(targetValue) && isObject(sourceValue)) {\n (target as any)[key] = deepMerge(targetValue, sourceValue);\n } else if (sourceValue !== undefined) {\n (target as any)[key] = sourceValue;\n }\n }\n\n return deepMerge(target, ...sources);\n}\n\nfunction isObject(item: any): item is object {\n return item && typeof item === 'object' && !Array.isArray(item);\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Gets a value from an object using a dot-notated path\n * @param obj - The object to get value from\n * @param path - The dot-notated path (e.g., 'a.b.c')\n * @param defaultValue - Default value if path doesn't exist\n * @returns The value at the path or default value\n * @since 1.9.0\n */\nexport function get<T = any>(obj: any, path: string, defaultValue?: T): T | undefined {\n const keys = path.split('.');\n let result = obj;\n\n for (const key of keys) {\n if (result == null || typeof result !== 'object') {\n return defaultValue;\n }\n result = result[key];\n }\n\n return result !== undefined ? result : defaultValue;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\nimport { isNullish } from \"radashi\";\n\n/**\n * Remove null and undefined values from an object.\n *\n * @param obj an object\n * @returns A shallow copy of the object without null or undefined values\n * @since 1.0.0\n */\nexport function removeUndefinedNull<T extends Record<string, string | number | boolean | null | undefined>>(obj: T): Partial<T>;\n\n/**\n * Remove null and undefined values from an object.\n *\n * @param obj a null object\n * @returns null\n * @since 1.0.0\n */\nexport function removeUndefinedNull(obj: null): null;\n\n/**\n * Remove null and undefined values from an object.\n *\n * @param obj an undefined object\n * @returns undefined\n * @since 1.0.0\n */\nexport function removeUndefinedNull(obj: undefined): undefined;\n\n/**\n * Remove null and undefined values from an object.\n *\n * @param obj an object\n * @returns A shallow copy of the object without null or undefined values\n * @since 1.0.0\n */\nexport function removeUndefinedNull<T extends Record<string, string | number | boolean | null | undefined>>(obj: T | null | undefined): Partial<T> | null | undefined {\n return obj ? Object.entries(obj)\n .filter(([_, v]) => !isNullish(v))\n .reduce((acc, [k, v]) => ({ ...acc, [k]: v }), {} as Partial<T>) : obj;\n}\n\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Sets a value in an object using a dot-notated path\n * @param obj - The object to set value in\n * @param path - The dot-notated path (e.g., 'a.b.c')\n * @param value - The value to set\n * @returns The modified object\n * @since 1.9.0\n */\nexport function set(obj: Record<string, any>, path: string, value: any): Record<string, any> {\n const keys = path.split('.');\n let current = obj;\n\n for (let i = 0; i < keys.length - 1; i++) {\n const key = keys[i];\n\n if (!(key in current) || typeof current[key] !== 'object' || current[key] === null) {\n current[key] = {};\n }\n\n current = current[key];\n }\n\n current[keys[keys.length - 1]] = value;\n return obj;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Quick comparison of two objects using JSON.stringify.\n * This is a fast but simple comparison that may not work for all edge cases.\n *\n * @param objA - First object to compare\n * @param objB - Second object to compare\n * @returns `true` if objects are identical according to JSON.stringify, `false` otherwise\n * @since 2.0.0\n */\nexport function shallowEquals(objA: unknown, objB: unknown): boolean {\n // Quick reference equality check\n if (objA === objB) {\n return true;\n }\n\n // Handle functions - they can't be JSON.stringified reliably\n if (typeof objA === 'function' || typeof objB === 'function') {\n return objA === objB;\n }\n\n try {\n return JSON.stringify(objA) === JSON.stringify(objB);\n } catch {\n // If JSON.stringify fails (e.g., circular references), fall back to basic comparison\n return objA === objB;\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAYA,SAAgB,UAAa,KAAW;AACtC,KAAI,QAAQ,QAAQ,OAAO,QAAQ,SACjC,QAAO;AAGT,KAAI,eAAe,KACjB,QAAO,IAAI,KAAK,IAAI,SAAS,CAAC;AAGhC,KAAI,MAAM,QAAQ,IAAI,CACpB,QAAO,IAAI,KAAI,SAAQ,UAAU,KAAK,CAAC;CAGzC,MAAM,SAAS,EAAE;AACjB,MAAK,MAAM,OAAO,IAChB,KAAI,IAAI,eAAe,IAAI,CACzB,QAAO,OAAO,UAAU,IAAI,KAAK;AAIrC,QAAO;;;;;;;;;;;;;;;;;;ACjBT,SAAgB,gBAAiB,MAAW,MAAoB;AAC9D,KAAI;AACF,SAA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AAO,MAAM,OAAO,QAAQ,IAAI,CAC7B,QAAQ,CAAC,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CACjC,QAAQ,KAAK,CAAC,GAAG,QAAQ;EAAE,GAAG;GAAM,IAAI;EAAG,GAAG,EAAE,CAAe,GAAG;;;;;;;;;;;;;;;;;AC/BvE,SAAgB,IAAI,KAA0B,MAAc,OAAiC;CAC3F,MAAM,OAAO,KAAK,MAAM,IAAI;CAC5B,IAAI,UAAU;AAEd,MAAK,IAAI,IAAI,GAAG,IAAI,KAAK,SAAS,GAAG,KAAK;EACxC,MAAM,MAAM,KAAK;AAEjB,MAAI,EAAE,OAAO,YAAY,OAAO,QAAQ,SAAS,YAAY,QAAQ,SAAS,KAC5E,SAAQ,OAAO,EAAE;AAGnB,YAAU,QAAQ;;AAGpB,SAAQ,KAAK,KAAK,SAAS,MAAM;AACjC,QAAO;;;;;;;;;;;;;;;;;;ACdT,SAAgB,cAAc,MAAe,MAAwB;AAEnE,KAAI,SAAS,KACX,QAAO;AAIT,KAAI,OAAO,SAAS,cAAc,OAAO,SAAS,WAChD,QAAO,SAAS;AAGlB,KAAI;AACF,SAAO,KAAK,UAAU,KAAK,KAAK,KAAK,UAAU,KAAK;SAC9C;AAEN,SAAO,SAAS"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../helpers/object/compact.ts","../../../helpers/object/deepClone.ts","../../../helpers/array/shallowEquals.ts","../../../helpers/date/compare.ts","../../../helpers/type/isSpecialObject.ts","../../../helpers/object/deepCompare.ts","../../../helpers/object/deepMerge.ts","../../../helpers/object/get.ts","../../../helpers/object/omit.ts","../../../helpers/object/pick.ts","../../../helpers/type/isNullish.ts","../../../helpers/object/removeUndefinedNull.ts","../../../helpers/object/set.ts","../../../helpers/object/shallowEquals.ts"],"sourcesContent":["/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Removes all entries with falsy values (`false`, `null`, `undefined`, `0`, `\"\"`, `NaN`) from an object.\n * @param obj - The source object\n * @returns A new object containing only entries with truthy values\n * @example\n * compact({ a: 1, b: null, c: '', d: 0, e: 'hello' })\n * // => { a: 1, e: 'hello' }\n * @since 2.0.0\n */\nexport function compact<T extends Record<string, unknown>>(obj: T): Partial<T> {\n const result: Partial<T> = {};\n for (const key of Object.keys(obj) as (keyof T)[]) {\n if (obj[key]) {\n result[key] = obj[key];\n }\n }\n return result;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Creates a deep copy of an object or array\n * @param obj - The object to clone\n * @returns Deep cloned object\n * @since 1.9.0\n */\nexport function deepClone<T>(obj: T): T {\n if (obj === null || typeof obj !== \"object\") {\n return obj;\n }\n\n if (obj instanceof Date) {\n return new Date(obj.getTime()) as T;\n }\n\n if (Array.isArray(obj)) {\n return obj.map(item => deepClone(item)) as T;\n }\n\n const cloned = {} as T;\n for (const key in obj) {\n if (obj.hasOwnProperty(key)) {\n cloned[key] = deepClone(obj[key]);\n }\n }\n\n return cloned;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Quick comparison of two arrays using JSON.stringify.\n * This is a fast but simple comparison that may not work for all edge cases.\n *\n * @param arrA - First array to compare\n * @param arrB - Second array to compare\n * @returns `true` if arrays are identical according to JSON.stringify, `false` otherwise\n * @since 2.0.0\n */\nexport function shallowEquals<T>(arrA: T[], arrB: T[]): boolean {\n try {\n return JSON.stringify(arrA) === JSON.stringify(arrB);\n } catch {\n // If JSON.stringify fails (e.g., circular references), fall back to reference equality\n return arrA === arrB;\n }\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Options for date comparison\n * @since 2.0.0\n */\nexport interface DateCompareOptions {\n /** \n * Comparison precision\n * - 'milliseconds': Compare all including milliseconds (default)\n * - 'seconds': Ignore milliseconds, compare to the second\n * - 'minutes': Ignore seconds and milliseconds, compare to the minute\n * - 'hours': Ignore minutes, seconds and milliseconds, compare to the hour\n * - 'days': Compare only the date part (ignore time completely)\n */\n precision?: 'milliseconds' | 'seconds' | 'minutes' | 'hours' | 'days';\n}\n\n/**\n * Comparison of two dates.\n * \n * @param dateA - First date to compare\n * @param dateB - Second date to compare\n * @param options - Comparison options\n * @returns `true` if dates are identical according to the specified precision, `false` otherwise\n * @since 2.0.0\n */\nexport function compare(dateA: Date, dateB: Date, options: DateCompareOptions = {}): boolean {\n const { precision = 'milliseconds' } = options;\n\n if (!(dateA instanceof Date) || !(dateB instanceof Date)) {\n return dateA === dateB;\n }\n\n // Handle invalid dates\n if (isNaN(dateA.getTime()) || isNaN(dateB.getTime())) {\n return isNaN(dateA.getTime()) && isNaN(dateB.getTime());\n }\n\n switch (precision) {\n case 'days':\n return dateA.toDateString() === dateB.toDateString();\n\n case 'hours':\n const hoursA = Math.floor(dateA.getTime() / (1000 * 60 * 60));\n const hoursB = Math.floor(dateB.getTime() / (1000 * 60 * 60));\n return hoursA === hoursB;\n\n case 'minutes':\n const minutesA = Math.floor(dateA.getTime() / (1000 * 60));\n const minutesB = Math.floor(dateB.getTime() / (1000 * 60));\n return minutesA === minutesB;\n\n case 'seconds':\n const secondsA = Math.floor(dateA.getTime() / 1000);\n const secondsB = Math.floor(dateB.getTime() / 1000);\n return secondsA === secondsB;\n\n case 'milliseconds':\n default:\n return dateA.getTime() === dateB.getTime();\n }\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Determines if a value is a special object that should not have its properties compared deeply.\n * Special objects include: Date, Function, Promise, Observable, RegExp, Error, Map, Set, WeakMap, WeakSet, etc.\n * \n * @param value - The value to check\n * @returns `true` if the value is a special object, `false` otherwise\n * @since 2.0.0\n */\nexport function isSpecialObject(value: unknown): boolean {\n if (value === null || value === undefined) {\n return false;\n }\n\n // Functions are special objects\n if (typeof value === 'function') {\n return true;\n }\n\n // Non-objects are not special\n if (typeof value !== 'object') {\n return false;\n }\n\n // Arrays are not considered special objects for our purposes\n if (Array.isArray(value)) {\n return false;\n }\n\n // Check for built-in special objects\n if (\n value instanceof Date ||\n value instanceof Promise ||\n value instanceof RegExp ||\n value instanceof Error ||\n value instanceof Map ||\n value instanceof Set ||\n value instanceof WeakMap ||\n value instanceof WeakSet ||\n value instanceof ArrayBuffer ||\n value instanceof DataView\n ) {\n return true;\n }\n\n // Check for Observable (RxJS or similar)\n if (value.constructor?.name === 'Observable') {\n return true;\n }\n\n // Check for DOM elements (if in browser environment)\n if (typeof HTMLElement !== 'undefined' && value instanceof HTMLElement) {\n return true;\n }\n\n // Check for other built-in types by constructor name\n const constructorName = value.constructor?.name;\n if (constructorName && [\n 'Buffer', // Node.js Buffer\n 'URL', // Web URL API\n 'URLSearchParams',\n 'File', // Web File API\n 'Blob', // Web Blob API\n 'FormData', // Web FormData API\n 'Headers', // Web Headers API\n 'Request', // Web Request API\n 'Response', // Web Response API\n 'EventTarget', // Web EventTarget API\n 'Symbol' // Symbol objects\n ].includes(constructorName)) {\n return true;\n }\n\n return false;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\nimport { shallowEquals as shallowEqualsArray } from '../array/shallowEquals';\nimport { compare as compareDate } from '../date/compare';\nimport { isSpecialObject } from '../type/isSpecialObject';\n\n/**\n * Result type for deep comparison when objects are not identical\n * @since 2.0.0\n */\nexport interface DeepCompareResult {\n [key: string]: \"onlyA\" | \"onlyB\" | false | DeepCompareResult;\n}\n\n/**\n * Deep comparison of two objects that returns detailed information about differences.\n *\n * @param objA - First object to compare (can be object, undefined, or null)\n * @param objB - Second object to compare (can be object, undefined, or null)\n * @returns `true` if objects are identical, `false` if incompatible types, or a `DeepCompareResult` object detailing differences\n * @since 2.0.0\n */\nexport function deepCompare(objA: object | undefined | null, objB: object | undefined | null): true | false | DeepCompareResult {\n // Quick reference equality check\n if (objA === objB) {\n return true;\n }\n\n // Handle null/undefined cases\n if (objA == null || objB == null) {\n return false;\n }\n\n // Handle Date objects\n if (objA instanceof Date && objB instanceof Date) {\n return compareDate(objA, objB);\n }\n\n // Handle Arrays at root level - use shallowEquals\n if (Array.isArray(objA) && Array.isArray(objB)) {\n return shallowEqualsArray(objA, objB);\n }\n\n // If one is array and other is not\n if (Array.isArray(objA) || Array.isArray(objB)) {\n return false;\n }\n\n // Handle special objects - compare by reference only\n if (isSpecialObject(objA) || isSpecialObject(objB)) {\n return objA === objB;\n }\n\n // Handle objects - detailed comparison\n const keys = Array.from(new Set([...Object.keys(objA), ...Object.keys(objB)]));\n\n const differences: DeepCompareResult = {};\n\n for (const key of keys) {\n const hasA = key in objA;\n const hasB = key in objB;\n\n if (!hasA && hasB) {\n differences[key] = \"onlyB\";\n } else if (hasA && !hasB) {\n differences[key] = \"onlyA\";\n } else {\n // Both objects have this key - compare values\n const valueA = (objA as any)[key];\n const valueB = (objB as any)[key];\n\n // For arrays, use shallowEquals\n if (Array.isArray(valueA) && Array.isArray(valueB)) {\n if (!shallowEqualsArray(valueA, valueB)) {\n differences[key] = false;\n }\n }\n // For dates, use compareDate\n else if (valueA instanceof Date && valueB instanceof Date) {\n if (!compareDate(valueA, valueB)) {\n differences[key] = false;\n }\n }\n // For special objects, compare by reference only\n else if (isSpecialObject(valueA) || isSpecialObject(valueB)) {\n if (valueA !== valueB) {\n differences[key] = false;\n }\n }\n // For objects, recurse (only plain objects now)\n else if (\n valueA !== null && valueB !== null &&\n valueA !== undefined && valueB !== undefined &&\n typeof valueA === 'object' && typeof valueB === 'object' &&\n !isSpecialObject(valueA) && !isSpecialObject(valueB)\n ) {\n const nestedResult = deepCompare(valueA, valueB);\n if (nestedResult !== true) {\n differences[key] = nestedResult === false ? false : nestedResult;\n }\n }\n // For primitives and other types, check equality\n else if (valueA !== valueB) {\n differences[key] = false;\n }\n }\n }\n\n return Object.keys(differences).length > 0 ? differences : true;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Merges two or more objects deeply\n * @param target - The target object\n * @param sources - The source objects to merge\n * @returns The merged object\n * @since 1.9.0\n */\nexport function deepMerge<T extends Record<string, any>>(target: T, ...sources: Record<string, any>[]): T {\n if (!sources.length) return target;\n const source = sources.shift();\n\n if (!source) return deepMerge(target, ...sources);\n\n for (const key in source) {\n const targetValue = target[key];\n const sourceValue = source[key];\n\n if (isObject(targetValue) && isObject(sourceValue)) {\n (target as any)[key] = deepMerge(targetValue, sourceValue);\n } else if (sourceValue !== undefined) {\n (target as any)[key] = sourceValue;\n }\n }\n\n return deepMerge(target, ...sources);\n}\n\nfunction isObject(item: any): item is object {\n return item && typeof item === 'object' && !Array.isArray(item);\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Gets a value from an object using a dot-notated path\n * @param obj - The object to get value from\n * @param path - The dot-notated path (e.g., 'a.b.c')\n * @param defaultValue - Default value if path doesn't exist\n * @returns The value at the path or default value\n * @since 1.9.0\n */\nexport function get<T = any>(obj: any, path: string, defaultValue?: T): T | undefined {\n const keys = path.split('.');\n let result = obj;\n\n for (const key of keys) {\n if (result == null || typeof result !== 'object') {\n return defaultValue;\n }\n result = result[key];\n }\n\n return result !== undefined ? result : defaultValue;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Creates a new object without the specified keys.\n * @param obj - The source object\n * @param keys - The keys to omit\n * @returns A new object without the omitted keys\n * @example\n * omit({ a: 1, b: 2, c: 3 }, ['b'])\n * // => { a: 1, c: 3 }\n * @since 2.0.0\n */\nexport function omit<T extends Record<string, unknown>, K extends keyof T>(\n obj: T,\n keys: readonly K[]\n): Omit<T, K> {\n const result = { ...obj };\n for (const key of keys) {\n delete result[key];\n }\n return result as Omit<T, K>;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Creates a new object with only the specified keys.\n * @param obj - The source object\n * @param keys - The keys to pick\n * @returns A new object with only the picked keys\n * @example\n * pick({ a: 1, b: 2, c: 3 }, ['a', 'c'])\n * // => { a: 1, c: 3 }\n * @since 2.0.0\n */\nexport function pick<T extends Record<string, unknown>, K extends keyof T>(\n obj: T,\n keys: readonly K[]\n): Pick<T, K> {\n const result = {} as Pick<T, K>;\n for (const key of keys) {\n if (Object.prototype.hasOwnProperty.call(obj, key)) {\n result[key] = obj[key];\n }\n }\n return result;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Checks if a value is null or undefined (nullish).\n * @param value - The value to check\n * @returns True if value is null or undefined\n * @example\n * isNullish(null) // => true\n * isNullish(undefined) // => true\n * isNullish(0) // => false\n * isNullish('') // => false\n * @since 2.0.0\n */\nexport function isNullish(value: unknown): value is null | undefined {\n return value === null || value === undefined;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\nimport { isNullish } from '../type/isNullish';\n\n/**\n * Remove null and undefined values from an object.\n *\n * @param obj an object\n * @returns A shallow copy of the object without null or undefined values\n * @since 1.0.0\n */\nexport function removeUndefinedNull<T extends Record<string, string | number | boolean | null | undefined>>(obj: T): Partial<T>;\n\n/**\n * Remove null and undefined values from an object.\n *\n * @param obj a null object\n * @returns null\n * @since 1.0.0\n */\nexport function removeUndefinedNull(obj: null): null;\n\n/**\n * Remove null and undefined values from an object.\n *\n * @param obj an undefined object\n * @returns undefined\n * @since 1.0.0\n */\nexport function removeUndefinedNull(obj: undefined): undefined;\n\n/**\n * Remove null and undefined values from an object.\n *\n * @param obj an object\n * @returns A shallow copy of the object without null or undefined values\n * @since 1.0.0\n */\nexport function removeUndefinedNull<T extends Record<string, string | number | boolean | null | undefined>>(obj: T | null | undefined): Partial<T> | null | undefined {\n return obj ? Object.entries(obj)\n .filter(([_, v]) => !isNullish(v))\n .reduce((acc, [k, v]) => ({ ...acc, [k]: v }), {} as Partial<T>) : obj;\n}\n\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Sets a value in an object using a dot-notated path\n * @param obj - The object to set value in\n * @param path - The dot-notated path (e.g., 'a.b.c')\n * @param value - The value to set\n * @returns The modified object\n * @since 1.9.0\n */\nexport function set(obj: Record<string, any>, path: string, value: any): Record<string, any> {\n const keys = path.split('.');\n let current = obj;\n\n for (let i = 0; i < keys.length - 1; i++) {\n const key = keys[i];\n\n if (!(key in current) || typeof current[key] !== 'object' || current[key] === null) {\n current[key] = {};\n }\n\n current = current[key];\n }\n\n current[keys[keys.length - 1]] = value;\n return obj;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Quick comparison of two objects using JSON.stringify.\n * This is a fast but simple comparison that may not work for all edge cases.\n *\n * @param objA - First object to compare\n * @param objB - Second object to compare\n * @returns `true` if objects are identical according to JSON.stringify, `false` otherwise\n * @since 2.0.0\n */\nexport function shallowEquals(objA: unknown, objB: unknown): boolean {\n // Quick reference equality check\n if (objA === objB) {\n return true;\n }\n\n // Handle functions - they can't be JSON.stringified reliably\n if (typeof objA === 'function' || typeof objB === 'function') {\n return objA === objB;\n }\n\n try {\n return JSON.stringify(objA) === JSON.stringify(objB);\n } catch {\n // If JSON.stringify fails (e.g., circular references), fall back to basic comparison\n return objA === objB;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAeA,SAAgB,QAA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C3F,MAAM,OAAO,KAAK,MAAM,IAAI;CAC5B,IAAI,UAAU;AAEd,MAAK,IAAI,IAAI,GAAG,IAAI,KAAK,SAAS,GAAG,KAAK;EACxC,MAAM,MAAM,KAAK;AAEjB,MAAI,EAAE,OAAO,YAAY,OAAO,QAAQ,SAAS,YAAY,QAAQ,SAAS,KAC5E,SAAQ,OAAO,EAAE;AAGnB,YAAU,QAAQ;;AAGpB,SAAQ,KAAK,KAAK,SAAS,MAAM;AACjC,QAAO;;;;;;;;;;;;;;;;;;ACdT,SAAgB,cAAc,MAAe,MAAwB;AAEnE,KAAI,SAAS,KACX,QAAO;AAIT,KAAI,OAAO,SAAS,cAAc,OAAO,SAAS,WAChD,QAAO,SAAS;AAGlB,KAAI;AACF,SAAO,KAAK,UAAU,KAAK,KAAK,KAAK,UAAU,KAAK;SAC9C;AAEN,SAAO,SAAS"}
|
package/meta/api.json
CHANGED
|
@@ -1,7 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"category": "object",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.11",
|
|
4
4
|
"functions": [
|
|
5
|
+
{
|
|
6
|
+
"name": "compact",
|
|
7
|
+
"kind": "function",
|
|
8
|
+
"description": "Removes all entries with falsy values (`false`, `null`, `undefined`, `0`, `\"\"`, `NaN`) from an object.",
|
|
9
|
+
"since": "2.0.0",
|
|
10
|
+
"signatures": [
|
|
11
|
+
{
|
|
12
|
+
"signature": "compact<T extends Record<string, unknown>>(obj: T): Partial<T>",
|
|
13
|
+
"description": "Removes all entries with falsy values (`false`, `null`, `undefined`, `0`, `\"\"`, `NaN`) from an object.",
|
|
14
|
+
"params": [
|
|
15
|
+
{
|
|
16
|
+
"name": "obj",
|
|
17
|
+
"type": "T",
|
|
18
|
+
"description": "The source object"
|
|
19
|
+
}
|
|
20
|
+
],
|
|
21
|
+
"returns": {
|
|
22
|
+
"type": "Partial<T>",
|
|
23
|
+
"description": "A new object containing only entries with truthy values"
|
|
24
|
+
},
|
|
25
|
+
"typeParameters": [
|
|
26
|
+
{
|
|
27
|
+
"name": "T",
|
|
28
|
+
"constraint": "Record<string, unknown>"
|
|
29
|
+
}
|
|
30
|
+
]
|
|
31
|
+
}
|
|
32
|
+
],
|
|
33
|
+
"examples": [
|
|
34
|
+
{
|
|
35
|
+
"title": "Remove falsy values from object",
|
|
36
|
+
"description": "Removes all entries with falsy values (false, null, undefined, 0, \"\", NaN).",
|
|
37
|
+
"code": "compact({ a: 1, b: null, c: '', d: 0, e: 'hello' })\n// => { a: 1, e: 'hello' }"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"title": "Clean up API response",
|
|
41
|
+
"description": "Useful to strip empty or missing fields before sending data.",
|
|
42
|
+
"code": "compact({ name: 'Alice', email: '', age: 0, role: 'admin' })\n// => { name: 'Alice', role: 'admin' }"
|
|
43
|
+
}
|
|
44
|
+
],
|
|
45
|
+
"sourceFile": "compact.ts"
|
|
46
|
+
},
|
|
5
47
|
{
|
|
6
48
|
"name": "deepClone",
|
|
7
49
|
"kind": "function",
|
|
@@ -183,6 +225,108 @@
|
|
|
183
225
|
],
|
|
184
226
|
"sourceFile": "get.ts"
|
|
185
227
|
},
|
|
228
|
+
{
|
|
229
|
+
"name": "omit",
|
|
230
|
+
"kind": "function",
|
|
231
|
+
"description": "Creates a new object without the specified keys.",
|
|
232
|
+
"since": "2.0.0",
|
|
233
|
+
"signatures": [
|
|
234
|
+
{
|
|
235
|
+
"signature": "omit<T extends Record<string, unknown>, K extends string | number | symbol>(obj: T, keys: readonly K[]): Omit<T, K>",
|
|
236
|
+
"description": "Creates a new object without the specified keys.",
|
|
237
|
+
"params": [
|
|
238
|
+
{
|
|
239
|
+
"name": "obj",
|
|
240
|
+
"type": "T",
|
|
241
|
+
"description": "The source object"
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
"name": "keys",
|
|
245
|
+
"type": "readonly K[]",
|
|
246
|
+
"description": "The keys to omit"
|
|
247
|
+
}
|
|
248
|
+
],
|
|
249
|
+
"returns": {
|
|
250
|
+
"type": "Omit<T, K>",
|
|
251
|
+
"description": "A new object without the omitted keys"
|
|
252
|
+
},
|
|
253
|
+
"typeParameters": [
|
|
254
|
+
{
|
|
255
|
+
"name": "T",
|
|
256
|
+
"constraint": "Record<string, unknown>"
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
"name": "K",
|
|
260
|
+
"constraint": "string | number | symbol"
|
|
261
|
+
}
|
|
262
|
+
]
|
|
263
|
+
}
|
|
264
|
+
],
|
|
265
|
+
"examples": [
|
|
266
|
+
{
|
|
267
|
+
"title": "Omit specific keys",
|
|
268
|
+
"description": "Creates a new object without the specified keys.",
|
|
269
|
+
"code": "omit({ a: 1, b: 2, c: 3 }, ['b'])\n// => { a: 1, c: 3 }"
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
"title": "Remove sensitive fields",
|
|
273
|
+
"description": "Useful to strip sensitive data before sending to client.",
|
|
274
|
+
"code": "const user = { id: 1, name: 'Alice', password: 'secret', token: 'abc123' };\nomit(user, ['password', 'token'])\n// => { id: 1, name: 'Alice' }"
|
|
275
|
+
}
|
|
276
|
+
],
|
|
277
|
+
"sourceFile": "omit.ts"
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
"name": "pick",
|
|
281
|
+
"kind": "function",
|
|
282
|
+
"description": "Creates a new object with only the specified keys.",
|
|
283
|
+
"since": "2.0.0",
|
|
284
|
+
"signatures": [
|
|
285
|
+
{
|
|
286
|
+
"signature": "pick<T extends Record<string, unknown>, K extends string | number | symbol>(obj: T, keys: readonly K[]): Pick<T, K>",
|
|
287
|
+
"description": "Creates a new object with only the specified keys.",
|
|
288
|
+
"params": [
|
|
289
|
+
{
|
|
290
|
+
"name": "obj",
|
|
291
|
+
"type": "T",
|
|
292
|
+
"description": "The source object"
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
"name": "keys",
|
|
296
|
+
"type": "readonly K[]",
|
|
297
|
+
"description": "The keys to pick"
|
|
298
|
+
}
|
|
299
|
+
],
|
|
300
|
+
"returns": {
|
|
301
|
+
"type": "Pick<T, K>",
|
|
302
|
+
"description": "A new object with only the picked keys"
|
|
303
|
+
},
|
|
304
|
+
"typeParameters": [
|
|
305
|
+
{
|
|
306
|
+
"name": "T",
|
|
307
|
+
"constraint": "Record<string, unknown>"
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
"name": "K",
|
|
311
|
+
"constraint": "string | number | symbol"
|
|
312
|
+
}
|
|
313
|
+
]
|
|
314
|
+
}
|
|
315
|
+
],
|
|
316
|
+
"examples": [
|
|
317
|
+
{
|
|
318
|
+
"title": "Pick specific keys",
|
|
319
|
+
"description": "Creates a new object with only the specified keys.",
|
|
320
|
+
"code": "pick({ a: 1, b: 2, c: 3 }, ['a', 'c'])\n// => { a: 1, c: 3 }"
|
|
321
|
+
},
|
|
322
|
+
{
|
|
323
|
+
"title": "Extract user fields",
|
|
324
|
+
"description": "Useful to select only the fields you need from an object.",
|
|
325
|
+
"code": "const user = { id: 1, name: 'Alice', email: 'alice@example.com', password: 'secret' };\npick(user, ['id', 'name', 'email'])\n// => { id: 1, name: 'Alice', email: 'alice@example.com' }"
|
|
326
|
+
}
|
|
327
|
+
],
|
|
328
|
+
"sourceFile": "pick.ts"
|
|
329
|
+
},
|
|
186
330
|
{
|
|
187
331
|
"name": "removeUndefinedNull",
|
|
188
332
|
"kind": "function",
|
package/meta/examples.json
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"category": "object",
|
|
3
3
|
"functions": [
|
|
4
|
+
{
|
|
5
|
+
"name": "compact",
|
|
6
|
+
"examples": [
|
|
7
|
+
{
|
|
8
|
+
"title": "Remove falsy values from object",
|
|
9
|
+
"description": "Removes all entries with falsy values (false, null, undefined, 0, \"\", NaN).",
|
|
10
|
+
"code": "compact({ a: 1, b: null, c: '', d: 0, e: 'hello' })\n// => { a: 1, e: 'hello' }"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"title": "Clean up API response",
|
|
14
|
+
"description": "Useful to strip empty or missing fields before sending data.",
|
|
15
|
+
"code": "compact({ name: 'Alice', email: '', age: 0, role: 'admin' })\n// => { name: 'Alice', role: 'admin' }"
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
},
|
|
4
19
|
{
|
|
5
20
|
"name": "deepClone",
|
|
6
21
|
"examples": [
|
|
@@ -51,6 +66,36 @@
|
|
|
51
66
|
}
|
|
52
67
|
]
|
|
53
68
|
},
|
|
69
|
+
{
|
|
70
|
+
"name": "omit",
|
|
71
|
+
"examples": [
|
|
72
|
+
{
|
|
73
|
+
"title": "Omit specific keys",
|
|
74
|
+
"description": "Creates a new object without the specified keys.",
|
|
75
|
+
"code": "omit({ a: 1, b: 2, c: 3 }, ['b'])\n// => { a: 1, c: 3 }"
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"title": "Remove sensitive fields",
|
|
79
|
+
"description": "Useful to strip sensitive data before sending to client.",
|
|
80
|
+
"code": "const user = { id: 1, name: 'Alice', password: 'secret', token: 'abc123' };\nomit(user, ['password', 'token'])\n// => { id: 1, name: 'Alice' }"
|
|
81
|
+
}
|
|
82
|
+
]
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
"name": "pick",
|
|
86
|
+
"examples": [
|
|
87
|
+
{
|
|
88
|
+
"title": "Pick specific keys",
|
|
89
|
+
"description": "Creates a new object with only the specified keys.",
|
|
90
|
+
"code": "pick({ a: 1, b: 2, c: 3 }, ['a', 'c'])\n// => { a: 1, c: 3 }"
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"title": "Extract user fields",
|
|
94
|
+
"description": "Useful to select only the fields you need from an object.",
|
|
95
|
+
"code": "const user = { id: 1, name: 'Alice', email: 'alice@example.com', password: 'secret' };\npick(user, ['id', 'name', 'email'])\n// => { id: 1, name: 'Alice', email: 'alice@example.com' }"
|
|
96
|
+
}
|
|
97
|
+
]
|
|
98
|
+
},
|
|
54
99
|
{
|
|
55
100
|
"name": "removeUndefinedNull",
|
|
56
101
|
"examples": [
|
package/meta/licenses.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helpers4/object",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.11",
|
|
4
4
|
"description": "A set of helpers in TS/JS, compatible with tree-shaking, for object.",
|
|
5
5
|
"author": "baxyz <baxy@etik.com>",
|
|
6
6
|
"license": "LGPL-3.0",
|
|
@@ -26,10 +26,13 @@
|
|
|
26
26
|
"keywords": [
|
|
27
27
|
"helpers",
|
|
28
28
|
"object",
|
|
29
|
+
"compact",
|
|
29
30
|
"deepClone",
|
|
30
31
|
"deepCompare",
|
|
31
32
|
"deepMerge",
|
|
32
33
|
"get",
|
|
34
|
+
"omit",
|
|
35
|
+
"pick",
|
|
33
36
|
"removeUndefinedNull",
|
|
34
37
|
"set",
|
|
35
38
|
"shallowEquals"
|
|
@@ -45,8 +48,5 @@
|
|
|
45
48
|
],
|
|
46
49
|
"engines": {
|
|
47
50
|
"node": ">=18.0.0"
|
|
48
|
-
},
|
|
49
|
-
"peerDependencies": {
|
|
50
|
-
"radashi": "^12.7.2"
|
|
51
51
|
}
|
|
52
52
|
}
|