Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Monster
Manage
Activity
Members
Plan
Jira
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OSS
Libraries
Javascript
Monster
Commits
130b723d
Verified
Commit
130b723d
authored
1 year ago
by
Volker Schukai
Browse files
Options
Downloads
Patches
Plain Diff
fix: issue #121 bug in extractKeys
parent
4e7146e8
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
application/source/dom/util/extract-keys.mjs
+2
-1
2 additions, 1 deletion
application/source/dom/util/extract-keys.mjs
development/test/cases/dom/util/extract-keys.mjs
+64
-0
64 additions, 0 deletions
development/test/cases/dom/util/extract-keys.mjs
with
66 additions
and
1 deletion
application/source/dom/util/extract-keys.mjs
+
2
−
1
View file @
130b723d
...
@@ -22,7 +22,7 @@ function extractKeys(obj, keyPrefix = "", keySeparator = "-", valueSeparator = "
...
@@ -22,7 +22,7 @@ function extractKeys(obj, keyPrefix = "", keySeparator = "-", valueSeparator = "
function
helper
(
currentObj
,
currentKeyPrefix
,
currentValuePrefix
)
{
function
helper
(
currentObj
,
currentKeyPrefix
,
currentValuePrefix
)
{
for
(
const
key
in
currentObj
)
{
for
(
const
key
in
currentObj
)
{
if
(
typeof
currentObj
[
key
]
===
"
object
"
&&
!
Array
.
isArray
(
currentObj
[
key
]))
{
if
(
currentObj
[
key
]
!==
null
&&
typeof
currentObj
[
key
]
===
"
object
"
&&
!
Array
.
isArray
(
currentObj
[
key
]))
{
const
newKeyPrefix
=
currentKeyPrefix
const
newKeyPrefix
=
currentKeyPrefix
?
currentKeyPrefix
+
keySeparator
+
key
.
toLowerCase
()
?
currentKeyPrefix
+
keySeparator
+
key
.
toLowerCase
()
:
key
.
toLowerCase
();
:
key
.
toLowerCase
();
...
@@ -41,3 +41,4 @@ function extractKeys(obj, keyPrefix = "", keySeparator = "-", valueSeparator = "
...
@@ -41,3 +41,4 @@ function extractKeys(obj, keyPrefix = "", keySeparator = "-", valueSeparator = "
helper
(
obj
,
keyPrefix
,
keyPrefix
);
helper
(
obj
,
keyPrefix
,
keyPrefix
);
return
resultMap
;
return
resultMap
;
}
}
This diff is collapsed.
Click to expand it.
development/test/cases/dom/util/extract-keys.mjs
0 → 100644
+
64
−
0
View file @
130b723d
import
{
expect
}
from
'
chai
'
;
import
{
extractKeys
}
from
"
../../../../../application/source/dom/util/extract-keys.mjs
"
;
describe
(
'
extractKeys
'
,
()
=>
{
it
(
'
should extract keys from the given object
'
,
()
=>
{
const
obj
=
{
firstName
:
'
John
'
,
lastName
:
'
Doe
'
,
address
:
{
street
:
'
123 Main St
'
,
city
:
'
New York
'
,
},
};
const
expected
=
new
Map
([
[
'
firstname
'
,
'
firstName
'
],
[
'
lastname
'
,
'
lastName
'
],
[
'
address-street
'
,
'
address.street
'
],
[
'
address-city
'
,
'
address.city
'
],
]);
const
result
=
extractKeys
(
obj
);
expect
(
JSON
.
stringify
(
Array
.
from
(
result
))).
to
.
equal
(
JSON
.
stringify
(
Array
.
from
(
expected
)));
});
it
(
'
should use custom key and value separators
'
,
()
=>
{
const
obj
=
{
firstName
:
'
John
'
,
lastName
:
'
Doe
'
,
};
const
expected
=
new
Map
([
[
'
prefix+firstname
'
,
'
prefix+firstName
'
],
[
'
prefix+lastname
'
,
'
prefix+lastName
'
],
]);
const
result
=
extractKeys
(
obj
,
'
prefix
'
,
'
+
'
,
'
+
'
);
expect
(
JSON
.
stringify
(
Array
.
from
(
result
))).
to
.
equal
(
JSON
.
stringify
(
Array
.
from
(
expected
)));
});
it
(
'
check if value is null
'
,
()
=>
{
const
obj
=
{
firstName
:
'
John
'
,
lastName
:
'
Doe
'
,
address
:
null
,
};
const
expected
=
new
Map
([
[
'
firstname
'
,
'
firstName
'
],
[
'
lastname
'
,
'
lastName
'
],
[
'
address
'
,
'
address
'
],
]);
const
result
=
extractKeys
(
obj
);
expect
(
JSON
.
stringify
(
Array
.
from
(
result
))).
to
.
equal
(
JSON
.
stringify
(
Array
.
from
(
expected
)));
});
// Add more test cases as needed
});
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment