Skip to content
This repository has been archived by the owner on Jun 30, 2020. It is now read-only.

Commit

Permalink
child items now supported by replace depends upon with hierarchies of…
Browse files Browse the repository at this point in the history
… identifier separator

DevSnicket/eunice#36
  • Loading branch information
grahamdyson committed Jun 17, 2019
1 parent 0d1f07a commit 96b3e30
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -89,5 +89,5 @@
"spellcheck": "find -type f \\( -name \"*.js\" -or -name \"*.md\" \\) ! -path \"./dist/*\" ! -path \"./dist/**/*\" ! -path \"./node_modules/**/*\" ! -path \"./test-coverage/**/*\" -exec npx cspell {} +",
"test": "npx jest --runInBand"
},
"version": "3.6.0"
"version": "3.6.1"
}
81 changes: 66 additions & 15 deletions replaceDependsUponWithHierarchiesOfIdentifierSeparator/index.js
Expand Up @@ -9,20 +9,71 @@ module.exports =
}) =>
items
&&
getIdentifierOrReplaceItemOrItemsInLevelOrStack({
identifierOrItemOrLevelOrStack: items,
replaceItem:
({
withIdentifierSeparator(identifierSeparator)
.getIdentifierOrReplaceDependsUponInItemOrItemsInLevelOrStack(items);

function withIdentifierSeparator(
identifierSeparator,
) {
return { getIdentifierOrReplaceDependsUponInItemOrItemsInLevelOrStack };

function getIdentifierOrReplaceDependsUponInItemOrItemsInLevelOrStack(
identifierOrItemOrLevelOrStack,
) {
return (
getIdentifierOrReplaceItemOrItemsInLevelOrStack({
identifierOrItemOrLevelOrStack,
replaceItem: replaceInItem,
})
);
}

function replaceInItem({
dependsUpon,
items,
...restOfItem
}) {
return (
{
...replaceDependsUponAsProperty(
dependsUpon,
...restOfItem
}) => (
{
dependsUpon:
replaceDependsUpon({
dependsUpon,
identifierSeparator,
}),
...restOfItem,
}
),
});
...replaceInItemsAsProperty(
items,
),
...restOfItem,
}
);
}

function replaceDependsUponAsProperty(
dependsUpon,
) {
return (
dependsUpon
&&
{
dependsUpon:
replaceDependsUpon({
dependsUpon,
identifierSeparator,
}),
}
);
}

function replaceInItemsAsProperty(
items,
) {
return (
items
&&
{
items:
getIdentifierOrReplaceDependsUponInItemOrItemsInLevelOrStack(
items,
),
}
);
}
}
27 changes: 27 additions & 0 deletions replaceDependsUponWithHierarchiesOfIdentifierSeparator/test.js
Expand Up @@ -31,6 +31,10 @@ test.each(
{ dependsUpon: "dependsUpon" },
{ dependsUpon: "dependsUpon" },
],
[
{ dependsUpon: {} },
{ dependsUpon: {} },
],
[
{
dependsUpon:
Expand Down Expand Up @@ -274,6 +278,29 @@ test.each(
},
},
],
[
{
id: "parent",
items:
{
dependsUpon: "dependsUponParent/dependsUponChild",
id: "child",
},
},
{
id: "parent",
items:
{
dependsUpon:
{
id: "dependsUponParent",
items: "dependsUponChild",
},
id:
"child",
},
},
],
],
)(
"%j items returns %j",
Expand Down

0 comments on commit 96b3e30

Please sign in to comment.