Skip to main content
Module

x/value_schema/dist-deno/appliers/ifEmptyString.ts

simple, easy-to-use, and declarative input validator; supports Node.js, TypeScript, Deno, and Bun
Latest
File
import { Key, Values } from "../libs/types.ts";import { RULE, ValueSchemaError } from "../libs/ValueSchemaError.ts";export interface Rules<T> { /** value if empty string (defaults: error) */ ifEmptyString?: T | null;}/** * apply schema * @param values input/output values * @param rules rules * @param keyStack key stack for error handling * @returns escapes from applyTo chain or not */export function applyTo<T>(values: Values, rules: Rules<T>, keyStack: Key[]): values is Values<T> { if (values.output !== "") { return false; } if (rules.ifEmptyString !== undefined) { values.output = rules.ifEmptyString; return true; } return ValueSchemaError.raise(RULE.EMPTY_STRING, values, keyStack);}