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

Commit

Permalink
adding items to stacks of a specifc identifier now uses a regular exp…
Browse files Browse the repository at this point in the history
…ression
  • Loading branch information
grahamdyson committed Jan 4, 2019
1 parent 215e279 commit 60c0546
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -84,5 +84,5 @@
"lint": "npx eslint .",
"test": "npx jest --runInBand"
},
"version": "1.9.0"
"version": "2.0.0"
}
5 changes: 3 additions & 2 deletions stacking/createOrAddToStacksToItemsWithIdentifier/bin.js
Expand Up @@ -7,13 +7,14 @@ const
callWithProcessStandardStreamsOfYaml(
({
commaSeparatedLevels,
identifierPattern,
items,
toIdentifier,
}) =>
createOrAddToStacksToItemsWithIdentifier({
identifierPattern:
new RegExp(identifierPattern),
identifiersInNewStack:
parseCommaSeparated(commaSeparatedLevels),
items,
toIdentifier,
}),
);
Expand Up @@ -2,7 +2,7 @@ module.exports =
({
ancestors,
identifiersInNewStack,
parentIdentifier,
parentIdentifierPattern,
}) => {
return (
hasParentWithIdentifier()
Expand All @@ -14,14 +14,28 @@ module.exports =

function hasParentWithIdentifier(
) {
return (
isParentIdentifierMatch(
getParentIdentifier(),
)
);
}

function getParentIdentifier() {
return (
ancestors.length
&&
getParent().id === parentIdentifier
ancestors[ancestors.length - 1].id
);
}

function getParent() {
return ancestors[ancestors.length - 1];
function isParentIdentifierMatch(
identifier,
) {
return (
identifier
&&
identifier.match(parentIdentifierPattern)
);
}
};
Expand Up @@ -33,7 +33,7 @@ test.each(
getIdentifiersInNewStackWhenParentAncestor({
ancestors,
identifiersInNewStack,
parentIdentifier: "addToParent",
parentIdentifierPattern: "addToParent",
}),
)
.toBe(
Expand Down
4 changes: 2 additions & 2 deletions stacking/createOrAddToStacksToItemsWithIdentifier/index.js
Expand Up @@ -5,9 +5,9 @@ const

module.exports =
({
identifierPattern,
identifiersInNewStack,
items,
toIdentifier,
}) =>
replaceItemsAndInItems({
identifierOrItemOrLevelOrStack:
Expand All @@ -25,7 +25,7 @@ module.exports =
getIdentifiersInNewStackWhenParentAncestor({
ancestors,
identifiersInNewStack,
parentIdentifier: toIdentifier,
parentIdentifierPattern: identifierPattern,
}),
}),
});
4 changes: 2 additions & 2 deletions stacking/createOrAddToStacksToItemsWithIdentifier/test.js
Expand Up @@ -5,6 +5,8 @@ test(
() =>
expect(
createOrAddToStacksToItemsWithIdentifier({
identifierPattern:
"^parent",
identifiersInNewStack:
[
[ "child 1" ],
Expand All @@ -20,8 +22,6 @@ test(
items: [ "child 1", "child 2" ],
},
},
toIdentifier:
"parent",
}),
)
.toEqual(
Expand Down

0 comments on commit 60c0546

Please sign in to comment.