diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2024-03-04 13:33:02 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2024-05-01 07:06:05 -0300 |
commit | b34f4b28667881cd1a5ff191d82d177bdeb5bba9 (patch) | |
tree | 56db936e4b7a7bda3a2fba79564ca709a57ec51d | |
parent | 5c15f47df44cd060d48eb3e7e0f7b0a2918922e9 (diff) |
validators: isThing
-rw-r--r-- | src/data/validators.js | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/data/validators.js b/src/data/validators.js index e3e56122..976e6217 100644 --- a/src/data/validators.js +++ b/src/data/validators.js @@ -613,6 +613,17 @@ export function isThingClass(thingClass) { return true; } +export function isThing(thing) { + isObject(thing); + isFunction(thing.constructor); + + if (!Object.hasOwn(thing.constructor, Symbol.for('Thing.referenceType'))) { + throw new TypeError(`Expected a Thing, constructor missing Thing.referenceType`); + } + + return true; +} + export const isContribution = validateProperties({ artist: isArtistRef, annotation: optional(isStringNonEmpty), |