diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2024-05-19 21:39:53 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2024-05-19 21:47:31 -0300 |
commit | 471de6e5ac73bd6c769a58392e3e49aff6d8f2cb (patch) | |
tree | 48cbdab24e36fa7e33026e8cbc42cd05cde02ada /src/data/composite/wiki-data/withDirectoryFromName.js | |
parent | 9da8aa3ddcca68f3183ac2b1c187ce1b5f98e2d1 (diff) |
data: withDirectory, withDirectoryFromName
Diffstat (limited to 'src/data/composite/wiki-data/withDirectoryFromName.js')
-rw-r--r-- | src/data/composite/wiki-data/withDirectoryFromName.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/data/composite/wiki-data/withDirectoryFromName.js b/src/data/composite/wiki-data/withDirectoryFromName.js new file mode 100644 index 00000000..034464e4 --- /dev/null +++ b/src/data/composite/wiki-data/withDirectoryFromName.js @@ -0,0 +1,42 @@ +// Compute a directory from a name - by default the current thing's own name. + +import {input, templateCompositeFrom} from '#composite'; + +import {isName} from '#validators'; +import {getKebabCase} from '#wiki-data'; + +import {raiseOutputWithoutDependency} from '#composite/control-flow'; + +export default templateCompositeFrom({ + annotation: `withDirectoryFromName`, + + inputs: { + name: input({ + validate: isName, + defaultDependency: 'name', + acceptsNull: true, + }), + }, + + outputs: ['#directory'], + + steps: () => [ + raiseOutputWithoutDependency({ + dependency: input('name'), + mode: input.value('falsy'), + output: input.value({ + ['#directory']: null, + }), + }), + + { + dependencies: [input('name')], + compute: (continuation, { + [input('name')]: name, + }) => continuation({ + ['#directory']: + getKebabCase(name), + }), + }, + ], +}); |