-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
366 additions
and
373 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import './yupTypes' | ||
import * as yup from 'yup/es' | ||
import * as yup from './yupTypes' | ||
|
||
export { yup } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,73 @@ | ||
declare module 'yup/es' { | ||
export type LocaleValueFnParams<TExtra extends {} = {}> = { | ||
path: string | ||
type: string | ||
label?: string | ||
value: any | ||
originalValue: any | ||
} & TExtra | ||
export type LocaleValueFnParams<TExtra extends {} = {}> = { | ||
path: string | ||
type: string | ||
label?: string | ||
value: any | ||
originalValue: any | ||
} & TExtra | ||
|
||
export type LocaleValueFn<TExtra extends {} = {}> = ( | ||
params: LocaleValueFnParams<TExtra>, | ||
) => string | ||
export type LocaleValueFn<TExtra extends {} = {}> = ( | ||
params: LocaleValueFnParams<TExtra>, | ||
) => string | ||
|
||
export type LocaleValue<TExtra extends {} = {}> = | ||
| string | ||
| LocaleValueFn<TExtra> | ||
export type LocaleValue<TExtra extends {} = {}> = string | LocaleValueFn<TExtra> | ||
|
||
export interface MixedLocale { | ||
default: LocaleValue | ||
required: LocaleValue | ||
oneOf: LocaleValue<{ values: string }> | ||
notOneOf: LocaleValue<{ values: string }> | ||
notType: LocaleValue | ||
defined: LocaleValue | ||
} | ||
export interface MixedLocale { | ||
default: LocaleValue | ||
required: LocaleValue | ||
oneOf: LocaleValue<{ values: string }> | ||
notOneOf: LocaleValue<{ values: string }> | ||
notType: LocaleValue | ||
defined: LocaleValue | ||
} | ||
|
||
export interface StringLocale { | ||
length: LocaleValue<{ length: number }> | ||
min: LocaleValue<{ min: number }> | ||
max: LocaleValue<{ max: number }> | ||
matches: LocaleValue<{ regex: RegExp }> | ||
email: LocaleValue<{ regex: RegExp }> | ||
url: LocaleValue<{ regex: RegExp }> | ||
trim: LocaleValue | ||
lowercase: LocaleValue | ||
uppercase: LocaleValue | ||
chineseMobilePhoneNumber: LocaleValue | ||
chineseIDCardNumber: LocaleValue | ||
} | ||
export interface StringLocale { | ||
length: LocaleValue<{ length: number }> | ||
min: LocaleValue<{ min: number }> | ||
max: LocaleValue<{ max: number }> | ||
matches: LocaleValue<{ regex: RegExp }> | ||
email: LocaleValue<{ regex: RegExp }> | ||
url: LocaleValue<{ regex: RegExp }> | ||
trim: LocaleValue | ||
lowercase: LocaleValue | ||
uppercase: LocaleValue | ||
chineseMobilePhoneNumber: LocaleValue | ||
chineseIDCardNumber: LocaleValue | ||
} | ||
|
||
export interface NumberLocale { | ||
min: LocaleValue<{ min: number }> | ||
max: LocaleValue<{ max: number }> | ||
lessThan: LocaleValue<{ less: number }> | ||
moreThan: LocaleValue<{ more: number }> | ||
positive: LocaleValue<{ more: number }> | ||
negative: LocaleValue<{ less: number }> | ||
integer: LocaleValue | ||
} | ||
export interface NumberLocale { | ||
min: LocaleValue<{ min: number }> | ||
max: LocaleValue<{ max: number }> | ||
lessThan: LocaleValue<{ less: number }> | ||
moreThan: LocaleValue<{ more: number }> | ||
positive: LocaleValue<{ more: number }> | ||
negative: LocaleValue<{ less: number }> | ||
integer: LocaleValue | ||
} | ||
|
||
export interface DateLocale { | ||
min: LocaleValue<{ min: Date | string }> | ||
max: LocaleValue<{ max: Date | string }> | ||
} | ||
export interface DateLocale { | ||
min: LocaleValue<{ min: Date | string }> | ||
max: LocaleValue<{ max: Date | string }> | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
export interface BooleanLocale {} | ||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
export interface BooleanLocale {} | ||
|
||
export interface ObjectLocale { | ||
noUnknown: LocaleValue<{ unknown: string }> | ||
} | ||
export interface ObjectLocale { | ||
noUnknown: LocaleValue<{ unknown: string }> | ||
} | ||
|
||
export interface ArrayLocale { | ||
min: LocaleValue<{ min: number }> | ||
max: LocaleValue<{ max: number }> | ||
} | ||
export interface ArrayLocale { | ||
min: LocaleValue<{ min: number }> | ||
max: LocaleValue<{ max: number }> | ||
} | ||
|
||
export interface Locale { | ||
mixed: MixedLocale | ||
string: StringLocale | ||
number: NumberLocale | ||
date: DateLocale | ||
boolean: BooleanLocale | ||
object: ObjectLocale | ||
array: ArrayLocale | ||
} | ||
export interface Locale { | ||
mixed: MixedLocale | ||
string: StringLocale | ||
number: NumberLocale | ||
date: DateLocale | ||
boolean: BooleanLocale | ||
object: ObjectLocale | ||
array: ArrayLocale | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,21 @@ | ||
declare module 'yup/es' { | ||
export class ValidationError { | ||
value: any | ||
import { LocaleValue, LocaleValueFnParams } from './Locale' | ||
|
||
path: string | ||
export declare class ValidationError { | ||
value: any | ||
|
||
type: string | ||
path: string | ||
|
||
errors: string[] | ||
type: string | ||
|
||
inner: any[] | ||
errors: string[] | ||
|
||
message: string | ||
inner: any[] | ||
|
||
stack?: any | ||
message: string | ||
|
||
static isError<T>(err: T): boolean | ||
stack?: any | ||
|
||
static formatError( | ||
message: LocaleValue, | ||
params: LocaleValueFnParams, | ||
): string | ||
} | ||
static isError<T>(err: T): boolean | ||
|
||
static formatError(message: LocaleValue, params: LocaleValueFnParams): string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,37 @@ | ||
declare module 'yup/es' { | ||
export function addMethod< | ||
TSchemaType extends | ||
| typeof mixed | ||
| typeof string | ||
| typeof number | ||
| typeof boolean | ||
| typeof date | ||
| typeof array | ||
| typeof object, | ||
TSchema extends TSchemaType extends typeof mixed | ||
? MixedSchema | ||
: TSchemaType extends typeof string | ||
? StringSchema | ||
: TSchemaType extends typeof number | ||
? NumberSchema | ||
: TSchemaType extends typeof boolean | ||
? BooleanSchema | ||
: TSchemaType extends typeof date | ||
? DateSchema | ||
: TSchemaType extends typeof array | ||
? ArraySchema | ||
: TSchemaType extends typeof object | ||
? ObjectSchema | ||
: MixedSchema | ||
>( | ||
schemaType: TSchemaType, | ||
name: string, | ||
fn: (this: TSchema, ...args: any[]) => TSchema, | ||
): void | ||
} | ||
import { array, ArraySchema } from './array' | ||
import { boolean, BooleanSchema } from './boolean' | ||
import { date, DateSchema } from './date' | ||
import { mixed, MixedSchema } from './mixed' | ||
import { number, NumberSchema } from './number' | ||
import { object, ObjectSchema } from './object' | ||
import { string, StringSchema } from './string' | ||
|
||
export declare function addMethod< | ||
TSchemaType extends | ||
| typeof mixed | ||
| typeof string | ||
| typeof number | ||
| typeof boolean | ||
| typeof date | ||
| typeof array | ||
| typeof object, | ||
TSchema extends TSchemaType extends typeof mixed | ||
? MixedSchema | ||
: TSchemaType extends typeof string | ||
? StringSchema | ||
: TSchemaType extends typeof number | ||
? NumberSchema | ||
: TSchemaType extends typeof boolean | ||
? BooleanSchema | ||
: TSchemaType extends typeof date | ||
? DateSchema | ||
: TSchemaType extends typeof array | ||
? ArraySchema | ||
: TSchemaType extends typeof object | ||
? ObjectSchema | ||
: MixedSchema, | ||
>( | ||
schemaType: TSchemaType, | ||
name: string, | ||
fn: (this: TSchema, ...args: any[]) => TSchema, | ||
): void |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
declare module 'yup/es' { | ||
export interface ArraySchema<T extends any = any> extends MixedSchema<T[]> { | ||
of(type: GetSchema<T>): this | ||
import { ArrayLocale, MixedLocale } from './Locale' | ||
import { GetSchema, MixedSchema } from './mixed' | ||
import { Ref } from './ref' | ||
|
||
required(message?: MixedLocale['required']): this | ||
export interface ArraySchema<T extends any = any> extends MixedSchema<T[]> { | ||
of(type: GetSchema<T>): this | ||
|
||
min(limit: number | Ref, message?: ArrayLocale['min']): this | ||
required(message?: MixedLocale['required']): this | ||
|
||
max(limit: number | Ref, message?: ArrayLocale['max']): this | ||
min(limit: number | Ref, message?: ArrayLocale['min']): this | ||
|
||
ensure(): this | ||
max(limit: number | Ref, message?: ArrayLocale['max']): this | ||
|
||
compact(rejector: (value: T) => boolean): this | ||
} | ||
ensure(): this | ||
|
||
export function array<T extends any = any>(): ArraySchema<T> | ||
compact(rejector: (value: T) => boolean): this | ||
} | ||
|
||
export declare function array<T extends any = any>(): ArraySchema<T> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
declare module 'yup/es' { | ||
export interface BooleanSchema<T extends boolean = boolean> | ||
extends MixedSchema<T> {} | ||
import { MixedSchema } from './mixed' | ||
|
||
export function boolean<T extends boolean = boolean>(): BooleanSchema<T> | ||
} | ||
export interface BooleanSchema<T extends boolean = boolean> | ||
extends MixedSchema<T> {} | ||
|
||
export declare function boolean<T extends boolean = boolean>(): BooleanSchema<T> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
declare module 'yup/es' { | ||
export interface DateSchema<T extends Date = Date> extends MixedSchema<T> { | ||
min(limit: Date | Ref, message?: DateLocale['min']): this | ||
import { DateLocale } from './Locale' | ||
import { MixedSchema } from './mixed' | ||
import { Ref } from './ref' | ||
|
||
max(limit: Date | Ref, message?: DateLocale['max']): this | ||
} | ||
export interface DateSchema<T extends Date = Date> extends MixedSchema<T> { | ||
min(limit: Date | Ref, message?: DateLocale['min']): this | ||
|
||
export function date<T extends Date = Date>(): DateSchema<T> | ||
max(limit: Date | Ref, message?: DateLocale['max']): this | ||
} | ||
|
||
export declare function date<T extends Date = Date>(): DateSchema<T> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
declare module 'yup/es' { | ||
export function getLocale(): Locale | ||
} | ||
import { Locale } from './Locale' | ||
|
||
export declare function getLocale(): Locale |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
// @index('./*.ts', f => `import '${f.path}'`) | ||
import './addMethod' | ||
import './array' | ||
import './boolean' | ||
import './date' | ||
import './getLocale' | ||
import './lazy' | ||
import './Locale' | ||
import './mixed' | ||
import './number' | ||
import './object' | ||
import './printValue' | ||
import './reach' | ||
import './ref' | ||
import './setLocale' | ||
import './string' | ||
import './ValidationError' | ||
// @index('./*.ts', f => `export * from '${f.path}'`) | ||
export * from './addMethod' | ||
export * from './array' | ||
export * from './boolean' | ||
export * from './date' | ||
export * from './getLocale' | ||
export * from './lazy' | ||
export * from './Locale' | ||
export * from './mixed' | ||
export * from './number' | ||
export * from './object' | ||
export * from './printValue' | ||
export * from './reach' | ||
export * from './ref' | ||
export * from './setLocale' | ||
export * from './string' | ||
export * from './ValidationError' | ||
// @endindex |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
declare module 'yup/es' { | ||
export interface Lazy extends MixedSchema {} | ||
import { MixedSchema } from './mixed' | ||
|
||
export function lazy<X extends MixedSchema>(fn: (value: any) => X): Lazy | ||
} | ||
export interface Lazy extends MixedSchema {} | ||
|
||
export declare function lazy<X extends MixedSchema>(fn: (value: any) => X): Lazy |
Oops, something went wrong.