@gucciogucci/contented
Advanced tools
Comparing version 3.0.0 to 3.1.0
@@ -10,2 +10,3 @@ export * from './always'; | ||
export * from './object'; | ||
export * from './oneOf'; | ||
export * from './permissiveArrayOf'; | ||
@@ -12,0 +13,0 @@ export * from './satisfy'; |
@@ -23,2 +23,3 @@ "use strict"; | ||
__exportStar(require("./object"), exports); | ||
__exportStar(require("./oneOf"), exports); | ||
__exportStar(require("./permissiveArrayOf"), exports); | ||
@@ -25,0 +26,0 @@ __exportStar(require("./satisfy"), exports); |
@@ -16,3 +16,3 @@ import { ContentedError } from './ContentedError'; | ||
export declare type ErrorType<T> = T extends Type<any, infer E> ? E : never; | ||
declare type OrErrors<E, F> = EnumerateErrors<StripJoint<E>, StripJoint<F>> extends never ? never : Joint<EnumerateErrors<StripJoint<E>, StripJoint<F>>>; | ||
export declare type OrErrors<E, F> = EnumerateErrors<StripJoint<E>, StripJoint<F>> extends never ? never : Joint<EnumerateErrors<StripJoint<E>, StripJoint<F>>>; | ||
declare type EnumerateErrors<E, F> = E extends never ? never : F extends never ? never : E extends unknown[] ? F extends unknown[] ? [...E, ...F] : [...E, F] : F extends unknown[] ? [E, ...F] : [E, F]; | ||
@@ -19,0 +19,0 @@ declare type StripJoint<T> = T extends Joint<infer U> ? U : T; |
{ | ||
"name": "@gucciogucci/contented", | ||
"description": "A library to coerce values at run-time.", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"author": "Gucci <npm@gucci.com>", | ||
@@ -6,0 +6,0 @@ "license": "LGPL-3.0-only", |
@@ -41,2 +41,3 @@ <div align="center"> | ||
- [`T1.or(T2)`](#t1ort2) | ||
- [`oneOf(...Ts)`](#oneofts) | ||
- [Errors](#errors) | ||
@@ -378,2 +379,26 @@ - [`InvalidCoercion`](#invalidcoercion) | ||
#### `oneOf(...Ts)` | ||
Repeated applications of `T1.or(T2)` may produce a significant amount of syntactic noise. By contrast, `oneOf` may produce better results in situations where more than two or three alternatives are needed. | ||
```typescript | ||
import { oneOf, match, coerceTo } from '@gucciogucci/contented'; | ||
const abc = oneOf(match('a'), match('b'), match('c')); // the same as match('a').or(match('b')).or(match('c')) | ||
coerceTo(abc, 'a'); | ||
// 'a' | ||
coerceTo(abc, 'd'); | ||
/* Joint { | ||
errors: [ | ||
InvalidCoercion { expected: 'a', got: 'd' }, | ||
InvalidCoercion { expected: 'b', got: 'd' }, | ||
InvalidCoercion { expected: 'c', got: 'd' } | ||
] | ||
} | ||
*/ | ||
``` | ||
### Errors | ||
@@ -380,0 +405,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
54964
51
720
484