castium
Version:
A lightweight and chainable utility for effortless data type conversation in JavaScript and Node.js
30 lines (28 loc) • 1.12 kB
text/typescript
declare class Castium<T> {
private value;
constructor(value: T);
number<D extends number | null>(defaultValue?: D): Castium<number | D>;
string(): Castium<string>;
boolean(): Castium<boolean>;
isEqual(expected: T): Castium<boolean>;
booleanString(): Castium<boolean | null>;
date(): Castium<Date | null>;
isoDate(): Castium<string | null>;
fromDate(): Castium<Date | null>;
toDate(): Castium<Date | null>;
dateTime(): Castium<number | null>;
array(): Castium<any[] | null>;
object(): Castium<object | null>;
nullable(): Castium<T | null>;
undefined(): Castium<T | undefined>;
default<U>(defaultValue: U): Castium<U | Exclude<T, null>>;
transform<U>(fn: (value: T) => U, defaultValue?: U): Castium<U | null>;
json(): Castium<object | null>;
match(regex: RegExp): Castium<boolean>;
oneOf(...values: (T | T[])[]): Castium<boolean>;
clamp(min: number, max: number): Castium<number>;
enum<E>(enumObj: Record<string, E>): Castium<Exclude<E, string> | null>;
get(): T;
}
declare const c: <T>(value: T) => Castium<T>;
export { c };