normul
Version:
Normul is a tiny TypeScript/JavaScript library for data normalization and transformation
29 lines • 753 B
JavaScript
import { isString } from '../../utils.js';
import { Schema } from '../Schema.js';
export class StringSchema extends Schema {
_normalize(input, ctx) {
if (isString(input)) {
return input;
}
this.makeIssue({
ctx,
message: 'Converted to string',
level: 'warn',
expected: 'string',
received: input,
});
if (input === null || input === undefined) {
return '';
}
if (typeof input === 'object') {
try {
return JSON.stringify(input);
}
catch {
//
}
}
return String(input);
}
}
//# sourceMappingURL=StringSchema.js.map