Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

typed-assert

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typed-assert - npm Package Compare versions

Comparing version 1.0.7 to 1.0.8

746

API.md

@@ -5,36 +5,37 @@ typed-assert

## Index
## Table of contents
### Type aliases
* [Assert](API.md#assert)
* [Check](API.md#check)
* [SubType](API.md#subtype)
* [WeakAssert](API.md#weakassert)
- [Assert](API.md#assert)
- [Check](API.md#check)
- [SubType](API.md#subtype)
- [WeakAssert](API.md#weakassert)
### Functions
* [assert](API.md#assert)
* [check](API.md#check)
* [defaultAssert](API.md#defaultassert)
* [isArray](API.md#isarray)
* [isArrayOfType](API.md#isarrayoftype)
* [isBoolean](API.md#isboolean)
* [isDate](API.md#isdate)
* [isExactly](API.md#isexactly)
* [isInstanceOf](API.md#isinstanceof)
* [isNotNull](API.md#isnotnull)
* [isNotUndefined](API.md#isnotundefined)
* [isNumber](API.md#isnumber)
* [isOneOf](API.md#isoneof)
* [isOneOfType](API.md#isoneoftype)
* [isOptionOfType](API.md#isoptionoftype)
* [isPromise](API.md#ispromise)
* [isRecord](API.md#isrecord)
* [isRecordOfType](API.md#isrecordoftype)
* [isRecordWithKeys](API.md#isrecordwithkeys)
* [isString](API.md#isstring)
* [isUnknown](API.md#isunknown)
* [safeJsonParse](API.md#safejsonparse)
* [setBaseAssert](API.md#setbaseassert)
- [assert](API.md#assert)
- [check](API.md#check)
- [defaultAssert](API.md#defaultassert)
- [isArray](API.md#isarray)
- [isArrayOfType](API.md#isarrayoftype)
- [isBoolean](API.md#isboolean)
- [isDate](API.md#isdate)
- [isExactly](API.md#isexactly)
- [isInstanceOf](API.md#isinstanceof)
- [isNever](API.md#isnever)
- [isNotNull](API.md#isnotnull)
- [isNotUndefined](API.md#isnotundefined)
- [isNumber](API.md#isnumber)
- [isOneOf](API.md#isoneof)
- [isOneOfType](API.md#isoneoftype)
- [isOptionOfType](API.md#isoptionoftype)
- [isPromise](API.md#ispromise)
- [isRecord](API.md#isrecord)
- [isRecordOfType](API.md#isrecordoftype)
- [isRecordWithKeys](API.md#isrecordwithkeys)
- [isString](API.md#isstring)
- [isUnknown](API.md#isunknown)
- [safeJsonParse](API.md#safejsonparse)
- [setBaseAssert](API.md#setbaseassert)

@@ -45,13 +46,30 @@ ## Type aliases

Ƭ **Assert**<Input, Output\>: (`input`: Input, `message?`: *string*) => asserts input is SubType<Input, Output\>
Ƭ **Assert**<`Input`, `Output`\>: (`input`: `Input`, `message?`: `string`) => asserts input is SubType<Input, Output\>
#### Type parameters:
#### Type parameters
Name | Default |
------ | ------ |
`Input` | *unknown* |
`Output` | Input |
| Name | Type |
| :------ | :------ |
| `Input` | `unknown` |
| `Output` | `Input` |
Defined in: [index.ts:7](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L7)
#### Type declaration
▸ (`input`, `message?`): asserts input is SubType<Input, Output\>
##### Parameters
| Name | Type |
| :------ | :------ |
| `input` | `Input` |
| `message?` | `string` |
##### Returns
asserts input is SubType<Input, Output\>
#### Defined in
[index.ts:7](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L7)
___

@@ -61,13 +79,29 @@

Ƭ **Check**<Input, Output\>: (`input`: Input) => input is SubType<Input, Output\>
Ƭ **Check**<`Input`, `Output`\>: (`input`: `Input`) => input is SubType<Input, Output\>
#### Type parameters:
#### Type parameters
Name | Default |
------ | ------ |
`Input` | *unknown* |
`Output` | Input |
| Name | Type |
| :------ | :------ |
| `Input` | `unknown` |
| `Output` | `Input` |
Defined in: [index.ts:12](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L12)
#### Type declaration
▸ (`input`): input is SubType<Input, Output\>
##### Parameters
| Name | Type |
| :------ | :------ |
| `input` | `Input` |
##### Returns
input is SubType<Input, Output\>
#### Defined in
[index.ts:12](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L12)
___

@@ -77,13 +111,15 @@

Ƭ **SubType**<Input, Output\>: Output *extends* Input ? Output : *never*
Ƭ **SubType**<`Input`, `Output`\>: `Output` extends `Input` ? `Output` : `never`
#### Type parameters:
#### Type parameters
Name |
------ |
`Input` |
`Output` |
| Name |
| :------ |
| `Input` |
| `Output` |
Defined in: [index.ts:5](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L5)
#### Defined in
[index.ts:5](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L5)
___

@@ -93,6 +129,23 @@

Ƭ **WeakAssert**: (`input`: *unknown*, `message?`: *string*) => *void*
Ƭ **WeakAssert**: (`input`: `unknown`, `message?`: `string`) => `void`
Defined in: [index.ts:3](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L3)
#### Type declaration
▸ (`input`, `message?`): `void`
##### Parameters
| Name | Type |
| :------ | :------ |
| `input` | `unknown` |
| `message?` | `string` |
##### Returns
`void`
#### Defined in
[index.ts:3](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L3)
## Functions

@@ -102,15 +155,19 @@

▸ `Const`**assert**(`input`: *boolean*, `message?`: *string*): asserts input is true
▸ `Const` **assert**(`input`, `message?`): asserts input is true
#### Parameters:
#### Parameters
Name | Type |
------ | ------ |
`input` | *boolean* |
`message?` | *string* |
| Name | Type |
| :------ | :------ |
| `input` | `boolean` |
| `message?` | `string` |
**Returns:** asserts input is true
#### Returns
Defined in: [index.ts:24](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L24)
asserts input is true
#### Defined in
[index.ts:24](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L24)
___

@@ -120,21 +177,25 @@

▸ **check**<Input, Output\>(`assertT`: [*Assert*](API.md#assert)<Input, Output\>): [*Check*](README.md#check)<Input, Output\>
▸ **check**<`Input`, `Output`\>(`assertT`): [`Check`](API.md#check)<`Input`, `Output`\>
#### Type parameters:
#### Type parameters
Name |
------ |
`Input` |
`Output` |
| Name |
| :------ |
| `Input` |
| `Output` |
#### Parameters:
#### Parameters
Name | Type |
------ | ------ |
`assertT` | [*Assert*](API.md#assert)<Input, Output\> |
| Name | Type |
| :------ | :------ |
| `assertT` | [`Assert`](API.md#assert)<`Input`, `Output`\> |
**Returns:** [*Check*](API.md#check)<Input, Output\>
#### Returns
Defined in: [index.ts:195](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L195)
[`Check`](API.md#check)<`Input`, `Output`\>
#### Defined in
[index.ts:202](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L202)
___

@@ -144,15 +205,19 @@

▸ `Const`**defaultAssert**(`input`: *unknown*, `message?`: *string*): *void*
▸ `Const` **defaultAssert**(`input`, `message?`): `void`
#### Parameters:
#### Parameters
Name | Type |
------ | ------ |
`input` | *unknown* |
`message?` | *string* |
| Name | Type |
| :------ | :------ |
| `input` | `unknown` |
| `message?` | `string` |
**Returns:** *void*
#### Returns
Defined in: [index.ts:16](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L16)
`void`
#### Defined in
[index.ts:16](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L16)
___

@@ -162,15 +227,19 @@

▸ **isArray**(`input`: *unknown*, `message?`: *string*): asserts input is unknown[]
▸ **isArray**(`input`, `message?`): asserts input is unknown[]
#### Parameters:
#### Parameters
Name | Type | Default value |
------ | ------ | ------ |
`input` | *unknown* | - |
`message` | *string* | ... |
| Name | Type |
| :------ | :------ |
| `input` | `unknown` |
| `message` | `string` |
**Returns:** asserts input is unknown[]
#### Returns
Defined in: [index.ts:114](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L114)
asserts input is unknown[]
#### Defined in
[index.ts:121](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L121)
___

@@ -180,23 +249,27 @@

▸ **isArrayOfType**<T\>(`input`: *unknown*, `assertT`: [*Assert*](API.md#assert)<*unknown*, T\>, `message?`: *string*, `itemMessage?`: *string*): asserts input is T[]
▸ **isArrayOfType**<`T`\>(`input`, `assertT`, `message?`, `itemMessage?`): asserts input is T[]
#### Type parameters:
#### Type parameters
Name |
------ |
`T` |
| Name |
| :------ |
| `T` |
#### Parameters:
#### Parameters
Name | Type | Default value |
------ | ------ | ------ |
`input` | *unknown* | - |
`assertT` | [*Assert*](API.md#assert)<*unknown*, T\> | - |
`message` | *string* | ... |
`itemMessage` | *string* | ... |
| Name | Type |
| :------ | :------ |
| `input` | `unknown` |
| `assertT` | [`Assert`](API.md#assert)<`unknown`, `T`\> |
| `message` | `string` |
| `itemMessage` | `string` |
**Returns:** asserts input is T[]
#### Returns
Defined in: [index.ts:133](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L133)
asserts input is T[]
#### Defined in
[index.ts:140](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L140)
___

@@ -206,15 +279,19 @@

▸ **isBoolean**(`input`: *unknown*, `message?`: *string*): asserts input is boolean
▸ **isBoolean**(`input`, `message?`): asserts input is boolean
#### Parameters:
#### Parameters
Name | Type | Default value |
------ | ------ | ------ |
`input` | *unknown* | - |
`message` | *string* | ... |
| Name | Type |
| :------ | :------ |
| `input` | `unknown` |
| `message` | `string` |
**Returns:** asserts input is boolean
#### Returns
Defined in: [index.ts:62](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L62)
asserts input is boolean
#### Defined in
[index.ts:69](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L69)
___

@@ -224,15 +301,19 @@

▸ **isDate**(`input`: *unknown*, `message?`: *string*): asserts input is Date
▸ **isDate**(`input`, `message?`): asserts input is Date
#### Parameters:
#### Parameters
Name | Type | Default value |
------ | ------ | ------ |
`input` | *unknown* | - |
`message` | *string* | ... |
| Name | Type |
| :------ | :------ |
| `input` | `unknown` |
| `message` | `string` |
**Returns:** asserts input is Date
#### Returns
Defined in: [index.ts:83](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L83)
asserts input is Date
#### Defined in
[index.ts:90](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L90)
___

@@ -242,23 +323,27 @@

▸ **isExactly**<Input, Output\>(`input`: Input, `value`: Output, `message?`: *string*): asserts input is SubType<Input, Output\>
▸ **isExactly**<`Input`, `Output`\>(`input`, `value`, `message?`): asserts input is SubType<Input, Output\>
#### Type parameters:
#### Type parameters
Name |
------ |
`Input` |
`Output` |
| Name |
| :------ |
| `Input` |
| `Output` |
#### Parameters:
#### Parameters
Name | Type | Default value |
------ | ------ | ------ |
`input` | Input | - |
`value` | Output | - |
`message` | *string* | ... |
| Name | Type |
| :------ | :------ |
| `input` | `Input` |
| `value` | `Output` |
| `message` | `string` |
**Returns:** asserts input is SubType<Input, Output\>
#### Returns
Defined in: [index.ts:54](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L54)
asserts input is SubType<Input, Output\>
#### Defined in
[index.ts:61](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L61)
___

@@ -268,45 +353,74 @@

▸ **isInstanceOf**<T\>(`input`: *unknown*, `constructor`: (...`args`: *any*[]) => T, `message?`: *string*): asserts input is T
▸ **isInstanceOf**<`T`\>(`input`, `constructor`, `message?`): asserts input is T
#### Type parameters:
#### Type parameters
Name |
------ |
`T` |
| Name |
| :------ |
| `T` |
#### Parameters:
#### Parameters
Name | Type | Default value |
------ | ------ | ------ |
`input` | *unknown* | - |
`constructor` | (...`args`: *any*[]) => T | - |
`message` | *string* | ... |
| Name | Type |
| :------ | :------ |
| `input` | `unknown` |
| `constructor` | (...`args`: `any`[]) => `T` |
| `message` | `string` |
**Returns:** asserts input is T
#### Returns
Defined in: [index.ts:179](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L179)
asserts input is T
#### Defined in
[index.ts:186](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L186)
___
### isNever
▸ **isNever**(`_input`, `message?`): `never`
#### Parameters
| Name | Type |
| :------ | :------ |
| `_input` | `never` |
| `message` | `string` |
#### Returns
`never`
#### Defined in
[index.ts:40](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L40)
___
### isNotNull
▸ **isNotNull**<T\>(`input`: *null* \| T, `message?`: *string*): asserts input is T
▸ **isNotNull**<`T`\>(`input`, `message?`): asserts input is T
#### Type parameters:
#### Type parameters
Name |
------ |
`T` |
| Name |
| :------ |
| `T` |
#### Parameters:
#### Parameters
Name | Type | Default value |
------ | ------ | ------ |
`input` | *null* \| T | - |
`message` | *string* | ... |
| Name | Type |
| :------ | :------ |
| `input` | ``null`` \| `T` |
| `message` | `string` |
**Returns:** asserts input is T
#### Returns
Defined in: [index.ts:40](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L40)
asserts input is T
#### Defined in
[index.ts:47](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L47)
___

@@ -316,21 +430,25 @@

▸ **isNotUndefined**<T\>(`input`: *undefined* \| T, `message?`: *string*): asserts input is T
▸ **isNotUndefined**<`T`\>(`input`, `message?`): asserts input is T
#### Type parameters:
#### Type parameters
Name |
------ |
`T` |
| Name |
| :------ |
| `T` |
#### Parameters:
#### Parameters
Name | Type | Default value |
------ | ------ | ------ |
`input` | *undefined* \| T | - |
`message` | *string* | ... |
| Name | Type |
| :------ | :------ |
| `input` | `undefined` \| `T` |
| `message` | `string` |
**Returns:** asserts input is T
#### Returns
Defined in: [index.ts:47](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L47)
asserts input is T
#### Defined in
[index.ts:54](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L54)
___

@@ -340,15 +458,19 @@

▸ **isNumber**(`input`: *unknown*, `message?`: *string*): asserts input is number
▸ **isNumber**(`input`, `message?`): asserts input is number
#### Parameters:
#### Parameters
Name | Type | Default value |
------ | ------ | ------ |
`input` | *unknown* | - |
`message` | *string* | ... |
| Name | Type |
| :------ | :------ |
| `input` | `unknown` |
| `message` | `string` |
**Returns:** asserts input is number
#### Returns
Defined in: [index.ts:69](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L69)
asserts input is number
#### Defined in
[index.ts:76](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L76)
___

@@ -358,23 +480,27 @@

▸ **isOneOf**<Input, Output\>(`input`: Input, `values`: readonly Output[], `message?`: *string*): asserts input is SubType<Input, Output\>
▸ **isOneOf**<`Input`, `Output`\>(`input`, `values`, `message?`): asserts input is SubType<Input, Output\>
#### Type parameters:
#### Type parameters
Name |
------ |
`Input` |
`Output` |
| Name |
| :------ |
| `Input` |
| `Output` |
#### Parameters:
#### Parameters
Name | Type | Default value |
------ | ------ | ------ |
`input` | Input | - |
`values` | readonly Output[] | - |
`message` | *string* | ... |
| Name | Type |
| :------ | :------ |
| `input` | `Input` |
| `values` | readonly `Output`[] |
| `message` | `string` |
**Returns:** asserts input is SubType<Input, Output\>
#### Returns
Defined in: [index.ts:156](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L156)
asserts input is SubType<Input, Output\>
#### Defined in
[index.ts:163](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L163)
___

@@ -384,23 +510,27 @@

▸ **isOneOfType**<T\>(`input`: *unknown*, `assertT`: [*Assert*](API.md#assert)<*unknown*, T\>[], `message?`: *string*, `itemMessage?`: *string*): asserts input is T
▸ **isOneOfType**<`T`\>(`input`, `assertT`, `message?`, `itemMessage?`): asserts input is T
#### Type parameters:
#### Type parameters
Name |
------ |
`T` |
| Name |
| :------ |
| `T` |
#### Parameters:
#### Parameters
Name | Type | Default value |
------ | ------ | ------ |
`input` | *unknown* | - |
`assertT` | [*Assert*](API.md#assert)<*unknown*, T\>[] | - |
`message` | *string* | ... |
`itemMessage?` | *string* | - |
| Name | Type |
| :------ | :------ |
| `input` | `unknown` |
| `assertT` | [`Assert`](API.md#assert)<`unknown`, `T`\>[] |
| `message` | `string` |
| `itemMessage?` | `string` |
**Returns:** asserts input is T
#### Returns
Defined in: [index.ts:164](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L164)
asserts input is T
#### Defined in
[index.ts:171](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L171)
___

@@ -410,23 +540,27 @@

▸ **isOptionOfType**<Input, Output\>(`input`: *undefined* \| Input, `assertT`: [*Assert*](API.md#assert)<Input, Output\>, `message?`: *string*): asserts input is SubType<Input, undefined\> \| SubType<Input, Output\>
▸ **isOptionOfType**<`Input`, `Output`\>(`input`, `assertT`, `message?`): asserts input is SubType<Input, undefined\> \| SubType<Input, Output\>
#### Type parameters:
#### Type parameters
Name |
------ |
`Input` |
`Output` |
| Name |
| :------ |
| `Input` |
| `Output` |
#### Parameters:
#### Parameters
Name | Type | Default value |
------ | ------ | ------ |
`input` | *undefined* \| Input | - |
`assertT` | [*Assert*](API.md#assert)<Input, Output\> | - |
`message` | *string* | ... |
| Name | Type |
| :------ | :------ |
| `input` | `Input` \| `undefined` |
| `assertT` | [`Assert`](API.md#assert)<`Input`, `Output`\> |
| `message` | `string` |
**Returns:** asserts input is SubType<Input, undefined\> \| SubType<Input, Output\>
#### Returns
Defined in: [index.ts:145](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L145)
asserts input is SubType<Input, undefined\> \| SubType<Input, Output\>
#### Defined in
[index.ts:152](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L152)
___

@@ -436,15 +570,19 @@

▸ **isPromise**(`input`: *unknown*, `message?`: *string*): asserts input is Promise<unknown\>
▸ **isPromise**(`input`, `message?`): asserts input is Promise<unknown\>
#### Parameters:
#### Parameters
Name | Type | Default value |
------ | ------ | ------ |
`input` | *unknown* | - |
`message` | *string* | ... |
| Name | Type |
| :------ | :------ |
| `input` | `unknown` |
| `message` | `string` |
**Returns:** asserts input is Promise<unknown\>
#### Returns
Defined in: [index.ts:188](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L188)
asserts input is Promise<unknown\>
#### Defined in
[index.ts:195](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L195)
___

@@ -454,15 +592,19 @@

▸ **isRecord**(`input`: *unknown*, `message?`: *string*): asserts input is Record<string, unknown\>
▸ **isRecord**(`input`, `message?`): asserts input is Record<string, unknown\>
#### Parameters:
#### Parameters
Name | Type | Default value |
------ | ------ | ------ |
`input` | *unknown* | - |
`message` | *string* | ... |
| Name | Type |
| :------ | :------ |
| `input` | `unknown` |
| `message` | `string` |
**Returns:** asserts input is Record<string, unknown\>
#### Returns
Defined in: [index.ts:90](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L90)
asserts input is Record<string, unknown\>
#### Defined in
[index.ts:97](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L97)
___

@@ -472,23 +614,27 @@

▸ **isRecordOfType**<T\>(`input`: *unknown*, `assertT`: [*Assert*](API.md#assert)<*unknown*, T\>, `message?`: *string*, `itemMessage?`: *string*): asserts input is Record<string, T\>
▸ **isRecordOfType**<`T`\>(`input`, `assertT`, `message?`, `itemMessage?`): asserts input is Record<string, T\>
#### Type parameters:
#### Type parameters
Name |
------ |
`T` |
| Name |
| :------ |
| `T` |
#### Parameters:
#### Parameters
Name | Type | Default value |
------ | ------ | ------ |
`input` | *unknown* | - |
`assertT` | [*Assert*](API.md#assert)<*unknown*, T\> | - |
`message` | *string* | ... |
`itemMessage` | *string* | ... |
| Name | Type |
| :------ | :------ |
| `input` | `unknown` |
| `assertT` | [`Assert`](API.md#assert)<`unknown`, `T`\> |
| `message` | `string` |
| `itemMessage` | `string` |
**Returns:** asserts input is Record<string, T\>
#### Returns
Defined in: [index.ts:121](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L121)
asserts input is Record<string, T\>
#### Defined in
[index.ts:128](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L128)
___

@@ -498,22 +644,26 @@

▸ **isRecordWithKeys**<K\>(`input`: *unknown*, `keys`: K[], `message?`: *string*): asserts input is { readonly[Key in string]: unknown}
▸ **isRecordWithKeys**<`K`\>(`input`, `keys`, `message?`): asserts input is { readonly[Key in string]: unknown}
#### Type parameters:
#### Type parameters
Name | Type |
------ | ------ |
`K` | *string* |
| Name | Type |
| :------ | :------ |
| `K` | extends `string` |
#### Parameters:
#### Parameters
Name | Type | Default value |
------ | ------ | ------ |
`input` | *unknown* | - |
`keys` | K[] | - |
`message` | *string* | ... |
| Name | Type |
| :------ | :------ |
| `input` | `unknown` |
| `keys` | `K`[] |
| `message` | `string` |
**Returns:** asserts input is { readonly[Key in string]: unknown}
#### Returns
Defined in: [index.ts:101](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L101)
asserts input is { readonly[Key in string]: unknown}
#### Defined in
[index.ts:108](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L108)
___

@@ -523,15 +673,19 @@

▸ **isString**(`input`: *unknown*, `message?`: *string*): asserts input is string
▸ **isString**(`input`, `message?`): asserts input is string
#### Parameters:
#### Parameters
Name | Type | Default value |
------ | ------ | ------ |
`input` | *unknown* | - |
`message` | *string* | ... |
| Name | Type |
| :------ | :------ |
| `input` | `unknown` |
| `message` | `string` |
**Returns:** asserts input is string
#### Returns
Defined in: [index.ts:76](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L76)
asserts input is string
#### Defined in
[index.ts:83](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L83)
___

@@ -541,14 +695,18 @@

▸ **isUnknown**(`_input`: *unknown*): \_input is unknown
▸ **isUnknown**(`_input`): \_input is unknown
#### Parameters:
#### Parameters
Name | Type |
------ | ------ |
`_input` | *unknown* |
| Name | Type |
| :------ | :------ |
| `_input` | `unknown` |
**Returns:** \_input is unknown
#### Returns
Defined in: [index.ts:36](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L36)
\_input is unknown
#### Defined in
[index.ts:36](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L36)
___

@@ -558,14 +716,18 @@

▸ `Const`**safeJsonParse**(`json`: *string*): *unknown*
▸ `Const` **safeJsonParse**(`json`): `unknown`
#### Parameters:
#### Parameters
Name | Type |
------ | ------ |
`json` | *string* |
| Name | Type |
| :------ | :------ |
| `json` | `string` |
**Returns:** *unknown*
#### Returns
Defined in: [index.ts:33](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L33)
`unknown`
#### Defined in
[index.ts:33](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L33)
___

@@ -575,12 +737,16 @@

▸ **setBaseAssert**(`assert?`: [*WeakAssert*](API.md#weakassert)): *void*
▸ **setBaseAssert**(`assert?`): `void`
#### Parameters:
#### Parameters
Name | Type |
------ | ------ |
`assert?` | [*WeakAssert*](API.md#weakassert) |
| Name | Type |
| :------ | :------ |
| `assert?` | [`WeakAssert`](API.md#weakassert) |
**Returns:** *void*
#### Returns
Defined in: [index.ts:27](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L27)
`void`
#### Defined in
[index.ts:27](https://github.com/elierotenberg/typed-assert/blob/master/src/index.ts#L27)

@@ -55,2 +55,13 @@ "use strict";

});
test("isNever", () => {
expect(() => {
const value = "a";
switch (value) {
case "a":
case "b":
return;
}
t.isNever(value);
}).not.toThrow();
});
test("isNotNull", () => {

@@ -57,0 +68,0 @@ const v = orNull(fixtures.string);

@@ -10,2 +10,3 @@ export declare type WeakAssert = (input: unknown, message?: string) => void;

export declare function isUnknown(_input: unknown): _input is unknown;
export declare function isNever(_input: never, message?: string): never;
export declare function isNotNull<T>(input: null | T, message?: string): asserts input is T;

@@ -12,0 +13,0 @@ export declare function isNotUndefined<T>(input: undefined | T, message?: string): asserts input is T;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.check = exports.isPromise = exports.isInstanceOf = exports.isOneOfType = exports.isOneOf = exports.isOptionOfType = exports.isArrayOfType = exports.isRecordOfType = exports.isArray = exports.isRecordWithKeys = exports.isRecord = exports.isDate = exports.isString = exports.isNumber = exports.isBoolean = exports.isExactly = exports.isNotUndefined = exports.isNotNull = exports.isUnknown = exports.safeJsonParse = exports.setBaseAssert = exports.assert = exports.defaultAssert = void 0;
exports.check = exports.isPromise = exports.isInstanceOf = exports.isOneOfType = exports.isOneOf = exports.isOptionOfType = exports.isArrayOfType = exports.isRecordOfType = exports.isArray = exports.isRecordWithKeys = exports.isRecord = exports.isDate = exports.isString = exports.isNumber = exports.isBoolean = exports.isExactly = exports.isNotUndefined = exports.isNotNull = exports.isNever = exports.isUnknown = exports.safeJsonParse = exports.setBaseAssert = exports.assert = exports.defaultAssert = void 0;
const expectedToBe = (type) => `expected to be ${type}`;

@@ -26,2 +26,6 @@ const defaultAssert = (condition, message) => {

exports.isUnknown = isUnknown;
function isNever(_input, message = expectedToBe("unreachable")) {
throw new TypeError(message);
}
exports.isNever = isNever;
function isNotNull(input, message = expectedToBe("not null")) {

@@ -28,0 +32,0 @@ exports.assert(input !== null, message);

{
"name": "typed-assert",
"version": "1.0.7",
"version": "1.0.8",
"description": "typesafe assertion library for TypeScript 3.7+",

@@ -30,17 +30,17 @@ "main": "build/index.js",

"devDependencies": {
"@types/jest": "^26.0.19",
"@types/node": "^14.14.20",
"@typescript-eslint/eslint-plugin": "^4.12.0",
"@typescript-eslint/parser": "^4.12.0",
"eslint": "^7.17.0",
"eslint-config-prettier": "^7.1.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-prettier": "^3.3.1",
"jest": "^26.6.3",
"prettier": "^2.2.1",
"ts-jest": "^26.4.4",
"typedoc": "^0.20.12",
"typedoc-plugin-markdown": "^3.2.1",
"typescript": "^4.1.3"
"@types/jest": "^26.0.23",
"@types/node": "^15.14.0",
"@typescript-eslint/eslint-plugin": "^4.28.1",
"@typescript-eslint/parser": "^4.28.1",
"eslint": "^7.29.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-prettier": "^3.4.0",
"jest": "^27.0.6",
"prettier": "^2.3.2",
"ts-jest": "^27.0.3",
"typedoc": "^0.21.2",
"typedoc-plugin-markdown": "^3.10.2",
"typescript": "^4.3.5"
}
}

@@ -63,2 +63,14 @@ import nodeAssert from "assert";

test("isNever", () => {
expect(() => {
const value = "a" as "a" | "b";
switch (value) {
case "a":
case "b":
return;
}
t.isNever(value);
}).not.toThrow();
});
test("isNotNull", () => {

@@ -65,0 +77,0 @@ const v = orNull(fixtures.string);

@@ -40,2 +40,9 @@ const expectedToBe = (type: string): string => `expected to be ${type}`;

export function isNever(
_input: never,
message: string = expectedToBe("unreachable"),
): never {
throw new TypeError(message)
}
export function isNotNull<T>(

@@ -42,0 +49,0 @@ input: null | T,

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc