diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2024-01-03 19:13:16 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2024-01-03 19:25:58 -0400 |
commit | 18dd81903cebb8cbd97c6b6e530bd8e517477da1 (patch) | |
tree | 09c3a179a56eeec2a9cfec097647e79ba4ffed47 /src | |
parent | f2accf775dd711cef9e212c05a0c58a5bcdd320d (diff) |
validators: validateAllPropertyValues: express in terms of validateProperties
Diffstat (limited to 'src')
-rw-r--r-- | src/data/things/validators.js | 33 |
1 files changed, 4 insertions, 29 deletions
diff --git a/src/data/things/validators.js b/src/data/things/validators.js index 939d78d5..5cbe33de 100644 --- a/src/data/things/validators.js +++ b/src/data/things/validators.js @@ -401,35 +401,10 @@ export function validateProperties(spec) { validateProperties.validateOtherKeys = Symbol(); validateProperties.allowOtherKeys = Symbol(); -export function validateAllPropertyValues(validator) { - return (object) => { - isObject(object); - - if (Array.isArray(object)) - throw new TypeError(`Expected an object, got array`); - - const errors = []; - - for (const key of Reflect.ownKeys(object)) { - const value = object[key]; - try { - validator(value); - } catch (error) { - const keyPart = colors.green(key.toString()); - const valuePart = inspect(value); - error.message = `(key: ${keyPart}, value: ${valuePart}) ${error.message}`; - errors.push(error); - } - } - - if (empty(errors)) { - return true; - } - - throw new AggregateError(errors, - `Errors validating object properties`); - }; -} +export const validateAllPropertyValues = (validator) => + validateProperties({ + [validateProperties.validateOtherKeys]: validator, + }); export const isContribution = validateProperties({ who: isArtistRef, |