diff --git a/package.json b/package.json index fec5b6f..c9dca37 100644 --- a/package.json +++ b/package.json @@ -84,5 +84,5 @@ "lint": "npx eslint .", "test": "npx jest --runInBand" }, - "version": "1.9.0" + "version": "2.0.0" } diff --git a/stacking/createOrAddToStacksToItemsWithIdentifier/bin.js b/stacking/createOrAddToStacksToItemsWithIdentifier/bin.js index 5c2f103..a15f17b 100644 --- a/stacking/createOrAddToStacksToItemsWithIdentifier/bin.js +++ b/stacking/createOrAddToStacksToItemsWithIdentifier/bin.js @@ -7,13 +7,14 @@ const callWithProcessStandardStreamsOfYaml( ({ commaSeparatedLevels, + identifierPattern, items, - toIdentifier, }) => createOrAddToStacksToItemsWithIdentifier({ + identifierPattern: + new RegExp(identifierPattern), identifiersInNewStack: parseCommaSeparated(commaSeparatedLevels), items, - toIdentifier, }), ); \ No newline at end of file diff --git a/stacking/createOrAddToStacksToItemsWithIdentifier/getIdentifiersInNewStackWhenParentAncestor/index.js b/stacking/createOrAddToStacksToItemsWithIdentifier/getIdentifiersInNewStackWhenParentAncestor/index.js index f3ee8a3..59defee 100644 --- a/stacking/createOrAddToStacksToItemsWithIdentifier/getIdentifiersInNewStackWhenParentAncestor/index.js +++ b/stacking/createOrAddToStacksToItemsWithIdentifier/getIdentifiersInNewStackWhenParentAncestor/index.js @@ -2,7 +2,7 @@ module.exports = ({ ancestors, identifiersInNewStack, - parentIdentifier, + parentIdentifierPattern, }) => { return ( hasParentWithIdentifier() @@ -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) + ); } }; \ No newline at end of file diff --git a/stacking/createOrAddToStacksToItemsWithIdentifier/getIdentifiersInNewStackWhenParentAncestor/test.js b/stacking/createOrAddToStacksToItemsWithIdentifier/getIdentifiersInNewStackWhenParentAncestor/test.js index 86c712f..473369c 100644 --- a/stacking/createOrAddToStacksToItemsWithIdentifier/getIdentifiersInNewStackWhenParentAncestor/test.js +++ b/stacking/createOrAddToStacksToItemsWithIdentifier/getIdentifiersInNewStackWhenParentAncestor/test.js @@ -33,7 +33,7 @@ test.each( getIdentifiersInNewStackWhenParentAncestor({ ancestors, identifiersInNewStack, - parentIdentifier: "addToParent", + parentIdentifierPattern: "addToParent", }), ) .toBe( diff --git a/stacking/createOrAddToStacksToItemsWithIdentifier/index.js b/stacking/createOrAddToStacksToItemsWithIdentifier/index.js index 78bb949..662bb96 100644 --- a/stacking/createOrAddToStacksToItemsWithIdentifier/index.js +++ b/stacking/createOrAddToStacksToItemsWithIdentifier/index.js @@ -5,9 +5,9 @@ const module.exports = ({ + identifierPattern, identifiersInNewStack, items, - toIdentifier, }) => replaceItemsAndInItems({ identifierOrItemOrLevelOrStack: @@ -25,7 +25,7 @@ module.exports = getIdentifiersInNewStackWhenParentAncestor({ ancestors, identifiersInNewStack, - parentIdentifier: toIdentifier, + parentIdentifierPattern: identifierPattern, }), }), }); \ No newline at end of file diff --git a/stacking/createOrAddToStacksToItemsWithIdentifier/test.js b/stacking/createOrAddToStacksToItemsWithIdentifier/test.js index 749c51d..e10bfd1 100644 --- a/stacking/createOrAddToStacksToItemsWithIdentifier/test.js +++ b/stacking/createOrAddToStacksToItemsWithIdentifier/test.js @@ -5,6 +5,8 @@ test( () => expect( createOrAddToStacksToItemsWithIdentifier({ + identifierPattern: + "^parent", identifiersInNewStack: [ [ "child 1" ], @@ -20,8 +22,6 @@ test( items: [ "child 1", "child 2" ], }, }, - toIdentifier: - "parent", }), ) .toEqual(