Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F995648
flatten-object-dot-notation.ts
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
628 B
Referenced Files
None
Subscribers
None
flatten-object-dot-notation.ts
View Options
export
default
function
flattenObjectToDotNotation
(
context
:
string
|
null
,
obj
:
{}
)
{
const
prefix
=
typeof
context
===
"string"
?
context
+
"."
:
""
;
return
flatten
(
prefix
,
obj
);
}
function
flatten
(
prefix
:
string
,
obj
:
{
[
field
:
string
]
:
{
[
field
:
string
]
:
any
}
}
)
{
return
Object
.
keys
(
obj
).
reduce
((
flattened
,
prop
)
=>
{
const
new_prop
=
prefix
+
prop
;
if
(
obj
[
prop
]
&&
typeof
obj
[
prop
]
===
"object"
)
{
Object
.
assign
(
flattened
,
flattenObjectToDotNotation
(
new_prop
+
"."
,
obj
[
prop
])
);
}
else
{
flattened
[
new_prop
]
=
obj
[
prop
];
}
return
flattened
;
},
{}
as
{
[
field
:
string
]
:
any
});
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Dec 23, 11:46 (1 d, 6 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
552956
Default Alt Text
flatten-object-dot-notation.ts (628 B)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline
Log In to Comment