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

Commit

Permalink
stacks are created without unnecessary sequences
Browse files Browse the repository at this point in the history
a single level stack is now just a level
and a a single item in single level stack  is now just an item
this makes the YAML less verbose
  • Loading branch information
grahamdyson committed Jun 20, 2019
1 parent 7715827 commit c81c2fc
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 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": "4.0.0"
"version": "4.1.0"
}
@@ -0,0 +1,26 @@
module.exports =
stack => {
return whenSingleLevel() || stack;

function whenSingleLevel() {
return (
stack.length === 1
&&
getLevelOrSingleItem(stack[0])
);
}
};

function getLevelOrSingleItem(
level,
) {
return whenSingleItem() || level;

function whenSingleItem() {
return (
level.length === 1
&&
level[0]
);
}
}
@@ -1,6 +1,8 @@
require("array.prototype.flat")
.shim();

const getStackOrSingleLevelOrSingleItem = require("./getStackOrSingleLevelOrSingleItem");

module.exports =
({
addMissing,
Expand All @@ -25,7 +27,9 @@ module.exports =
return (
itemsByIdentifiersInNewLevel.size || addMissing
?
identifiersInNewStack.reduce(aggregate, [])
getStackOrSingleLevelOrSingleItem(
identifiersInNewStack.reduce(aggregate, []),
)
:
getExistingWhenNoNewLevels()
);
Expand Down
Expand Up @@ -74,6 +74,13 @@ test.each(
[ "itemNotSpecified" ],
],
],
[
{
identifierOrItemOrLevelOrStack: "itemSpecified",
identifiersInNewStack: [ "itemSpecified" ],
},
"itemSpecified",
],
[
{
identifierOrItemOrLevelOrStack: [ "itemSpecified", "itemNotSpecified" ],
Expand Down Expand Up @@ -179,7 +186,7 @@ test.each(
identifierOrItemOrLevelOrStack: [ "item1", "item2" ],
identifiersInNewStack: [ [ "item1", "item2" ] ],
},
[ [ "item1", "item2" ] ],
[ "item1", "item2" ],
],
[
{
Expand Down Expand Up @@ -245,7 +252,7 @@ test.each(
identifierOrItemOrLevelOrStack: [ "item1", [] ],
identifiersInNewStack: [ "item1" ],
},
[ [ "item1" ] ],
"item1",
],
],
)(
Expand Down

0 comments on commit c81c2fc

Please sign in to comment.