/
githubmirror
/
nest
Обзор
Документация
Войти
/
githubmirror
/
nest
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
packages/common/utils/validate-each.util.ts
31 строка
716 B
Kamil Myśliwiec
bugfix: fix incorrect dependencies, simplify relations
19 окт 2018, 10:55
Не верифицирован
19 окт 2018, 10:55
6f9b242
Код
Авторство
О чём код?
export class InvalidDecoratorItemException extends Error { private readonly msg: string; constructor(decorator: string, item: string, context: string) { const message = `Invalid ${item} passed to ${decorator}() decorator (${context}).`; super(message); this.msg = message; } public what(): string { return this.msg; } } export function validateEach( context: { name: string }, arr: any[], predicate: Function, decorator: string, item: string, ): boolean { if (!context || !context.name) { return true; } const errors = arr.some(str => !predicate(str)); if (errors) { throw new InvalidDecoratorItemException(decorator, item, context.name); } return true; }