-
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.
feat: screw that let's make it simple again
- Loading branch information
Showing
76 changed files
with
325 additions
and
697 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import type { AndSchema, Validate } from "@assertions/and/types"; | ||
import type { Assertion } from "@the-minimal/types"; | ||
import type { Intersection } from "./types"; | ||
|
||
/** | ||
* Checks if all the assertions pass. | ||
|
@@ -18,9 +19,14 @@ import type { AndSchema, Validate } from "@assertions/and/types"; | |
* userEmail("[email protected]"); // passes | ||
* ``` | ||
*/ | ||
export const and = <const $Schema extends AndSchema>(assertions: $Schema) => | ||
((v: unknown) => { | ||
export const and = | ||
<const $Values extends unknown[]>( | ||
assertions: { | ||
[$Key in keyof $Values]: Assertion<$Values[$Key]>; | ||
}, | ||
): Assertion<Intersection<$Values>> => | ||
(v: unknown) => { | ||
for (let i = 0; i < assertions.length; ++i) { | ||
((assertions as any)[i] as any)(v); | ||
(assertions[i] as any)(v); | ||
} | ||
}) as unknown as Validate.And<$Schema>; | ||
}; |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// TODO: move into @the-minimal/types | ||
export type Intersection<$Values extends unknown[]> = $Values extends [ | ||
infer $Head, | ||
...infer $Tail, | ||
] | ||
? $Tail extends [infer _1, ...infer _2] | ||
? $Head & Intersection<$Tail> | ||
: $Head | ||
: never; |
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,8 @@ | ||
import type { Validate } from "@assertions/and/types"; | ||
import type { AnyBrand } from "@the-minimal/types"; | ||
import type { | ||
Assertion, | ||
InferAssertion, | ||
UnknownAssertion, | ||
} from "@the-minimal/types"; | ||
|
||
/** | ||
* Checks that both assertions pass. | ||
|
@@ -16,11 +19,12 @@ import type { AnyBrand } from "@the-minimal/types"; | |
* userEmail("[email protected]"); // passes | ||
* ``` | ||
*/ | ||
export const and2 = <$Brand1 extends AnyBrand, $Brand2 extends AnyBrand>( | ||
brand1: $Brand1, | ||
brand2: $Brand2, | ||
) => | ||
((v: unknown) => { | ||
(brand1 as any)(v); | ||
(brand2 as any)(v); | ||
}) as unknown as Validate.And<[$Brand1, $Brand2]>; | ||
export const and2 = | ||
<$Assertion1 extends UnknownAssertion, $Assertion2 extends UnknownAssertion>( | ||
assertion1: $Assertion1, | ||
assertion2: $Assertion2, | ||
): Assertion<InferAssertion<$Assertion1> & InferAssertion<$Assertion2>> => | ||
(v: unknown) => { | ||
assertion1(v); | ||
assertion2(v); | ||
}; |
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,8 @@ | ||
import type { Validate } from "@assertions/and/types"; | ||
import type { AnyBrand } from "@the-minimal/types"; | ||
import type { | ||
Assertion, | ||
InferAssertion, | ||
UnknownAssertion, | ||
} from "@the-minimal/types"; | ||
|
||
/** | ||
* Checks that all three assertions pass. | ||
|
@@ -18,17 +21,22 @@ import type { AnyBrand } from "@the-minimal/types"; | |
* userEmail("[email protected]"); // passes | ||
* ``` | ||
*/ | ||
export const and3 = < | ||
$Brand1 extends AnyBrand, | ||
$Brand2 extends AnyBrand, | ||
$Brand3 extends AnyBrand, | ||
>( | ||
brand1: $Brand1, | ||
brand2: $Brand2, | ||
brand3: $Brand3, | ||
) => | ||
((v: unknown) => { | ||
(brand1 as any)(v); | ||
(brand2 as any)(v); | ||
(brand3 as any)(v); | ||
}) as unknown as Validate.And<[$Brand1, $Brand2, $Brand3]>; | ||
export const and3 = | ||
< | ||
$Assertion1 extends UnknownAssertion, | ||
$Assertion2 extends UnknownAssertion, | ||
$Assertion3 extends UnknownAssertion, | ||
>( | ||
assertion1: $Assertion1, | ||
assertion2: $Assertion2, | ||
assertion3: $Assertion3, | ||
): Assertion< | ||
InferAssertion<$Assertion1> & | ||
InferAssertion<$Assertion2> & | ||
InferAssertion<$Assertion3> | ||
> => | ||
(v: unknown) => { | ||
assertion1(v); | ||
assertion2(v); | ||
assertion3(v); | ||
}; |
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 was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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 } from "@assertions/regex"; | ||
import type { Validate } from "./types"; | ||
|
||
/** | ||
* Checks if value matches email RegExp. | ||
|
@@ -10,4 +9,4 @@ import type { Validate } from "./types"; | |
* email("[email protected]"); // passes | ||
* ``` | ||
*/ | ||
export const email = regex(/^\w+@.+\..+$/) as Validate.Regex.Email; | ||
export const email = regex(/^\w+@.+\..+$/); |
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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
Oops, something went wrong.