UNPKG

mongoose-schema-jsonschema

Version:

Mongoose extension that allows to build json schema for mongoose models, schemas and queries

23 lines (16 loc) 643 B
const isString = keyValue => typeof keyValue === 'string'; const isTupple = keyValue => ( Array.isArray(keyValue) && keyValue.length === 2 && keyValue.every(isString) ); const stringOrTuple = keyValue => isString(keyValue) || isTupple(keyValue); const validateMap = map => { if (Array.isArray(map) && map.every(stringOrTuple)) return map; if (typeof map === 'object' && map != null && Object.entries(map).every(isTupple)) return map; throw TypeError( 'fieldsMapping Error: Wrong type of option value. ' + 'Expected: { [key: string]: string } | Array<string|[string, string]>', ); }; module.exports = validateMap;