validation.ts
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -7,2 +7,4 @@ import { Result, Ok, Err } from 'space-lift/result'; | ||
filter(fn: (value: T) => boolean): Validator<T>; | ||
tagged<TAG extends string>(this: Validator<string>): Validator<TAG>; | ||
tagged<TAG extends number>(this: Validator<number>): Validator<TAG>; | ||
} | ||
@@ -9,0 +11,0 @@ export declare type Any = Validator<Object>; |
@@ -34,2 +34,5 @@ "use strict"; | ||
}; | ||
Validator.prototype.tagged = function () { | ||
return this; | ||
}; | ||
return Validator; | ||
@@ -36,0 +39,0 @@ }()); |
{ | ||
"name": "validation.ts", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "Validation for TypeScript", | ||
@@ -5,0 +5,0 @@ "main": "lib/validation.js", |
@@ -51,2 +51,14 @@ # validation.ts | ||
### tagged primitive | ||
Sometimes, a `string` or a `number` is not just any string or number but carry extra meaning, e.g: `email`, `uuid`, `userId`, `KiloGram`, etc. | ||
Tagging such a primitive as it's validated can help make the downstream code more robust. | ||
```ts | ||
type UserId = string & { __tag: 'UserId' } // Note: You can use any naming convention for the tag. | ||
const userIdValidator = v.string.tagged<UserId>() | ||
``` | ||
## literal | ||
@@ -53,0 +65,0 @@ |
28485
606
171