UNPKG

vue-types

Version:
163 lines (150 loc) 7.43 kB
import { c as VueTypeDef, a as PropOptions, I as InferType, f as VueTypeValidableDef, V as ValidatorFunction, b as VueProp, P as Prop, C as Constructor, e as VueTypeShape, h as VueTypesDefaults, g as VueTypesConfig } from './shared/vue-types.CqspdBQ7.js'; export { d as VueTypeLooseShape, i as config } from './shared/vue-types.CqspdBQ7.js'; import 'vue'; /** * Validates a given value against a prop type object. * * If `silent` is `false` (default) will return a boolean. If it is set to `true` * it will return `true` on success or a string error message on failure * * @param type - Type to use for validation. Either a type object or a constructor * @param value - Value to check * @param silent - Silence warnings */ declare function validateType(type: unknown, value: unknown, silent?: boolean): string | boolean; /** * Adds `isRequired` and `def` modifiers to an object * * @param name - Type internal name * @param obj - Object to enhance */ declare function toType<T = any>(name: string, obj: PropOptions<T>): VueTypeDef<T>; /** * Like `toType` but also adds the `validate()` method to the type object * * @param name - Type internal name * @param obj - Object to enhance */ declare function toValidableType<T = any>(name: string, obj: PropOptions<T>): VueTypeValidableDef<T>; /** * Return a new VueTypes type using another type as base. * * Properties in the `props` object will overwrite those defined in the source one * expect for the `validator` function. In that case both functions will be executed in series. * * @param name - Name of the new type * @param source - Source type * @param props - Custom type properties */ declare function fromType<T extends VueTypeDef<any>>(name: string, source: T): T; declare function fromType<T extends VueTypeDef<any>, V extends PropOptions<InferType<T>>>(name: string, source: T, props: V): Omit<T, keyof V> & V; declare const any: <T = any>() => VueTypeValidableDef<T, ValidatorFunction<T>>; declare const func: <T extends (...args: any[]) => any>() => VueTypeValidableDef<T, ValidatorFunction<T>>; declare const bool: () => VueTypeValidableDef<boolean, ValidatorFunction<boolean>>; declare const string: <T extends string = string>() => VueTypeValidableDef<T, ValidatorFunction<T>>; declare const number: <T extends number = number>() => VueTypeValidableDef<T, ValidatorFunction<T>>; declare const array: <T>() => VueTypeValidableDef<T[], ValidatorFunction<T[]>>; declare const object: <T extends Record<string, any>>() => VueTypeValidableDef<T, ValidatorFunction<T>>; declare const integer: <T extends number = number>() => VueTypeDef<T>; declare const symbol: () => VueTypeDef<symbol>; declare const nullable: () => PropOptions<null>; declare function custom<T>(validatorFn: ValidatorFunction<T>, warnMsg?: string): VueTypeDef<T>; declare function oneOf<D, T extends readonly D[] = readonly D[]>(arr: T): VueTypeDef<T[number]>; declare function oneOfType<D extends InferType<U>, U extends VueProp<any> | Prop<any> = any>(arr: U[]): VueTypeDef<D>; declare function arrayOf<T extends VueProp<any> | Prop<any>>(type: T): VueTypeDef<InferType<T>[]>; declare function instanceOf<C extends Constructor>(instanceConstructor: C): VueTypeDef<InstanceType<C>>; declare function objectOf<T extends VueProp<any> | Prop<any>>(type: T): VueTypeDef<Record<string, InferType<T>>>; declare function shape<T extends object>(obj: { [K in keyof T]: Prop<T[K]> | VueProp<T[K]>; }): VueTypeShape<T>; declare function utilsToType<T = unknown>(name: string, obj: PropOptions<T>, validable: true): VueTypeValidableDef<T>; declare function utilsToType<T = unknown>(name: string, obj: PropOptions<T>, validable?: false): VueTypeDef<T>; declare function createTypes(defs?: Partial<VueTypesDefaults>): { new (): {}; defaults: Partial<VueTypesDefaults>; get sensibleDefaults(): boolean | Partial<VueTypesDefaults>; set sensibleDefaults(v: boolean | Partial<VueTypesDefaults>); config: VueTypesConfig; get any(): VueTypeValidableDef<any, ValidatorFunction<any>>; get func(): VueTypeValidableDef<(...args: any[]) => any, ValidatorFunction<(...args: any[]) => any>> & { default: (...args: any[]) => any; }; get bool(): VueTypeValidableDef<boolean, ValidatorFunction<boolean>>; get string(): VueTypeValidableDef<string, ValidatorFunction<string>> & { default: string; }; get number(): VueTypeValidableDef<number, ValidatorFunction<number>> & { default: number; }; get array(): VueTypeValidableDef<unknown[], ValidatorFunction<unknown[]>> & { default: () => unknown[]; }; get object(): VueTypeValidableDef<Record<string, any>, ValidatorFunction<Record<string, any>>> & { default: () => Record<string, any>; }; get integer(): VueTypeDef<number> & { default: number; }; get symbol(): VueTypeDef<symbol>; get nullable(): PropOptions<null, null>; readonly custom: typeof custom; readonly oneOf: typeof oneOf; readonly instanceOf: typeof instanceOf; readonly oneOfType: typeof oneOfType; readonly arrayOf: typeof arrayOf; readonly objectOf: typeof objectOf; readonly shape: typeof shape; extend(..._args: any[]): void; utils: { validate(value: unknown, type: unknown): boolean; toType: typeof utilsToType; }; }; declare const VueTypes_base: { new (): {}; defaults: Partial<VueTypesDefaults>; get sensibleDefaults(): boolean | Partial<VueTypesDefaults>; set sensibleDefaults(v: boolean | Partial<VueTypesDefaults>); config: VueTypesConfig; get any(): VueTypeValidableDef<any, ValidatorFunction<any>>; get func(): VueTypeValidableDef<(...args: any[]) => any, ValidatorFunction<(...args: any[]) => any>> & { default: (...args: any[]) => any; }; get bool(): VueTypeValidableDef<boolean, ValidatorFunction<boolean>>; get string(): VueTypeValidableDef<string, ValidatorFunction<string>> & { default: string; }; get number(): VueTypeValidableDef<number, ValidatorFunction<number>> & { default: number; }; get array(): VueTypeValidableDef<unknown[], ValidatorFunction<unknown[]>> & { default: () => unknown[]; }; get object(): VueTypeValidableDef<Record<string, any>, ValidatorFunction<Record<string, any>>> & { default: () => Record<string, any>; }; get integer(): VueTypeDef<number> & { default: number; }; get symbol(): VueTypeDef<symbol>; get nullable(): PropOptions<null, null>; readonly custom: typeof custom; readonly oneOf: typeof oneOf; readonly instanceOf: typeof instanceOf; readonly oneOfType: typeof oneOfType; readonly arrayOf: typeof arrayOf; readonly objectOf: typeof objectOf; readonly shape: typeof shape; extend(..._args: any[]): void; utils: { validate(value: unknown, type: unknown): boolean; toType: typeof utilsToType; }; }; declare class VueTypes/*#__PURE__*/ extends VueTypes_base { } type VueTypesInterface = ReturnType<typeof createTypes>; // @ts-ignore export = VueTypes; export { VueTypeDef, VueTypeShape, VueTypeValidableDef, any, array, arrayOf, bool, createTypes, custom, fromType, func, instanceOf, integer, nullable, number, object, objectOf, oneOf, oneOfType, shape, string, symbol, toType, toValidableType, validateType }; export type { VueTypesInterface };