Support custom assertion messages (#204)

Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
This commit is contained in:
Martin Eneqvist 2024-04-23 07:58:28 +02:00 committed by GitHub
parent 664b9077e1
commit f2e5834421
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 634 additions and 268 deletions

View file

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