@blacklane/sarcastic
Advanced tools
Comparing version 1.5.0 to 1.5.1
@@ -5,3 +5,3 @@ 'use strict'; | ||
/*:: | ||
type Assertion<T> = (val: mixed, name: string) => T; | ||
export type Assertion<T> = (val: mixed, name: string) => T; | ||
type AssertionMap = { [key: string]: Assertion<any> }; | ||
@@ -8,0 +8,0 @@ type ExtractAssertionType = <T>(Assertion<T>) => T; |
{ | ||
"name": "@blacklane/sarcastic", | ||
"version": "1.5.0", | ||
"version": "1.5.1", | ||
"description": "Cast unknown values to typed values", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -203,10 +203,22 @@ # Sarcastic | ||
```js | ||
(is('a', is.literal/*::<'a'> */('a')) // returns 'a' | ||
is(42, is.literal/*::<'a'> */('a'), '42') // throws instanceof is.AssertionError | ||
is('a', is.literal('a')) // returns 'a' | ||
is(42, is.literal('a')) // throws instanceof is.AssertionError | ||
``` | ||
**With strict typing:** | ||
```js | ||
let literalAssetion = is.literal<'a'>('a'); | ||
// or if syntax above doesn't work due to JSX, Prettier, ESLint etc | ||
import { type Assertion } from 'sarcastic'; | ||
let literalAssetion: Assertion<'a'> = is.literal('a'); | ||
is('a', literalAssetion) // returns 'a' | ||
is(42, is.literal<'a'>('a')) // throws instanceof is.AssertionError | ||
``` | ||
### `is.literals(arrayOfStringLiterals)` | ||
```js | ||
let literalsAssertion = is.literals/*::<'a'|'b'|'c'>*/([ | ||
let literalsAssertion = is.literals([ | ||
'a', 'b', 'c' | ||
@@ -219,1 +231,18 @@ ]); | ||
``` | ||
**With strict typing:** | ||
```js | ||
let literalsAssertion = is.literals<'a'|'b'|'c'>([ | ||
'a', 'b', 'c' | ||
]); | ||
// or if syntax above doesn't work due to JSX, Prettier, ESLint etc | ||
import { type Assertion } from 'sarcastic'; | ||
let literalsAssertion: Assertion<'a'|'b'|'c'> = is.literals<'a'|'b'|'c'>([ | ||
'a', 'b', 'c' | ||
]); | ||
is('a', literalsAssertion) // returns 'a' | ||
is('b', literalsAssertion) // returns 'b' | ||
is('c', literalsAssertion) // returns 'c' | ||
is(42, literalsAssertion) // throws instanceof is.AssertionError | ||
``` |
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
13016
247