From 73bbd2853e7a6ecc143d9d71dcca522e84375e30 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sun, 27 Jun 2021 13:11:26 -0300 Subject: aggregate shenanigans left uncommitted --- src/thing/structures.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/thing/structures.js') diff --git a/src/thing/structures.js b/src/thing/structures.js index e1bf06c..89c9bd3 100644 --- a/src/thing/structures.js +++ b/src/thing/structures.js @@ -1,5 +1,18 @@ // Generic structure utilities common across various Thing types. +export function validateDirectory(directory) { + if (typeof directory !== 'string') + throw new TypeError(`Expected a string, got ${directory}`); + + if (directory.length === 0) + throw new TypeError(`Expected directory to be non-zero length`); + + if (directory.match(/[^a-zA-Z0-9\-]/)) + throw new TypeError(`Expected only letters, numbers, and dash, got "${directory}"`); + + return true; +} + export function validateReference(type = '') { return ref => { if (typeof ref !== 'string') -- cgit 1.3.0-6-gf8a5