UNPKG

normul

Version:

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

25 lines 721 B
import { isBoolean } from '../../utils.js'; import { Schema } from '../Schema.js'; export class BooleanSchema extends Schema { _normalize(input, ctx) { if (isBoolean(input)) { return input; } this.makeIssue({ ctx, message: 'Converted to boolean', level: 'warn', expected: 'boolean', received: input, }); const string = String(input).trim().toLowerCase(); if (['false', '0', 'no'].includes(string)) { return false; } if (['true', '1', 'yes'].includes(string)) { return true; } return !!input; } } //# sourceMappingURL=BooleanSchema.js.map