UNPKG

normul

Version:

Normul is a tiny TypeScript/JavaScript library for data normalization and transformation

36 lines 1.02 kB
import { isArray } from '../../utils.js'; import { Schema } from '../Schema.js'; export class TupleSchema extends Schema { elementSchemas; constructor(elementSchemas) { super(); this.elementSchemas = elementSchemas; } _normalize(input, ctx) { let array; if (isArray(input)) { array = input; } else { this.makeIssue({ ctx, message: 'Converted to array', level: 'warn', expected: 'array', received: input, }); array = input == null ? [] : [input]; } const result = []; for (let i = 0; i < this.elementSchemas.length; i++) { ctx.path.push(i); result[i] = this.invokeNormalize(this.elementSchemas[i], array[i], ctx); ctx.path.pop(); } return result; } cloneArgs() { return [this.elementSchemas]; } } //# sourceMappingURL=TupleSchema.js.map