Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F995630
transform-object.ts
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
transform-object.ts
View Options
/* eslint-disable @typescript-eslint/no-unsafe-return */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
export
default
function
transformObject
(
obj
:
Record
<
string
,
any
>
,
prop_tranformer
:
(
prop
:
string
,
parent_props
:
string
[])
=>
string
,
value_transformer
:
(
prop
:
string
,
obj
:
unknown
,
parent_props
:
string
[]
)
=>
any
,
parent_props
:
string
[]
=
[]
)
{
// console.log("transformObject", obj);
const
new_obj
=
Array
.
isArray
(
obj
)
?
[]
:
({}
as
any
);
for
(
const
prop
in
obj
)
{
const
new_prop
=
prop_tranformer
(
prop
,
parent_props
);
// if (new_prop !== prop) {
// console.log(prop, "→", new_prop);
// }
new_obj
[
new_prop
]
=
typeof
obj
[
prop
]
===
"object"
?
transformObject
(
obj
[
prop
],
prop_tranformer
,
value_transformer
,
[
new_prop
,
...
parent_props
]
)
:
value_transformer
(
prop
,
obj
[
prop
],
[
new_prop
,
...
parent_props
,
]);
// console.log(obj[prop], "→", new_obj[new_prop]);
}
// console.log(obj, "→", new_obj);
return
new_obj
;
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Dec 23, 10:36 (1 d, 16 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
556367
Default Alt Text
transform-object.ts (1 KB)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline
Log In to Comment