diff options
author | (quasar) nebula <towerofnix@gmail.com> | 2021-06-07 14:50:01 -0300 |
---|---|---|
committer | (quasar) nebula <towerofnix@gmail.com> | 2021-06-07 14:50:01 -0300 |
commit | 04682cbea790fde874a8488777738d28758012a9 (patch) | |
tree | 8791f4eff39905d577749c5f70d4587b2607f000 /src/thing/structures.js | |
parent | b2469c03bd4bdb29c5e80752f812203a6755c159 (diff) |
experimental AggregateError & Thing class hijinks
Diffstat (limited to 'src/thing/structures.js')
-rw-r--r-- | src/thing/structures.js | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/thing/structures.js b/src/thing/structures.js new file mode 100644 index 00000000..e6b9fd4b --- /dev/null +++ b/src/thing/structures.js @@ -0,0 +1,17 @@ +// Generic structure utilities common across various Thing types. + +export function validateReference(type = '') { + return ref => { + if (typeof ref !== 'string') + throw new TypeError(`Expected a string, got ${ref}`); + + if (type) { + if (!ref.includes(':')) + throw new TypeError(`Expected ref to begin with "${type}:", but no type specified (ref: ${ref})`); + + const typePart = ref.split(':')[0]; + if (typePart !== type) + throw new TypeError(`Expected ref to begin with "${type}:", got "${typePart}:" (ref: ${ref})`); + } + }; +} |