-
Notifications
You must be signed in to change notification settings - Fork 0
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
48 changed files
with
224 additions
and
215 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
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
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
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
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,14 +1,18 @@ | ||
import type { Assertion } from "@the-minimal/types"; | ||
import type { FakeAssertion, InferAssertionValues, Intersection } from "@types"; | ||
import type { Validation } from "@the-minimal/types"; | ||
import type { | ||
FakeValidation, | ||
InferValidationValues, | ||
Intersection, | ||
} from "@types"; | ||
|
||
export const and = <$Assertions extends Array<Assertion<unknown>>>( | ||
fns: $Assertions, | ||
): Assertion<Intersection<InferAssertionValues<$Assertions>>> => { | ||
export const and = <$Validations extends Array<Validation<unknown>>>( | ||
fns: $Validations, | ||
) => { | ||
const length = fns.length; | ||
|
||
return (value) => { | ||
return ((value) => { | ||
for (let i = 0; i < length; ++i) { | ||
(fns[i] as FakeAssertion)(value); | ||
(fns[i] as FakeValidation)(value); | ||
} | ||
}; | ||
}) as Validation<Intersection<InferValidationValues<$Validations>>>; | ||
}; |
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,11 +1,10 @@ | ||
import type { Assertion } from "@the-minimal/types"; | ||
import type { Validation } from "@the-minimal/types"; | ||
|
||
export const and2 = <$Value1, $Value2>( | ||
fn1: Assertion<$Value1>, | ||
fn2: Assertion<$Value2>, | ||
): Assertion<$Value1 & $Value2> => { | ||
return (value: unknown) => { | ||
fn1: Validation<$Value1>, | ||
fn2: Validation<$Value2>, | ||
) => | ||
((value: unknown) => { | ||
fn1(value); | ||
fn2(value); | ||
}; | ||
}; | ||
}) as Validation<$Value1 & $Value2>; |
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,13 +1,12 @@ | ||
import type { Assertion } from "@the-minimal/types"; | ||
import type { Validation } from "@the-minimal/types"; | ||
|
||
export const and3 = <$Value1, $Value2, $Value3>( | ||
fn1: Assertion<$Value1>, | ||
fn2: Assertion<$Value2>, | ||
fn3: Assertion<$Value3>, | ||
): Assertion<$Value1 & $Value2 & $Value3> => { | ||
return (value: unknown) => { | ||
fn1: Validation<$Value1>, | ||
fn2: Validation<$Value2>, | ||
fn3: Validation<$Value3>, | ||
) => | ||
((value: unknown) => { | ||
fn1(value); | ||
fn2(value); | ||
fn3(value); | ||
}; | ||
}; | ||
}) as Validation<$Value1 & $Value2 & $Value3>; |
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 @@ | ||
import type { Assertion } from "@the-minimal/types"; | ||
import type { Validation } from "@the-minimal/types"; | ||
|
||
export const any: Assertion<any> = () => {}; | ||
export const any = (() => {}) as Validation<any>; |
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,12 +1,11 @@ | ||
import type { Assertion } from "@the-minimal/types"; | ||
import type { Validation } from "@the-minimal/types"; | ||
import { isArray } from "@validators/isArray"; | ||
|
||
export const array = | ||
<$Value>(fn: Assertion<$Value>): Assertion<Array<$Value>> => | ||
(value) => { | ||
export const array = <$Value>(fn: Validation<$Value>) => | ||
((value) => { | ||
isArray(value); | ||
|
||
for (let i = 0; i < (value as unknown[]).length; ++i) { | ||
fn(value[i]); | ||
fn((value as any)[i]); | ||
} | ||
}; | ||
}) as Validation<Array<$Value>>; |
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,4 @@ | ||
import { REGEX_EMAIL } from "@constants"; | ||
import type { Assertion } from "@the-minimal/types"; | ||
import { regex } from "@validators/regex"; | ||
|
||
export const email: Assertion<string> = regex(REGEX_EMAIL); | ||
export const email = regex(REGEX_EMAIL); |
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,4 @@ | ||
import type { Assertion } from "@the-minimal/types"; | ||
import { assert } from "@validators/assert"; | ||
import { validate } from "@validators/validate"; | ||
|
||
export const endsWith = (value: string): Assertion<string> => | ||
assert((v) => (v as string).endsWith(value), "endsWith", value); | ||
export const endsWith = (value: string) => | ||
validate<string>((v) => (v as string).endsWith(value), "endsWith", value); |
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
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,9 @@ | ||
import type { Assertion } from "@the-minimal/types"; | ||
import { assert } from "@validators/assert"; | ||
import type { Validation } from "@the-minimal/types"; | ||
import { validate } from "@validators/validate"; | ||
|
||
export const includes = (value: string): Assertion<string | unknown[]> => | ||
assert((v) => (v as string | unknown[]).includes(value), "includes", value); | ||
export const includes = (value: string) => | ||
validate<string | unknown[]>( | ||
(v) => (v as string | unknown[]).includes(value), | ||
"includes", | ||
value, | ||
); |
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
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 @@ | ||
import type { Assertion, Class } from "@the-minimal/types"; | ||
import { assert } from "@validators/assert"; | ||
import type { Class, Validation } from "@the-minimal/types"; | ||
import { validate } from "@validators/validate"; | ||
|
||
export const instance = <$Type>(cls: Class<$Type>): Assertion<$Type> => | ||
assert((value) => value instanceof cls, "instance", cls); | ||
export const instance = <$Type>(cls: Class<$Type>) => | ||
validate<$Type>((value) => value instanceof cls, "instance", cls); |
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,4 @@ | ||
import type { Assertion } from "@the-minimal/types"; | ||
import { assert } from "@validators/assert"; | ||
import type { Validation } from "@the-minimal/types"; | ||
import { validate } from "@validators/validate"; | ||
|
||
export const integer: Assertion<number> = assert(Number.isInteger, "integer"); | ||
export const integer = validate<number>(Number.isInteger, "integer"); |
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,7 +1,4 @@ | ||
import type { Assertion } from "@the-minimal/types"; | ||
import { assert } from "@validators/assert"; | ||
import type { Validation } from "@the-minimal/types"; | ||
import { validate } from "@validators/validate"; | ||
|
||
export const isArray: Assertion<Array<unknown>> = assert( | ||
Array.isArray, | ||
"isArray", | ||
); | ||
export const isArray = validate<Array<unknown>>(Array.isArray, "isArray"); |
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,8 +1,7 @@ | ||
import type { Assertion } from "@the-minimal/types"; | ||
import type { ObjectUnknown } from "@types"; | ||
import { assert } from "@validators/assert"; | ||
import { validate } from "@validators/validate"; | ||
|
||
export const isObject: Assertion<ObjectUnknown> = assert( | ||
export const isObject = validate<ObjectUnknown>( | ||
(v) => v !== null && typeof v === "object", | ||
"isObject", | ||
); |
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,9 @@ | ||
import type { Assertion } from "@the-minimal/types"; | ||
import type { FakeAssertion } from "@types"; | ||
import type { Validation } from "@the-minimal/types"; | ||
import type { FakeValidation } from "@types"; | ||
|
||
export const lazy = <$Assertion extends Assertion<unknown>>( | ||
fn: (value: unknown) => $Assertion, | ||
export const lazy = <$Validation extends Validation<unknown>>( | ||
fn: (value: unknown) => $Validation, | ||
) => | ||
((value: unknown) => { | ||
(fn(value) as FakeAssertion)(value); | ||
}) as $Assertion; | ||
(fn(value) as FakeValidation)(value); | ||
}) as $Validation; |
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
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,9 @@ | ||
import type { Assertion } from "@the-minimal/types"; | ||
import { assert } from "@validators/assert"; | ||
import type { Validation } from "@the-minimal/types"; | ||
import { validate } from "@validators/validate"; | ||
|
||
export const length = (value: number): Assertion<string | unknown[]> => | ||
assert((v) => (v as string | unknown[]).length === value, "length", value); | ||
export const length = (value: number) => | ||
validate<string | unknown[]>( | ||
(v) => (v as string | unknown[]).length === value, | ||
"length", | ||
value, | ||
); |
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,9 @@ | ||
import type { Assertion } from "@the-minimal/types"; | ||
import { assert } from "@validators/assert"; | ||
import type { Validation } from "@the-minimal/types"; | ||
import { validate } from "@validators/validate"; | ||
|
||
export const maxLength = (value: number): Assertion<string | unknown[]> => | ||
assert((v) => (v as string | unknown[]).length <= value, "maxLength", value); | ||
export const maxLength = (value: number) => | ||
validate<string | unknown[]>( | ||
(v) => (v as string | unknown[]).length <= value, | ||
"maxLength", | ||
value, | ||
); |
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 @@ | ||
import type { Assertion } from "@the-minimal/types"; | ||
import { assert } from "@validators/assert"; | ||
import type { Validation } from "@the-minimal/types"; | ||
import { validate } from "@validators/validate"; | ||
|
||
export const maxValue = (value: number): Assertion<any> => | ||
assert((v) => (v as any) <= value, "maxValue", value); | ||
export const maxValue = (value: number) => | ||
validate<unknown>((v) => (v as any) <= value, "maxValue", value); |
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,9 @@ | ||
import type { Assertion } from "@the-minimal/types"; | ||
import { assert } from "@validators/assert"; | ||
import type { Validation } from "@the-minimal/types"; | ||
import { validate } from "@validators/validate"; | ||
|
||
export const minLength = (value: number): Assertion<string | unknown[]> => | ||
assert((v) => (v as string | unknown[]).length >= value, "minLength", value); | ||
export const minLength = (value: number) => | ||
validate<string | unknown[]>( | ||
(v) => (v as string | unknown[]).length >= value, | ||
"minLength", | ||
value, | ||
); |
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 @@ | ||
import type { Assertion } from "@the-minimal/types"; | ||
import { assert } from "@validators/assert"; | ||
import type { Validation } from "@the-minimal/types"; | ||
import { validate } from "@validators/validate"; | ||
|
||
export const minValue = (value: number): Assertion<any> => | ||
assert((v) => (v as any) >= value, "minValue", value); | ||
export const minValue = (value: number) => | ||
validate<unknown>((v) => (v as any) >= value, "minValue", value); |
Oops, something went wrong.