From 6ac3a98cb60651b82d2f93a3ced0e56162ea4be7 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sun, 3 Nov 2024 09:52:22 -0400 Subject: data: withDirectoryFromName: move to helpers Also remove the more-composable default behavior of using the current thing's name, because this is no longer meant to be composed generally. --- .../wiki-data/helpers/withDirectoryFromName.js | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/data/composite/wiki-data/helpers/withDirectoryFromName.js (limited to 'src/data/composite/wiki-data/helpers') diff --git a/src/data/composite/wiki-data/helpers/withDirectoryFromName.js b/src/data/composite/wiki-data/helpers/withDirectoryFromName.js new file mode 100644 index 00000000..f85dae16 --- /dev/null +++ b/src/data/composite/wiki-data/helpers/withDirectoryFromName.js @@ -0,0 +1,41 @@ +// Compute a directory from a 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, + 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), + }), + }, + ], +}); -- cgit 1.3.0-6-gf8a5