UNPKG

typia

Version:

Superfast runtime validators with only one line

523 lines (522 loc) 19 kB
import { CamelCase, IValidation, KebabCase, PascalCase, SnakeCase } from "@typia/interface"; import { TypeGuardError } from "./TypeGuardError"; /** * Converts property names to camelCase. * * Transforms all property names in the object (including nested) to camelCase * convention. Creates a new object with renamed properties. Distinct source * keys that become the same destination key are rejected with an error instead * of silently discarding a value. This collision policy also applies to the * assert, is, validate, and factory variants. * * Does not validate the input. For validation, use: * * - {@link assertCamel} — Throws on type mismatch * - {@link isCamel} — Returns `null` on type mismatch * - {@link validateCamel} — Returns detailed validation errors * * @template T Type of input value * @param input Object to convert * @returns New object with camelCase property names * @throws {Error} When two source keys become the same destination key */ export declare function camel<T>(input: T): CamelCase<T>; /** * Converts property names to camelCase with assertion. * * Transforms all property names to camelCase with {@link assert} validation. * Throws {@link TypeGuardError} on type mismatch. * * Related functions: * * - {@link camel} — No validation * - {@link isCamel} — Returns `null` instead of throwing * - {@link validateCamel} — Returns detailed validation errors * * @template T Type of input value * @param input Object to convert * @param errorFactory Custom error factory receiving * {@link TypeGuardError.IProps} * @returns New object with camelCase property names * @throws {TypeGuardError} When input doesn't conform to type `T` */ export declare function assertCamel<T>(input: T, errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error)): CamelCase<T>; /** * Converts property names to camelCase with type checking. * * Transforms all property names to camelCase with {@link is} validation. Returns * `null` on type mismatch. * * Related functions: * * - {@link camel} — No validation * - {@link assertCamel} — Throws instead of returning `null` * - {@link validateCamel} — Returns detailed validation errors * * @template T Type of input value * @param input Object to convert * @returns New object with camelCase property names, or `null` if invalid */ export declare function isCamel<T>(input: T): CamelCase<T> | null; /** * Converts property names to camelCase with validation. * * Transforms all property names to camelCase with {@link validate} validation. * Returns {@link IValidation.IFailure} with all errors on mismatch, or * {@link IValidation.ISuccess} with converted object. * * Related functions: * * - {@link camel} — No validation * - {@link assertCamel} — Throws on first error * - {@link isCamel} — Returns `null` instead of error details * * @template T Type of input value * @param input Object to convert * @returns Validation result containing converted object or errors */ export declare function validateCamel<T>(input: T): IValidation<CamelCase<T>>; /** * Converts property names to PascalCase. * * Transforms all property names in the object (including nested) to PascalCase * convention. Creates a new object with renamed properties. Distinct source * keys that become the same destination key are rejected with an error instead * of silently discarding a value. This collision policy also applies to the * assert, is, validate, and factory variants. * * Does not validate the input. For validation, use: * * - {@link assertPascal} — Throws on type mismatch * - {@link isPascal} — Returns `null` on type mismatch * - {@link validatePascal} — Returns detailed validation errors * * @template T Type of input value * @param input Object to convert * @returns New object with PascalCase property names * @throws {Error} When two source keys become the same destination key */ export declare function pascal<T>(input: T): PascalCase<T>; /** * Converts property names to PascalCase with assertion. * * Transforms all property names to PascalCase with {@link assert} validation. * Throws {@link TypeGuardError} on type mismatch. * * Related functions: * * - {@link pascal} — No validation * - {@link isPascal} — Returns `null` instead of throwing * - {@link validatePascal} — Returns detailed validation errors * * @template T Type of input value * @param input Object to convert * @param errorFactory Custom error factory receiving * {@link TypeGuardError.IProps} * @returns New object with PascalCase property names * @throws {TypeGuardError} When input doesn't conform to type `T` */ export declare function assertPascal<T>(input: T, errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error)): PascalCase<T>; /** * Converts property names to PascalCase with type checking. * * Transforms all property names to PascalCase with {@link is} validation. * Returns `null` on type mismatch. * * Related functions: * * - {@link pascal} — No validation * - {@link assertPascal} — Throws instead of returning `null` * - {@link validatePascal} — Returns detailed validation errors * * @template T Type of input value * @param input Object to convert * @returns New object with PascalCase property names, or `null` if invalid */ export declare function isPascal<T>(input: T): PascalCase<T> | null; /** * Converts property names to PascalCase with validation. * * Transforms all property names to PascalCase with {@link validate} validation. * Returns {@link IValidation.IFailure} with all errors on mismatch, or * {@link IValidation.ISuccess} with converted object. * * Related functions: * * - {@link pascal} — No validation * - {@link assertPascal} — Throws on first error * - {@link isPascal} — Returns `null` instead of error details * * @template T Type of input value * @param input Object to convert * @returns Validation result containing converted object or errors */ export declare function validatePascal<T>(input: T): IValidation<PascalCase<T>>; /** * Converts property names to snake_case. * * Transforms all property names in the object (including nested) to snake_case * convention. Creates a new object with renamed properties. Distinct source * keys that become the same destination key are rejected with an error instead * of silently discarding a value. This collision policy also applies to the * assert, is, validate, and factory variants. * * Does not validate the input. For validation, use: * * - {@link assertSnake} — Throws on type mismatch * - {@link isSnake} — Returns `null` on type mismatch * - {@link validateSnake} — Returns detailed validation errors * * @template T Type of input value * @param input Object to convert * @returns New object with snake_case property names * @throws {Error} When two source keys become the same destination key */ export declare function snake<T>(input: T): SnakeCase<T>; /** * Converts property names to snake_case with assertion. * * Transforms all property names to snake_case with {@link assert} validation. * Throws {@link TypeGuardError} on type mismatch. * * Related functions: * * - {@link snake} — No validation * - {@link isSnake} — Returns `null` instead of throwing * - {@link validateSnake} — Returns detailed validation errors * * @template T Type of input value * @param input Object to convert * @param errorFactory Custom error factory receiving * {@link TypeGuardError.IProps} * @returns New object with snake_case property names * @throws {TypeGuardError} When input doesn't conform to type `T` */ export declare function assertSnake<T>(input: T, errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error)): SnakeCase<T>; /** * Converts property names to snake_case with type checking. * * Transforms all property names to snake_case with {@link is} validation. * Returns `null` on type mismatch. * * Related functions: * * - {@link snake} — No validation * - {@link assertSnake} — Throws instead of returning `null` * - {@link validateSnake} — Returns detailed validation errors * * @template T Type of input value * @param input Object to convert * @returns New object with snake_case property names, or `null` if invalid */ export declare function isSnake<T>(input: T): SnakeCase<T> | null; /** * Converts property names to snake_case with validation. * * Transforms all property names to snake_case with {@link validate} validation. * Returns {@link IValidation.IFailure} with all errors on mismatch, or * {@link IValidation.ISuccess} with converted object. * * Related functions: * * - {@link snake} — No validation * - {@link assertSnake} — Throws on first error * - {@link isSnake} — Returns `null` instead of error details * * @template T Type of input value * @param input Object to convert * @returns Validation result containing converted object or errors */ export declare function validateSnake<T>(input: T): IValidation<SnakeCase<T>>; /** * Converts property names to kebab-case. * * Transforms all property names in the object (including nested) to kebab-case * convention. Creates a new object with renamed properties. Distinct source * keys that become the same destination key are rejected with an error instead * of silently discarding a value. This collision policy also applies to the * assert, is, validate, and factory variants. * * Does not validate the input. For validation, use: * * - {@link assertKebab} — Throws on type mismatch * - {@link isKebab} — Returns `null` on type mismatch * - {@link validateKebab} — Returns detailed validation errors * * @template T Type of input value * @param input Object to convert * @returns New object with kebab-case property names * @throws {Error} When two source keys become the same destination key */ export declare function kebab<T>(input: T): KebabCase<T>; /** * Converts property names to kebab-case with assertion. * * Transforms all property names to kebab-case with {@link assert} validation. * Throws {@link TypeGuardError} on type mismatch. * * Related functions: * * - {@link kebab} — No validation * - {@link isKebab} — Returns `null` instead of throwing * - {@link validateKebab} — Returns detailed validation errors * * @template T Type of input value * @param input Object to convert * @param errorFactory Custom error factory receiving * {@link TypeGuardError.IProps} * @returns New object with kebab-case property names * @throws {TypeGuardError} When input doesn't conform to type `T` */ export declare function assertKebab<T>(input: T, errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error)): KebabCase<T>; /** * Converts property names to kebab-case with type checking. * * Transforms all property names to kebab-case with {@link is} validation. * Returns `null` on type mismatch. * * Related functions: * * - {@link kebab} — No validation * - {@link assertKebab} — Throws instead of returning `null` * - {@link validateKebab} — Returns detailed validation errors * * @template T Type of input value * @param input Object to convert * @returns New object with kebab-case property names, or `null` if invalid */ export declare function isKebab<T>(input: T): KebabCase<T> | null; /** * Converts property names to kebab-case with validation. * * Transforms all property names to kebab-case with {@link validate} validation. * Returns {@link IValidation.IFailure} with all errors on mismatch, or * {@link IValidation.ISuccess} with converted object. * * Related functions: * * - {@link kebab} — No validation * - {@link assertKebab} — Throws on first error * - {@link isKebab} — Returns `null` instead of error details * * @template T Type of input value * @param input Object to convert * @returns Validation result containing converted object or errors */ export declare function validateKebab<T>(input: T): IValidation<KebabCase<T>>; /** * Creates reusable {@link camel} function. * * @danger You must configure the generic argument `T` */ export declare function createCamel(): never; /** * Creates reusable {@link camel} function. * * @template T Type of input value * @returns Reusable conversion function */ export declare function createCamel<T>(): (input: T) => CamelCase<T>; /** * Creates reusable {@link assertCamel} function. * * @danger You must configure the generic argument `T` */ export declare function createAssertCamel(errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error)): never; /** * Creates reusable {@link assertCamel} function. * * @template T Type of input value * @param errorFactory Custom error factory receiving * {@link TypeGuardError.IProps} * @returns Reusable conversion function */ export declare function createAssertCamel<T>(errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error)): (input: T) => CamelCase<T>; /** * Creates reusable {@link isCamel} function. * * @danger You must configure the generic argument `T` */ export declare function createIsCamel(): never; /** * Creates reusable {@link isCamel} function. * * @template T Type of input value * @returns Reusable conversion function */ export declare function createIsCamel<T>(): (input: T) => CamelCase<T> | null; /** * Creates reusable {@link validateCamel} function. * * @danger You must configure the generic argument `T` */ export declare function createValidateCamel(): never; /** * Creates reusable {@link validateCamel} function. * * @template T Type of input value * @returns Reusable conversion function */ export declare function createValidateCamel<T>(): (input: T) => IValidation<CamelCase<T>>; /** * Creates reusable {@link pascal} function. * * @danger You must configure the generic argument `T` */ export declare function createPascal(): never; /** * Creates reusable {@link pascal} function. * * @template T Type of input value * @returns Reusable conversion function */ export declare function createPascal<T>(): (input: T) => PascalCase<T>; /** * Creates reusable {@link assertPascal} function. * * @danger You must configure the generic argument `T` */ export declare function createAssertPascal(errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error)): never; /** * Creates reusable {@link assertPascal} function. * * @template T Type of input value * @param errorFactory Custom error factory receiving * {@link TypeGuardError.IProps} * @returns Reusable conversion function */ export declare function createAssertPascal<T>(errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error)): (input: T) => PascalCase<T>; /** * Creates reusable {@link isPascal} function. * * @danger You must configure the generic argument `T` */ export declare function createIsPascal(): never; /** * Creates reusable {@link isPascal} function. * * @template T Type of input value * @returns Reusable conversion function */ export declare function createIsPascal<T>(): (input: T) => PascalCase<T> | null; /** * Creates reusable {@link validatePascal} function. * * @danger You must configure the generic argument `T` */ export declare function createValidatePascal(): never; /** * Creates reusable {@link validatePascal} function. * * @template T Type of input value * @returns Reusable conversion function */ export declare function createValidatePascal<T>(): (input: T) => IValidation<PascalCase<T>>; /** * Creates reusable {@link snake} function. * * @danger You must configure the generic argument `T` */ export declare function createSnake(): never; /** * Creates reusable {@link snake} function. * * @template T Type of input value * @returns Reusable conversion function */ export declare function createSnake<T>(): (input: T) => SnakeCase<T>; /** * Creates reusable {@link assertSnake} function. * * @danger You must configure the generic argument `T` */ export declare function createAssertSnake(errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error)): never; /** * Creates reusable {@link assertSnake} function. * * @template T Type of input value * @param errorFactory Custom error factory receiving * {@link TypeGuardError.IProps} * @returns Reusable conversion function */ export declare function createAssertSnake<T>(errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error)): (input: T) => SnakeCase<T>; /** * Creates reusable {@link isSnake} function. * * @danger You must configure the generic argument `T` */ export declare function createIsSnake(): never; /** * Creates reusable {@link isSnake} function. * * @template T Type of input value * @returns Reusable conversion function */ export declare function createIsSnake<T>(): (input: T) => SnakeCase<T> | null; /** * Creates reusable {@link validateSnake} function. * * @danger You must configure the generic argument `T` */ export declare function createValidateSnake(): never; /** * Creates reusable {@link validateSnake} function. * * @template T Type of input value * @returns Reusable conversion function */ export declare function createValidateSnake<T>(): (input: T) => IValidation<SnakeCase<T>>; /** * Creates reusable {@link kebab} function. * * @danger You must configure the generic argument `T` */ export declare function createKebab(): never; /** * Creates reusable {@link kebab} function. * * @template T Type of input value * @returns Reusable conversion function */ export declare function createKebab<T>(): (input: T) => KebabCase<T>; /** * Creates reusable {@link assertKebab} function. * * @danger You must configure the generic argument `T` */ export declare function createAssertKebab(errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error)): never; /** * Creates reusable {@link assertKebab} function. * * @template T Type of input value * @param errorFactory Custom error factory receiving * {@link TypeGuardError.IProps} * @returns Reusable conversion function */ export declare function createAssertKebab<T>(errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error)): (input: T) => KebabCase<T>; /** * Creates reusable {@link isKebab} function. * * @danger You must configure the generic argument `T` */ export declare function createIsKebab(): never; /** * Creates reusable {@link isKebab} function. * * @template T Type of input value * @returns Reusable conversion function */ export declare function createIsKebab<T>(): (input: T) => KebabCase<T> | null; /** * Creates reusable {@link validateKebab} function. * * @danger You must configure the generic argument `T` */ export declare function createValidateKebab(): never; /** * Creates reusable {@link validateKebab} function. * * @template T Type of input value * @returns Reusable conversion function */ export declare function createValidateKebab<T>(): (input: T) => IValidation<KebabCase<T>>;