@twin.org/core 0.0.3-next.40 → 0.0.3-next.42

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 +1 @@
1
- {"version":3,"file":"objectHelper.js","sourceRoot":"","sources":["../../../src/helpers/objectHelper.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAEpC;;GAEG;AACH,MAAM,OAAO,YAAY;IACxB;;OAEG;IACI,MAAM,CAAU,UAAU,kBAAkC;IAEnE;;;;;OAKG;IACI,MAAM,CAAC,OAAO,CAAI,GAAkB,EAAE,SAAkB,KAAK;QACnE,IAAI,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC;YACvB,OAAO,IAAI,UAAU,EAAE,CAAC;QACzB,CAAC;QACD,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QAEjF,OAAO,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,SAAS,CAAI,KAAoC;QAC9D,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC3C,OAAO,SAAyB,CAAC;QAClC,CAAC;QACD,IAAI,CAAC;YACJ,MAAM,IAAI,GAAG,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;YAC1C,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAM,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AU,GAAG,OAAO,EAAE,UAAU,IAAI,KAAK,CAAC;YAChD,MAAM,MAAM,GAA8B,EAAE,CAAC;YAC7C,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAC9B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;gBACxB,IAAI,CAAC,CAAC,CAAC,eAAe,IAAI,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,IAAI,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;oBACzF,MAAM,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC,qBAAqB,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,CAAC;gBACrE,CAAC;YACF,CAAC;YACD,OAAO,MAAW,CAAC;QACpB,CAAC;aAAM,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;YAC1B,MAAM,GAAG,GAAG,EAAE,CAAC;YACf,KAAK,MAAM,OAAO,IAAI,GAAG,EAAE,CAAC;gBAC3B,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,qBAAqB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;YAChE,CAAC;YACD,OAAO,GAAQ,CAAC;QACjB,CAAC;QACD,OAAO,GAAG,CAAC;IACZ,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { nameof } from \"@twin.org/nameof\";\nimport { JsonHelper } from \"./jsonHelper.js\";\nimport { GeneralError } from \"../errors/generalError.js\";\nimport { Converter } from \"../utils/converter.js\";\nimport { Is } from \"../utils/is.js\";\n\n/**\n * Class to help with objects.\n */\nexport class ObjectHelper {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<ObjectHelper>();\n\n\t/**\n\t * Convert an object to bytes.\n\t * @param obj The object to convert.\n\t * @param format Format the JSON content.\n\t * @returns The object as bytes.\n\t */\n\tpublic static toBytes<T>(obj: T | undefined, format: boolean = false): Uint8Array {\n\t\tif (Is.undefined(obj)) {\n\t\t\treturn new Uint8Array();\n\t\t}\n\t\tconst json = format ? JSON.stringify(obj, undefined, \"\\t\") : JSON.stringify(obj);\n\n\t\treturn Converter.utf8ToBytes(json);\n\t}\n\n\t/**\n\t * Convert a bytes to an object.\n\t * @param bytes The bytes to convert to an object.\n\t * @returns The object.\n\t * @throws GeneralError if there was an error parsing the JSON.\n\t */\n\tpublic static fromBytes<T>(bytes: Uint8Array | undefined | null): T {\n\t\tif (Is.empty(bytes) || bytes.length === 0) {\n\t\t\treturn undefined as unknown as T;\n\t\t}\n\t\ttry {\n\t\t\tconst utf8 = Converter.bytesToUtf8(bytes);\n\t\t\treturn JSON.parse(utf8) as T;\n\t\t} catch (err) {\n\t\t\tthrow new GeneralError(ObjectHelper.CLASS_NAME, \"failedBytesToJSON\", undefined, err);\n\t\t}\n\t}\n\n\t/**\n\t * Make a deep clone of an object.\n\t * @param obj The object to clone.\n\t * @returns The objects clone.\n\t */\n\tpublic static clone<T>(obj: T): T;\n\t/**\n\t * Make a deep clone of an object.\n\t * @param obj The object to clone.\n\t * @returns The objects clone, or undefined if the input was undefined.\n\t */\n\tpublic static clone<T>(obj: T | undefined): T | undefined {\n\t\tif (Is.undefined(obj)) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn structuredClone(obj);\n\t}\n\n\t/**\n\t * Deep merge objects.\n\t * @param obj1 The first object to merge.\n\t * @param obj2 The second object to merge.\n\t * @returns The combined deep merge of the objects.\n\t */\n\tpublic static merge<T = unknown, U = unknown>(obj1: T, obj2: U): T & U {\n\t\tif (Is.empty(obj1)) {\n\t\t\treturn ObjectHelper.clone(obj2) as T & U;\n\t\t}\n\t\tif (Is.empty(obj2)) {\n\t\t\treturn ObjectHelper.clone(obj1) as T & U;\n\t\t}\n\n\t\tconst obj1Clone = ObjectHelper.clone(obj1);\n\n\t\tif (Is.object(obj1Clone) && Is.object(obj2)) {\n\t\t\tconst keys = Object.keys(obj2);\n\t\t\tfor (const key of keys) {\n\t\t\t\tif (Is.object(obj1Clone[key]) && Is.object(obj2[key])) {\n\t\t\t\t\tObjectHelper.propertySet(obj1Clone, key, ObjectHelper.merge(obj1Clone[key], obj2[key]));\n\t\t\t\t} else {\n\t\t\t\t\tObjectHelper.propertySet(obj1Clone, key, obj2[key]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn obj1Clone as T & U;\n\t}\n\n\t/**\n\t * Does one object equal another.\n\t * @param obj1 The first object to compare.\n\t * @param obj2 The second object to compare.\n\t * @param strictPropertyOrder Should the properties be in the same order, defaults to true.\n\t * @returns True is the objects are equal.\n\t */\n\tpublic static equal<T>(obj1: T, obj2: T, strictPropertyOrder?: boolean): boolean {\n\t\tif (strictPropertyOrder ?? true) {\n\t\t\treturn JSON.stringify(obj1) === JSON.stringify(obj2);\n\t\t}\n\t\treturn JsonHelper.canonicalize(obj1) === JsonHelper.canonicalize(obj2);\n\t}\n\n\t/**\n\t * Get the property of an unknown object.\n\t * @param obj The object to get the property from.\n\t * @param property The property to get, can be separated by dots for nested path.\n\t * @returns The property.\n\t */\n\tpublic static propertyGet<T = unknown>(obj: unknown, property: string): T | undefined {\n\t\tconst pathParts = property.split(\".\");\n\n\t\tlet pathValue: unknown = obj;\n\t\tfor (const pathPart of pathParts) {\n\t\t\t// Is the path part numeric i.e. an array index.\n\t\t\tconst arrayMatch = /^(\\d+)$/.exec(pathPart);\n\n\t\t\tif (arrayMatch) {\n\t\t\t\tconst arrayIndex = Number.parseInt(arrayMatch[1], 10);\n\n\t\t\t\tif (Is.arrayValue(pathValue) && arrayIndex < pathValue.length) {\n\t\t\t\t\t// There is no prop name so this is a direct array index on the current object\n\t\t\t\t\tpathValue = pathValue[arrayIndex];\n\t\t\t\t} else {\n\t\t\t\t\t// Array index for non array object so return\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\t\t\t} else if (Is.object(pathValue)) {\n\t\t\t\t// No array part in path so assume object sub property\n\t\t\t\tpathValue = pathValue[pathPart];\n\t\t\t} else {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t}\n\n\t\treturn pathValue as T;\n\t}\n\n\t/**\n\t * Set the property of an unknown object.\n\t * @param obj The object to set the property from.\n\t * @param property The property to set.\n\t * @param value The value to set.\n\t * @throws GeneralError if the property target is not an object.\n\t */\n\tpublic static propertySet(obj: unknown, property: string, value: unknown): void {\n\t\tconst pathParts = property.split(\".\");\n\n\t\tlet pathValue: unknown = obj;\n\t\tlet parentObj: unknown;\n\t\tfor (let i = 0; i < pathParts.length; i++) {\n\t\t\tconst pathPart = pathParts[i];\n\n\t\t\t// Is the path part numeric i.e. an array index.\n\t\t\tconst arrayMatch = /^(\\d+)$/.exec(pathPart);\n\t\t\tconst arrayIndex = arrayMatch ? Number.parseInt(arrayMatch[1], 10) : -1;\n\n\t\t\tif (i === pathParts.length - 1) {\n\t\t\t\t// Last part of path so set the value\n\t\t\t\tif (arrayIndex >= 0) {\n\t\t\t\t\tif (Is.array(pathValue)) {\n\t\t\t\t\t\tpathValue[arrayIndex] = value;\n\t\t\t\t\t} else if (Is.object(pathValue)) {\n\t\t\t\t\t\tpathValue[arrayIndex] = value;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new GeneralError(ObjectHelper.CLASS_NAME, \"cannotSetArrayIndex\", {\n\t\t\t\t\t\t\tproperty,\n\t\t\t\t\t\t\tindex: arrayIndex\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t} else if (Is.object(pathValue)) {\n\t\t\t\t\tpathValue[pathPart] = value;\n\t\t\t\t} else {\n\t\t\t\t\tthrow new GeneralError(ObjectHelper.CLASS_NAME, \"cannotSetProperty\", { property });\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tparentObj = pathValue;\n\t\t\t\tif (Is.object(pathValue)) {\n\t\t\t\t\tpathValue = pathValue[pathPart];\n\t\t\t\t} else if (Is.array(pathValue)) {\n\t\t\t\t\tpathValue = pathValue[arrayIndex];\n\t\t\t\t}\n\n\t\t\t\tif (Is.empty(pathValue)) {\n\t\t\t\t\tconst nextArrayMatch = /^(\\d+)$/.exec(pathParts[i + 1]);\n\t\t\t\t\tconst nextArrayIndex = nextArrayMatch ? Number.parseInt(nextArrayMatch[1], 10) : -1;\n\n\t\t\t\t\tif (nextArrayIndex >= 0) {\n\t\t\t\t\t\tpathValue = [];\n\t\t\t\t\t} else {\n\t\t\t\t\t\tpathValue = {};\n\t\t\t\t\t}\n\n\t\t\t\t\tif (Is.object(parentObj)) {\n\t\t\t\t\t\tparentObj[pathPart] = pathValue;\n\t\t\t\t\t} else if (Is.array(parentObj)) {\n\t\t\t\t\t\tparentObj[arrayIndex] = pathValue;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Delete the property of an unknown object.\n\t * @param obj The object to delete the property from.\n\t * @param property The property to delete.\n\t */\n\tpublic static propertyDelete(obj: unknown, property: string): void {\n\t\tif (Is.object(obj)) {\n\t\t\tdelete obj[property];\n\t\t}\n\t}\n\n\t/**\n\t * Extract a property from the object, providing alternative names.\n\t * @param obj The object to extract from.\n\t * @param propertyNames The possible names for the property.\n\t * @param removeProperties Remove the properties from the object, defaults to true.\n\t * @returns The property if available.\n\t */\n\tpublic static extractProperty<T>(\n\t\tobj: unknown,\n\t\tpropertyNames: string | string[],\n\t\tremoveProperties: boolean = true\n\t): T | undefined {\n\t\tlet retVal: T | undefined;\n\n\t\tif (Is.object(obj)) {\n\t\t\tconst names = Is.string(propertyNames) ? [propertyNames] : propertyNames;\n\n\t\t\tfor (const prop of names) {\n\t\t\t\tretVal ??= ObjectHelper.propertyGet<T>(obj, prop);\n\t\t\t\tif (removeProperties) {\n\t\t\t\t\tObjectHelper.propertyDelete(obj, prop);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn retVal;\n\t}\n\n\t/**\n\t * Pick a subset of properties from an object.\n\t * @param obj The object to pick the properties from.\n\t * @param keys The property keys to pick.\n\t * @returns The picked object, or undefined if the input was undefined.\n\t */\n\tpublic static pick<T extends object, K extends keyof T>(\n\t\tobj: T | undefined,\n\t\tkeys: readonly K[]\n\t): T extends undefined ? undefined : Pick<T, K> {\n\t\tif (Is.object(obj)) {\n\t\t\tconst result = {} as Pick<T, K>;\n\t\t\tif (Is.arrayValue(keys)) {\n\t\t\t\tfor (const key of keys) {\n\t\t\t\t\tresult[key] = obj[key];\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result as T extends undefined ? undefined : Pick<T, K>;\n\t\t}\n\n\t\treturn undefined as T extends undefined ? undefined : Pick<T, K>;\n\t}\n\n\t/**\n\t * Omit a subset of properties from an object.\n\t * @param obj The object to omit the properties from.\n\t * @param keys The property keys to omit.\n\t * @returns The object without the omitted keys, or undefined if the input was undefined.\n\t */\n\tpublic static omit<T, K extends keyof T>(\n\t\tobj: T | undefined,\n\t\tkeys: readonly K[]\n\t): T extends undefined ? undefined : Omit<T, K> {\n\t\tif (Is.object(obj) && Is.arrayValue(keys)) {\n\t\t\tconst result = ObjectHelper.clone(obj);\n\t\t\tfor (const key of keys) {\n\t\t\t\tdelete result[key];\n\t\t\t}\n\t\t\treturn result as T extends undefined ? undefined : Omit<T, K>;\n\t\t}\n\n\t\treturn obj as T extends undefined ? undefined : Omit<T, K>;\n\t}\n\n\t/**\n\t * Converter the non JSON primitives to extended types.\n\t * @param obj The object to convert.\n\t * @returns The object with extended properties.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tpublic static toExtended(obj: any): any {\n\t\tconst jsonExtended = JsonHelper.stringifyEx(obj);\n\t\treturn JSON.parse(jsonExtended);\n\t}\n\n\t/**\n\t * Converter the extended types to non JSON primitives.\n\t * @param obj The object to convert.\n\t * @returns The object with regular properties.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tpublic static fromExtended(obj: any): any {\n\t\tconst jsonExtended = JsonHelper.stringifyEx(obj);\n\t\treturn JsonHelper.parseEx(jsonExtended);\n\t}\n\n\t/**\n\t * Remove empty properties from an object.\n\t * @param obj The object to remove the empty properties from.\n\t * @param options The options for the removal.\n\t * @param options.removeUndefined Remove undefined properties, defaults to true.\n\t * @param options.removeNull Remove null properties, defaults to false.\n\t * @returns The object with empty properties removed.\n\t */\n\tpublic static removeEmptyProperties<T = unknown>(\n\t\tobj: T,\n\t\toptions?: { removeUndefined?: boolean; removeNull?: boolean }\n\t): T {\n\t\tif (Is.object(obj)) {\n\t\t\tconst removeUndefined = options?.removeUndefined ?? true;\n\t\t\tconst removeNull = options?.removeNull ?? false;\n\t\t\tconst newObj: { [id: string]: unknown } = {};\n\t\t\tconst keys = Object.keys(obj);\n\t\t\tfor (const key of keys) {\n\t\t\t\tif (!((removeUndefined && Is.undefined(obj[key])) || (removeNull && Is.null(obj[key])))) {\n\t\t\t\t\tnewObj[key] = ObjectHelper.removeEmptyProperties(obj[key], options);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn newObj as T;\n\t\t} else if (Is.array(obj)) {\n\t\t\tconst arr = [];\n\t\t\tfor (const element of obj) {\n\t\t\t\tarr.push(ObjectHelper.removeEmptyProperties(element, options));\n\t\t\t}\n\t\t\treturn arr as T;\n\t\t}\n\t\treturn obj;\n\t}\n}\n"]}
1
+ {"version":3,"file":"objectHelper.js","sourceRoot":"","sources":["../../../src/helpers/objectHelper.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAEpC;;GAEG;AACH,MAAM,OAAO,YAAY;IACxB;;OAEG;IACI,MAAM,CAAU,UAAU,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C,EAAE,OAAO,CAAC,CAAC;gBACrE,CAAC;YACF,CAAC;YACD,OAAO,MAAW,CAAC;QACpB,CAAC;aAAM,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;YAC1B,MAAM,GAAG,GAAG,EAAE,CAAC;YACf,KAAK,MAAM,OAAO,IAAI,GAAG,EAAE,CAAC;gBAC3B,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,qBAAqB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;YAChE,CAAC;YACD,OAAO,GAAQ,CAAC;QACjB,CAAC;QACD,OAAO,GAAG,CAAC;IACZ,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { nameof } from \"@twin.org/nameof\";\nimport { JsonHelper } from \"./jsonHelper.js\";\nimport { GeneralError } from \"../errors/generalError.js\";\nimport { Converter } from \"../utils/converter.js\";\nimport { Is } from \"../utils/is.js\";\n\n/**\n * Class to help with objects.\n */\nexport class ObjectHelper {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<ObjectHelper>();\n\n\t/**\n\t * Convert an object to bytes.\n\t * @param obj The object to convert.\n\t * @param format Format the JSON content.\n\t * @returns The object as bytes.\n\t */\n\tpublic static toBytes<T>(obj: T | undefined, format: boolean = false): Uint8Array {\n\t\tif (Is.undefined(obj)) {\n\t\t\treturn new Uint8Array();\n\t\t}\n\t\tconst json = format ? JSON.stringify(obj, undefined, \"\\t\") : JSON.stringify(obj);\n\n\t\treturn Converter.utf8ToBytes(json);\n\t}\n\n\t/**\n\t * Convert a bytes to an object.\n\t * @param bytes The bytes to convert to an object.\n\t * @returns The object.\n\t * @throws GeneralError if there was an error parsing the JSON.\n\t */\n\tpublic static fromBytes<T>(bytes: Uint8Array | undefined | null): T {\n\t\tif (Is.empty(bytes) || bytes.length === 0) {\n\t\t\treturn undefined as unknown as T;\n\t\t}\n\t\ttry {\n\t\t\tconst utf8 = Converter.bytesToUtf8(bytes);\n\t\t\treturn JSON.parse(utf8) as T;\n\t\t} catch (err) {\n\t\t\tthrow new GeneralError(ObjectHelper.CLASS_NAME, \"failedBytesToJSON\", undefined, err);\n\t\t}\n\t}\n\n\t/**\n\t * Make a deep clone of an object.\n\t * @param obj The object to clone.\n\t * @returns The objects clone.\n\t */\n\tpublic static clone<T>(obj: T): T;\n\t/**\n\t * Make a deep clone of an object.\n\t * @param obj The object to clone.\n\t * @returns The objects clone, or undefined if the input was undefined.\n\t */\n\tpublic static clone<T>(obj: T | undefined): T | undefined {\n\t\tif (Is.undefined(obj)) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn structuredClone(obj);\n\t}\n\n\t/**\n\t * Deep merge objects.\n\t * @param obj1 The first object to merge.\n\t * @param obj2 The second object to merge.\n\t * @returns The combined deep merge of the objects.\n\t */\n\tpublic static merge<T = unknown, U = unknown>(obj1: T, obj2: U): T & U {\n\t\tif (Is.empty(obj1)) {\n\t\t\treturn ObjectHelper.clone(obj2) as T & U;\n\t\t}\n\t\tif (Is.empty(obj2)) {\n\t\t\treturn ObjectHelper.clone(obj1) as T & U;\n\t\t}\n\n\t\tconst obj1Clone = ObjectHelper.clone(obj1);\n\n\t\tif (Is.object(obj1Clone) && Is.object(obj2)) {\n\t\t\tconst keys = Object.keys(obj2);\n\t\t\tfor (const key of keys) {\n\t\t\t\tif (Is.object(obj1Clone[key]) && Is.object(obj2[key])) {\n\t\t\t\t\tObjectHelper.propertySet(obj1Clone, key, ObjectHelper.merge(obj1Clone[key], obj2[key]));\n\t\t\t\t} else {\n\t\t\t\t\tObjectHelper.propertySet(obj1Clone, key, obj2[key]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn obj1Clone as T & U;\n\t}\n\n\t/**\n\t * Does one object equal another.\n\t * @param obj1 The first object to compare.\n\t * @param obj2 The second object to compare.\n\t * @param strictPropertyOrder Should the properties be in the same order, defaults to true.\n\t * @returns True is the objects are equal.\n\t */\n\tpublic static equal<T>(obj1: T, obj2: T, strictPropertyOrder?: boolean): boolean {\n\t\tif (strictPropertyOrder ?? true) {\n\t\t\treturn JSON.stringify(obj1) === JSON.stringify(obj2);\n\t\t}\n\t\treturn JsonHelper.canonicalize(obj1) === JsonHelper.canonicalize(obj2);\n\t}\n\n\t/**\n\t * Get the property of an unknown object.\n\t * @param obj The object to get the property from.\n\t * @param property The property to get, can be separated by dots for nested path.\n\t * @returns The property.\n\t */\n\tpublic static propertyGet<T = unknown>(obj: unknown, property: string): T | undefined {\n\t\tconst pathParts = property.split(\".\");\n\n\t\tlet pathValue: unknown = obj;\n\t\tfor (const pathPart of pathParts) {\n\t\t\t// Is the path part numeric i.e. an array index.\n\t\t\tconst arrayMatch = /^(\\d+)$/.exec(pathPart);\n\n\t\t\tif (arrayMatch) {\n\t\t\t\tconst arrayIndex = Number.parseInt(arrayMatch[1], 10);\n\n\t\t\t\tif (Is.arrayValue(pathValue) && arrayIndex < pathValue.length) {\n\t\t\t\t\t// There is no prop name so this is a direct array index on the current object\n\t\t\t\t\tpathValue = pathValue[arrayIndex];\n\t\t\t\t} else {\n\t\t\t\t\t// Array index for non array object so return\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\t\t\t} else if (Is.object(pathValue)) {\n\t\t\t\t// No array part in path so assume object sub property\n\t\t\t\tpathValue = pathValue[pathPart];\n\t\t\t} else {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t}\n\n\t\treturn pathValue as T;\n\t}\n\n\t/**\n\t * Set the property of an unknown object.\n\t * @param obj The object to set the property from.\n\t * @param property The property to set.\n\t * @param value The value to set.\n\t * @throws GeneralError if the property target is not an object.\n\t */\n\tpublic static propertySet(obj: unknown, property: string, value: unknown): void {\n\t\tconst pathParts = property.split(\".\");\n\n\t\tlet pathValue: unknown = obj;\n\t\tlet parentObj: unknown;\n\t\tfor (let i = 0; i < pathParts.length; i++) {\n\t\t\tconst pathPart = pathParts[i];\n\n\t\t\t// Is the path part numeric i.e. an array index.\n\t\t\tconst arrayMatch = /^(\\d+)$/.exec(pathPart);\n\t\t\tconst arrayIndex = arrayMatch ? Number.parseInt(arrayMatch[1], 10) : -1;\n\n\t\t\tif (i === pathParts.length - 1) {\n\t\t\t\t// Last part of path so set the value\n\t\t\t\tif (arrayIndex >= 0) {\n\t\t\t\t\tif (Is.array(pathValue)) {\n\t\t\t\t\t\tpathValue[arrayIndex] = value;\n\t\t\t\t\t} else if (Is.object(pathValue)) {\n\t\t\t\t\t\tpathValue[arrayIndex] = value;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new GeneralError(ObjectHelper.CLASS_NAME, \"cannotSetArrayIndex\", {\n\t\t\t\t\t\t\tproperty,\n\t\t\t\t\t\t\tindex: arrayIndex\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t} else if (Is.object(pathValue)) {\n\t\t\t\t\tpathValue[pathPart] = value;\n\t\t\t\t} else {\n\t\t\t\t\tthrow new GeneralError(ObjectHelper.CLASS_NAME, \"cannotSetProperty\", { property });\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tparentObj = pathValue;\n\t\t\t\tif (Is.object(pathValue)) {\n\t\t\t\t\tpathValue = pathValue[pathPart];\n\t\t\t\t} else if (Is.array(pathValue)) {\n\t\t\t\t\tpathValue = pathValue[arrayIndex];\n\t\t\t\t}\n\n\t\t\t\tif (Is.empty(pathValue)) {\n\t\t\t\t\tconst nextArrayMatch = /^(\\d+)$/.exec(pathParts[i + 1]);\n\t\t\t\t\tconst nextArrayIndex = nextArrayMatch ? Number.parseInt(nextArrayMatch[1], 10) : -1;\n\n\t\t\t\t\tif (nextArrayIndex >= 0) {\n\t\t\t\t\t\tpathValue = [];\n\t\t\t\t\t} else {\n\t\t\t\t\t\tpathValue = {};\n\t\t\t\t\t}\n\n\t\t\t\t\tif (Is.object(parentObj)) {\n\t\t\t\t\t\tparentObj[pathPart] = pathValue;\n\t\t\t\t\t} else if (Is.array(parentObj)) {\n\t\t\t\t\t\tparentObj[arrayIndex] = pathValue;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Delete the property of an unknown object.\n\t * @param obj The object to delete the property from.\n\t * @param property The property to delete.\n\t */\n\tpublic static propertyDelete(obj: unknown, property: string): void {\n\t\tif (Is.object(obj)) {\n\t\t\tdelete obj[property];\n\t\t}\n\t}\n\n\t/**\n\t * Extract a property from the object, providing alternative names.\n\t * @param obj The object to extract from.\n\t * @param propertyNames The possible names for the property.\n\t * @param removeProperties Remove the properties from the object, defaults to true.\n\t * @returns The property if available.\n\t */\n\tpublic static extractProperty<T>(\n\t\tobj: unknown,\n\t\tpropertyNames: string | string[],\n\t\tremoveProperties: boolean = true\n\t): T | undefined {\n\t\tlet retVal: T | undefined;\n\n\t\tif (Is.object(obj)) {\n\t\t\tconst names = Is.string(propertyNames) ? [propertyNames] : propertyNames;\n\n\t\t\tfor (const prop of names) {\n\t\t\t\tretVal ??= ObjectHelper.propertyGet<T>(obj, prop);\n\t\t\t\tif (removeProperties) {\n\t\t\t\t\tObjectHelper.propertyDelete(obj, prop);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn retVal;\n\t}\n\n\t/**\n\t * Pick a subset of properties from an object.\n\t * @param obj The object to pick the properties from.\n\t * @param keys The property keys to pick.\n\t * @returns The picked object.\n\t */\n\tpublic static pick<T, K extends keyof T>(obj: T, keys?: K[]): Pick<T, K>;\n\t/**\n\t * Pick a subset of properties from an object.\n\t * @param obj The object to pick the properties from.\n\t * @param keys The property keys to pick.\n\t * @returns The picked object, or undefined if the input was undefined.\n\t */\n\tpublic static pick<T, K extends keyof T>(obj: T | undefined, keys?: K[]): Pick<T, K> | undefined;\n\t/**\n\t * Pick a subset of properties from an object.\n\t * @param obj The object to pick the properties from.\n\t * @param keys The property keys to pick.\n\t * @returns The picked object, or undefined if the input was undefined.\n\t */\n\tpublic static pick<T, K extends keyof T>(obj: T | undefined, keys?: K[]): Pick<T, K> | undefined {\n\t\tif (Is.object(obj)) {\n\t\t\tconst result = {} as Pick<T, K>;\n\t\t\tif (Is.arrayValue(keys)) {\n\t\t\t\tfor (const key of keys) {\n\t\t\t\t\tresult[key] = obj[key];\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Omit a subset of properties from an object.\n\t * @param obj The object to omit the properties from.\n\t * @param keys The property keys to omit.\n\t * @returns The object without the omitted keys.\n\t */\n\tpublic static omit<T, K extends keyof T>(obj: T, keys?: K[]): Omit<T, K>;\n\t/**\n\t * Omit a subset of properties from an object.\n\t * @param obj The object to omit the properties from.\n\t * @param keys The property keys to omit.\n\t * @returns The object without the omitted keys, or undefined if the input was undefined.\n\t */\n\tpublic static omit<T, K extends keyof T>(obj: T | undefined, keys?: K[]): Omit<T, K> | undefined;\n\t/**\n\t * Omit a subset of properties from an object.\n\t * @param obj The object to omit the properties from.\n\t * @param keys The property keys to omit.\n\t * @returns The object without the omitted keys, or undefined if the input was undefined.\n\t */\n\tpublic static omit<T, K extends keyof T>(obj: T | undefined, keys?: K[]): Omit<T, K> {\n\t\tif (Is.object(obj) && Is.arrayValue(keys)) {\n\t\t\tconst result = ObjectHelper.clone(obj);\n\t\t\tfor (const key of keys) {\n\t\t\t\tdelete result[key];\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\treturn obj as Omit<T, K>;\n\t}\n\n\t/**\n\t * Converter the non JSON primitives to extended types.\n\t * @param obj The object to convert.\n\t * @returns The object with extended properties.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tpublic static toExtended(obj: any): any {\n\t\tconst jsonExtended = JsonHelper.stringifyEx(obj);\n\t\treturn JSON.parse(jsonExtended);\n\t}\n\n\t/**\n\t * Converter the extended types to non JSON primitives.\n\t * @param obj The object to convert.\n\t * @returns The object with regular properties.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tpublic static fromExtended(obj: any): any {\n\t\tconst jsonExtended = JsonHelper.stringifyEx(obj);\n\t\treturn JsonHelper.parseEx(jsonExtended);\n\t}\n\n\t/**\n\t * Remove empty properties from an object.\n\t * @param obj The object to remove the empty properties from.\n\t * @param options The options for the removal.\n\t * @param options.removeUndefined Remove undefined properties, defaults to true.\n\t * @param options.removeNull Remove null properties, defaults to false.\n\t * @returns The object with empty properties removed.\n\t */\n\tpublic static removeEmptyProperties<T = unknown>(\n\t\tobj: T,\n\t\toptions?: { removeUndefined?: boolean; removeNull?: boolean }\n\t): T {\n\t\tif (Is.object(obj)) {\n\t\t\tconst removeUndefined = options?.removeUndefined ?? true;\n\t\t\tconst removeNull = options?.removeNull ?? false;\n\t\t\tconst newObj: { [id: string]: unknown } = {};\n\t\t\tconst keys = Object.keys(obj);\n\t\t\tfor (const key of keys) {\n\t\t\t\tif (!((removeUndefined && Is.undefined(obj[key])) || (removeNull && Is.null(obj[key])))) {\n\t\t\t\t\tnewObj[key] = ObjectHelper.removeEmptyProperties(obj[key], options);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn newObj as T;\n\t\t} else if (Is.array(obj)) {\n\t\t\tconst arr = [];\n\t\t\tfor (const element of obj) {\n\t\t\t\tarr.push(ObjectHelper.removeEmptyProperties(element, options));\n\t\t\t}\n\t\t\treturn arr as T;\n\t\t}\n\t\treturn obj;\n\t}\n}\n"]}
@@ -70,20 +70,34 @@ export declare class ObjectHelper {
70
70
  * @returns The property if available.
71
71
  */
72
72
  static extractProperty<T>(obj: unknown, propertyNames: string | string[], removeProperties?: boolean): T | undefined;
73
+ /**
74
+ * Pick a subset of properties from an object.
75
+ * @param obj The object to pick the properties from.
76
+ * @param keys The property keys to pick.
77
+ * @returns The picked object.
78
+ */
79
+ static pick<T, K extends keyof T>(obj: T, keys?: K[]): Pick<T, K>;
73
80
  /**
74
81
  * Pick a subset of properties from an object.
75
82
  * @param obj The object to pick the properties from.
76
83
  * @param keys The property keys to pick.
77
84
  * @returns The picked object, or undefined if the input was undefined.
78
85
  */
79
- static pick<T extends object, K extends keyof T>(obj: T | undefined, keys: readonly K[]): T extends undefined ? undefined : Pick<T, K>;
86
+ static pick<T, K extends keyof T>(obj: T | undefined, keys?: K[]): Pick<T, K> | undefined;
87
+ /**
88
+ * Omit a subset of properties from an object.
89
+ * @param obj The object to omit the properties from.
90
+ * @param keys The property keys to omit.
91
+ * @returns The object without the omitted keys.
92
+ */
93
+ static omit<T, K extends keyof T>(obj: T, keys?: K[]): Omit<T, K>;
80
94
  /**
81
95
  * Omit a subset of properties from an object.
82
96
  * @param obj The object to omit the properties from.
83
97
  * @param keys The property keys to omit.
84
98
  * @returns The object without the omitted keys, or undefined if the input was undefined.
85
99
  */
86
- static omit<T, K extends keyof T>(obj: T | undefined, keys: readonly K[]): T extends undefined ? undefined : Omit<T, K>;
100
+ static omit<T, K extends keyof T>(obj: T | undefined, keys?: K[]): Omit<T, K> | undefined;
87
101
  /**
88
102
  * Converter the non JSON primitives to extended types.
89
103
  * @param obj The object to convert.
package/docs/changelog.md CHANGED
@@ -1,5 +1,39 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.0.3-next.42](https://github.com/iotaledger/twin-framework/compare/core-v0.0.3-next.41...core-v0.0.3-next.42) (2026-05-15)
4
+
5
+
6
+ ### Miscellaneous Chores
7
+
8
+ * **core:** Synchronize repo versions
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @twin.org/nameof bumped from 0.0.3-next.41 to 0.0.3-next.42
16
+ * devDependencies
17
+ * @twin.org/nameof-transformer bumped from 0.0.3-next.41 to 0.0.3-next.42
18
+ * @twin.org/nameof-vitest-plugin bumped from 0.0.3-next.41 to 0.0.3-next.42
19
+
20
+ ## [0.0.3-next.41](https://github.com/iotaledger/twin-framework/compare/core-v0.0.3-next.40...core-v0.0.3-next.41) (2026-05-13)
21
+
22
+
23
+ ### Features
24
+
25
+ * improve signatures ([45a7d58](https://github.com/iotaledger/twin-framework/commit/45a7d58baa5b6abc8c0735656f393d402fabb4ad))
26
+
27
+
28
+ ### Dependencies
29
+
30
+ * The following workspace dependencies were updated
31
+ * dependencies
32
+ * @twin.org/nameof bumped from 0.0.3-next.40 to 0.0.3-next.41
33
+ * devDependencies
34
+ * @twin.org/nameof-transformer bumped from 0.0.3-next.40 to 0.0.3-next.41
35
+ * @twin.org/nameof-vitest-plugin bumped from 0.0.3-next.40 to 0.0.3-next.41
36
+
3
37
  ## [0.0.3-next.40](https://github.com/iotaledger/twin-framework/compare/core-v0.0.3-next.39...core-v0.0.3-next.40) (2026-05-13)
4
38
 
5
39
 
@@ -332,37 +332,85 @@ The property if available.
332
332
 
333
333
  ### pick() {#pick}
334
334
 
335
- > `static` **pick**\<`T`, `K`\>(`obj`, `keys`): `T` *extends* `undefined` ? `undefined` : `Pick`\<`T`, `K`\>
335
+ Pick a subset of properties from an object.
336
+
337
+ #### Param
338
+
339
+ The object to pick the properties from.
340
+
341
+ #### Param
342
+
343
+ The property keys to pick.
344
+
345
+ #### Call Signature
346
+
347
+ > `static` **pick**\<`T`, `K`\>(`obj`, `keys?`): `Pick`\<`T`, `K`\>
336
348
 
337
349
  Pick a subset of properties from an object.
338
350
 
339
- #### Type Parameters
351
+ ##### Type Parameters
340
352
 
341
- ##### T
353
+ ###### T
342
354
 
343
- `T` *extends* `object`
355
+ `T`
344
356
 
345
- ##### K
357
+ ###### K
346
358
 
347
359
  `K` *extends* `string` \| `number` \| `symbol`
348
360
 
349
- #### Parameters
361
+ ##### Parameters
350
362
 
351
- ##### obj
363
+ ###### obj
364
+
365
+ `T`
366
+
367
+ The object to pick the properties from.
368
+
369
+ ###### keys?
370
+
371
+ `K`[]
372
+
373
+ The property keys to pick.
374
+
375
+ ##### Returns
376
+
377
+ `Pick`\<`T`, `K`\>
378
+
379
+ The picked object.
380
+
381
+ #### Call Signature
382
+
383
+ > `static` **pick**\<`T`, `K`\>(`obj`, `keys?`): `Pick`\<`T`, `K`\> \| `undefined`
384
+
385
+ Pick a subset of properties from an object.
386
+
387
+ ##### Type Parameters
388
+
389
+ ###### T
390
+
391
+ `T`
392
+
393
+ ###### K
394
+
395
+ `K` *extends* `string` \| `number` \| `symbol`
396
+
397
+ ##### Parameters
398
+
399
+ ###### obj
352
400
 
353
401
  `T` \| `undefined`
354
402
 
355
403
  The object to pick the properties from.
356
404
 
357
- ##### keys
405
+ ###### keys?
358
406
 
359
- readonly `K`[]
407
+ `K`[]
360
408
 
361
409
  The property keys to pick.
362
410
 
363
- #### Returns
411
+ ##### Returns
364
412
 
365
- `T` *extends* `undefined` ? `undefined` : `Pick`\<`T`, `K`\>
413
+ `Pick`\<`T`, `K`\> \| `undefined`
366
414
 
367
415
  The picked object, or undefined if the input was undefined.
368
416
 
@@ -370,37 +418,85 @@ The picked object, or undefined if the input was undefined.
370
418
 
371
419
  ### omit() {#omit}
372
420
 
373
- > `static` **omit**\<`T`, `K`\>(`obj`, `keys`): `T` *extends* `undefined` ? `undefined` : `Omit`\<`T`, `K`\>
421
+ Omit a subset of properties from an object.
422
+
423
+ #### Param
424
+
425
+ The object to omit the properties from.
426
+
427
+ #### Param
428
+
429
+ The property keys to omit.
430
+
431
+ #### Call Signature
432
+
433
+ > `static` **omit**\<`T`, `K`\>(`obj`, `keys?`): `Omit`\<`T`, `K`\>
374
434
 
375
435
  Omit a subset of properties from an object.
376
436
 
377
- #### Type Parameters
437
+ ##### Type Parameters
378
438
 
379
- ##### T
439
+ ###### T
380
440
 
381
441
  `T`
382
442
 
383
- ##### K
443
+ ###### K
384
444
 
385
445
  `K` *extends* `string` \| `number` \| `symbol`
386
446
 
387
- #### Parameters
447
+ ##### Parameters
388
448
 
389
- ##### obj
449
+ ###### obj
450
+
451
+ `T`
452
+
453
+ The object to omit the properties from.
454
+
455
+ ###### keys?
456
+
457
+ `K`[]
458
+
459
+ The property keys to omit.
460
+
461
+ ##### Returns
462
+
463
+ `Omit`\<`T`, `K`\>
464
+
465
+ The object without the omitted keys.
466
+
467
+ #### Call Signature
468
+
469
+ > `static` **omit**\<`T`, `K`\>(`obj`, `keys?`): `Omit`\<`T`, `K`\> \| `undefined`
470
+
471
+ Omit a subset of properties from an object.
472
+
473
+ ##### Type Parameters
474
+
475
+ ###### T
476
+
477
+ `T`
478
+
479
+ ###### K
480
+
481
+ `K` *extends* `string` \| `number` \| `symbol`
482
+
483
+ ##### Parameters
484
+
485
+ ###### obj
390
486
 
391
487
  `T` \| `undefined`
392
488
 
393
489
  The object to omit the properties from.
394
490
 
395
- ##### keys
491
+ ###### keys?
396
492
 
397
- readonly `K`[]
493
+ `K`[]
398
494
 
399
495
  The property keys to omit.
400
496
 
401
- #### Returns
497
+ ##### Returns
402
498
 
403
- `T` *extends* `undefined` ? `undefined` : `Omit`\<`T`, `K`\>
499
+ `Omit`\<`T`, `K`\> \| `undefined`
404
500
 
405
501
  The object without the omitted keys, or undefined if the input was undefined.
406
502
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/core",
3
- "version": "0.0.3-next.40",
3
+ "version": "0.0.3-next.42",
4
4
  "description": "Helper methods/classes for data type checking/validation/guarding/error handling",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,7 +14,7 @@
14
14
  "node": ">=20.0.0"
15
15
  },
16
16
  "dependencies": {
17
- "@twin.org/nameof": "0.0.3-next.40",
17
+ "@twin.org/nameof": "0.0.3-next.42",
18
18
  "intl-messageformat": "11.2.4",
19
19
  "rfc6902": "5.2.0"
20
20
  },