UNPKG

normul

Version:

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

31 lines 846 B
import { isNumber } from '../../utils.js'; import { Schema } from '../Schema.js'; export class NumberSchema extends Schema { _normalize(input, ctx) { if (isNumber(input)) { return input; } const number = Number(input); if (isNumber(number)) { this.makeIssue({ ctx, message: 'Converted to number', level: 'warn', expected: 'number', received: input, }); return number; } else { this.makeIssue({ ctx, message: 'Converted to 0', level: 'warn', expected: 'number', received: input, }); return 0; } } } //# sourceMappingURL=NumberSchema.js.map