Skip to content

Commit cfa958b

Browse files
chore: exported more types
1 parent edb8773 commit cfa958b

File tree

16 files changed

+43
-28
lines changed

16 files changed

+43
-28
lines changed

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ export * from './config'
22
// Export validator library
33
export { default as validator } from './lib'
44
export * from './types'
5-
65
export { v } from './validation'
6+
7+
export * from './validators'

src/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ export interface NormalizeEmailOptions {
246246
}
247247

248248
export interface Validator<T> {
249-
name: 'string' | 'number' | 'array' | 'boolean' | 'enum' | 'date' | 'datetime' | 'object' | 'custom' | 'timestamp' | 'unix' | 'password'
249+
name: ValidationNames
250250
test: (value: T) => boolean
251251
validate: (value: T) => ValidationResult
252252
required: () => Validator<T>
@@ -358,3 +358,5 @@ export interface ValidationInstance {
358358
export type ValidationType = StringValidatorType | NumberValidatorType | ArrayValidatorType<any> | BooleanValidatorType | EnumValidatorType<any> | DateValidatorType | DatetimeValidatorType | ObjectValidatorType<any> | CustomValidatorType<any> | TimestampValidatorType | UnixValidatorType | PasswordValidatorType
359359

360360
export type Infer<T> = T extends Validator<infer U> ? U : never
361+
362+
export type ValidationNames = 'base' | 'string' | 'number' | 'array' | 'boolean' | 'enum' | 'date' | 'datetime' | 'object' | 'custom' | 'timestamp' | 'unix' | 'password'

src/validators/arrays.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import type { ArrayValidatorType, Validator } from '../types'
1+
import type { ArrayValidatorType, ValidationNames, Validator } from '../types'
22
import { BaseValidator } from './base'
33

44
export class ArrayValidator<T> extends BaseValidator<T[]> implements ArrayValidatorType<T> {
5-
public name: string = 'array'
5+
public name: ValidationNames = 'array'
66

77
constructor() {
88
super()

src/validators/base.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import type { ValidationError, ValidationErrorMap, ValidationResult, ValidationRule } from '../types'
1+
import type { ValidationError, ValidationErrorMap, ValidationNames, ValidationResult, ValidationRule } from '../types'
22

33
export abstract class BaseValidator<T> {
44
protected rules: ValidationRule<T>[] = []
55
protected isRequired = true
66
protected fieldName = 'value'
77
protected isPartOfShape = false
8-
public name: string = 'base'
8+
public name: ValidationNames = 'base'
99

1010
required(): this {
1111
this.isRequired = true

src/validators/booleans.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import type { BooleanValidatorType } from '../types'
1+
import type { BooleanValidatorType, ValidationNames } from '../types'
22
import { BaseValidator } from './base'
33

44
export class BooleanValidator extends BaseValidator<boolean> implements BooleanValidatorType {
5-
public name: string = 'boolean'
5+
public name: ValidationNames = 'boolean'
66

77
constructor() {
88
super()

src/validators/custom.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import type { CustomValidatorType } from '../types'
1+
import type { CustomValidatorType, ValidationNames } from '../types'
22
import { BaseValidator } from './base'
33

44
export class CustomValidator<T> extends BaseValidator<T> implements CustomValidatorType<T> {
5-
public name: string = 'custom'
5+
public name: ValidationNames = 'custom'
66

77
constructor(validationFn: (value: T) => boolean, message: string) {
88
super()

src/validators/dates.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import type { DateValidatorType } from '../types'
1+
import type { DateValidatorType, ValidationNames } from '../types'
22
import { BaseValidator } from './base'
33

44
export class DateValidator extends BaseValidator<Date> implements DateValidatorType {
5-
public name: string = 'date'
5+
public name: ValidationNames = 'date'
66

77
constructor() {
88
super()

src/validators/datetimes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import type { DatetimeValidatorType } from '../types'
1+
import type { DatetimeValidatorType, ValidationNames } from '../types'
22
import { BaseValidator } from './base'
33

44
export class DatetimeValidator extends BaseValidator<Date> implements DatetimeValidatorType {
5-
public name: string = 'datetime'
5+
public name: ValidationNames = 'datetime'
66

77
constructor() {
88
super()

src/validators/enums.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import type { EnumValidatorType } from '../types'
1+
import type { EnumValidatorType, ValidationNames } from '../types'
22
import { BaseValidator } from './base'
33

44
export class EnumValidator<T extends string | number> extends BaseValidator<T> implements EnumValidatorType<T> {
5-
public name: string = 'enum'
5+
public name: ValidationNames = 'enum'
66

77
private allowedValues: readonly T[]
88

src/validators/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export * from './arrays'
2+
export * from './booleans'
3+
export * from './custom'
4+
export * from './dates'
5+
export * from './datetimes'
6+
export * from './enums'
7+
export * from './numbers'
8+
export * from './objects'
9+
export * from './password'
10+
export * from './strings'
11+
export * from './timestamps'
12+
export * from './unix'

0 commit comments

Comments
 (0)