@twin.org/core 0.0.1-next.7 → 0.0.1-next.8
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/dist/cjs/index.cjs
CHANGED
|
@@ -2819,6 +2819,26 @@ class ObjectHelper {
|
|
|
2819
2819
|
delete obj[property];
|
|
2820
2820
|
}
|
|
2821
2821
|
}
|
|
2822
|
+
/**
|
|
2823
|
+
* Extract a property from the object, providing alternative names.
|
|
2824
|
+
* @param obj The object to extract from.
|
|
2825
|
+
* @param propertyNames The possible names for the property.
|
|
2826
|
+
* @param removeProperties Remove the properties from the object, defaults to true.
|
|
2827
|
+
* @returns The property if available.
|
|
2828
|
+
*/
|
|
2829
|
+
static extractProperty(obj, propertyNames, removeProperties = true) {
|
|
2830
|
+
let retVal;
|
|
2831
|
+
if (Is.object(obj)) {
|
|
2832
|
+
const names = Is.string(propertyNames) ? [propertyNames] : propertyNames;
|
|
2833
|
+
for (const prop of names) {
|
|
2834
|
+
retVal ??= ObjectHelper.propertyGet(obj, prop);
|
|
2835
|
+
if (removeProperties) {
|
|
2836
|
+
ObjectHelper.propertyDelete(obj, prop);
|
|
2837
|
+
}
|
|
2838
|
+
}
|
|
2839
|
+
}
|
|
2840
|
+
return retVal;
|
|
2841
|
+
}
|
|
2822
2842
|
/**
|
|
2823
2843
|
* Pick a subset of properties from an object.
|
|
2824
2844
|
* @param obj The object to pick the properties from.
|
package/dist/esm/index.mjs
CHANGED
|
@@ -2817,6 +2817,26 @@ class ObjectHelper {
|
|
|
2817
2817
|
delete obj[property];
|
|
2818
2818
|
}
|
|
2819
2819
|
}
|
|
2820
|
+
/**
|
|
2821
|
+
* Extract a property from the object, providing alternative names.
|
|
2822
|
+
* @param obj The object to extract from.
|
|
2823
|
+
* @param propertyNames The possible names for the property.
|
|
2824
|
+
* @param removeProperties Remove the properties from the object, defaults to true.
|
|
2825
|
+
* @returns The property if available.
|
|
2826
|
+
*/
|
|
2827
|
+
static extractProperty(obj, propertyNames, removeProperties = true) {
|
|
2828
|
+
let retVal;
|
|
2829
|
+
if (Is.object(obj)) {
|
|
2830
|
+
const names = Is.string(propertyNames) ? [propertyNames] : propertyNames;
|
|
2831
|
+
for (const prop of names) {
|
|
2832
|
+
retVal ??= ObjectHelper.propertyGet(obj, prop);
|
|
2833
|
+
if (removeProperties) {
|
|
2834
|
+
ObjectHelper.propertyDelete(obj, prop);
|
|
2835
|
+
}
|
|
2836
|
+
}
|
|
2837
|
+
}
|
|
2838
|
+
return retVal;
|
|
2839
|
+
}
|
|
2820
2840
|
/**
|
|
2821
2841
|
* Pick a subset of properties from an object.
|
|
2822
2842
|
* @param obj The object to pick the properties from.
|
|
@@ -57,6 +57,14 @@ export declare class ObjectHelper {
|
|
|
57
57
|
* @param property The property to set
|
|
58
58
|
*/
|
|
59
59
|
static propertyDelete(obj: unknown, property: string): void;
|
|
60
|
+
/**
|
|
61
|
+
* Extract a property from the object, providing alternative names.
|
|
62
|
+
* @param obj The object to extract from.
|
|
63
|
+
* @param propertyNames The possible names for the property.
|
|
64
|
+
* @param removeProperties Remove the properties from the object, defaults to true.
|
|
65
|
+
* @returns The property if available.
|
|
66
|
+
*/
|
|
67
|
+
static extractProperty<T>(obj: unknown, propertyNames: string | string[], removeProperties?: boolean): T | undefined;
|
|
60
68
|
/**
|
|
61
69
|
* Pick a subset of properties from an object.
|
|
62
70
|
* @param obj The object to pick the properties from.
|
package/docs/changelog.md
CHANGED
|
@@ -232,6 +232,38 @@ The property to set
|
|
|
232
232
|
|
|
233
233
|
***
|
|
234
234
|
|
|
235
|
+
### extractProperty()
|
|
236
|
+
|
|
237
|
+
> `static` **extractProperty**\<`T`\>(`obj`, `propertyNames`, `removeProperties`): `undefined` \| `T`
|
|
238
|
+
|
|
239
|
+
Extract a property from the object, providing alternative names.
|
|
240
|
+
|
|
241
|
+
#### Type Parameters
|
|
242
|
+
|
|
243
|
+
• **T**
|
|
244
|
+
|
|
245
|
+
#### Parameters
|
|
246
|
+
|
|
247
|
+
• **obj**: `unknown`
|
|
248
|
+
|
|
249
|
+
The object to extract from.
|
|
250
|
+
|
|
251
|
+
• **propertyNames**: `string` \| `string`[]
|
|
252
|
+
|
|
253
|
+
The possible names for the property.
|
|
254
|
+
|
|
255
|
+
• **removeProperties**: `boolean` = `true`
|
|
256
|
+
|
|
257
|
+
Remove the properties from the object, defaults to true.
|
|
258
|
+
|
|
259
|
+
#### Returns
|
|
260
|
+
|
|
261
|
+
`undefined` \| `T`
|
|
262
|
+
|
|
263
|
+
The property if available.
|
|
264
|
+
|
|
265
|
+
***
|
|
266
|
+
|
|
235
267
|
### pick()
|
|
236
268
|
|
|
237
269
|
> `static` **pick**\<`T`\>(`obj`, `keys`?): `Partial`\<`T`\>
|