« get me outta code hell

data: withDirectoryFromName: move to helpers - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/composite/wiki-data/helpers/withDirectoryFromName.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-11-03 09:52:22 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-11-14 07:59:22 -0400
commit6ac3a98cb60651b82d2f93a3ced0e56162ea4be7 (patch)
tree4e5f88dc92cb5bb7ed912cae0ccfbd47d19fe01b /src/data/composite/wiki-data/helpers/withDirectoryFromName.js
parent317138b543564205de91b04dc246ab3c0e501551 (diff)
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.
Diffstat (limited to 'src/data/composite/wiki-data/helpers/withDirectoryFromName.js')
-rw-r--r--src/data/composite/wiki-data/helpers/withDirectoryFromName.js41
1 files changed, 41 insertions, 0 deletions
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),
+      }),
+    },
+  ],
+});