Skip to content

Commit e6b06d3

Browse files
feat: types
1 parent bdbafd5 commit e6b06d3

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

src/types.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
import type { alphanumeric } from './lib/isAlphanumeric'
2+
import type { ArrayValidator } from './validators/arrays'
3+
import type { BooleanValidator } from './validators/booleans'
4+
import type { CustomValidator } from './validators/custom'
5+
import type { DateValidator } from './validators/dates'
6+
import type { EnumValidator } from './validators/enums'
7+
import type { NumberValidator } from './validators/numbers'
8+
import type { ObjectValidator } from './validators/objects'
9+
import type { StringValidator } from './validators/strings'
210

311
export interface ValidationError {
412
message: string
@@ -235,3 +243,14 @@ export interface ValidationConfig {
235243
cacheResults?: boolean
236244
errorMessages?: Record<string, string>
237245
}
246+
247+
export interface ValidationInstance {
248+
string: () => StringValidator
249+
number: () => NumberValidator
250+
array: <T>() => ArrayValidator<T>
251+
boolean: () => BooleanValidator
252+
enum: <T extends string | number>(values: readonly T[]) => EnumValidator<T>
253+
date: () => DateValidator
254+
object: <T extends Record<string, any>>() => ObjectValidator<T>
255+
custom: <T>(validationFn: (value: T) => boolean, message: string) => CustomValidator<T>
256+
}

src/validation.ts

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
import type { ArrayValidator } from './validators/arrays'
2-
import type { BooleanValidator } from './validators/booleans'
3-
import type { CustomValidator } from './validators/custom'
4-
import type { DateValidator } from './validators/dates'
5-
import type { EnumValidator } from './validators/enums'
6-
import type { NumberValidator } from './validators/numbers'
7-
import type { ObjectValidator } from './validators/objects'
8-
import type { StringValidator } from './validators/strings'
9-
1+
import type { ValidationInstance } from './types'
102
import { array } from './validators/arrays'
113
import { boolean } from './validators/booleans'
124
import { custom } from './validators/custom'
@@ -16,18 +8,7 @@ import { number } from './validators/numbers'
168
import { object } from './validators/objects'
179
import { string } from './validators/strings'
1810

19-
interface Validator {
20-
string: () => StringValidator
21-
number: () => NumberValidator
22-
array: <T>() => ArrayValidator<T>
23-
boolean: () => BooleanValidator
24-
enum: <T extends string | number>(values: readonly T[]) => EnumValidator<T>
25-
date: () => DateValidator
26-
object: <T extends Record<string, any>>() => ObjectValidator<T>
27-
custom: <T>(validationFn: (value: T) => boolean, message: string) => CustomValidator<T>
28-
}
29-
30-
export const v: Validator = {
11+
export const v: ValidationInstance = {
3112
string,
3213
number,
3314
array,

0 commit comments

Comments
 (0)