Skip to content

Commit 6eae1ca

Browse files
feat(abstract-utxo): add apply option to toPlainObject
This allows lower-level control Issue: BTC-1450
1 parent 1861966 commit 6eae1ca

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

modules/abstract-utxo/test/core/toPlainObject.utils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ type ToPlainObjectOpts = {
22
propertyDescriptors?: boolean;
33
skipUndefinedValues?: boolean;
44
ignorePaths?: string[] | ((path: PathElement[]) => boolean);
5+
apply?: (v: unknown, path: PathElement[]) => unknown;
56
};
67
export type PathElement = string | number;
78

@@ -50,6 +51,13 @@ function toPlainObjectFromPropertyDescriptors(v: unknown, opts: ToPlainObjectOpt
5051
}
5152

5253
export function toPlainObject(v: unknown, opts: ToPlainObjectOpts, path: PathElement[]): unknown {
54+
if (opts.apply) {
55+
const result = opts.apply(v, path);
56+
if (result !== undefined) {
57+
return result;
58+
}
59+
}
60+
5361
switch (typeof v) {
5462
case 'string':
5563
case 'number':

0 commit comments

Comments
 (0)