Adds custom assertion message example to README

This commit is contained in:
Martin Eneqvist 2024-04-22 13:19:06 +02:00
parent d9619cdc01
commit 7a397c996f

View file

@ -45,6 +45,15 @@ assert.string(2);
//=> Error: Expected value which is `string`, received value of type `number`.
```
Most assertions also support an optional custom error message.
```js
import {assert} from '@sindresorhus/is';
assert.nonEmptyString(process.env.API_URL, 'API_URL env variable is required.');
//=> Error: API_URL env variable is required.
```
And with TypeScript:
```ts