From 7a397c996f4110356f50ebfdf823c4248123e503 Mon Sep 17 00:00:00 2001 From: Martin Eneqvist Date: Mon, 22 Apr 2024 13:19:06 +0200 Subject: [PATCH] Adds custom assertion message example to README --- readme.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/readme.md b/readme.md index 527745a..7bbaacf 100644 --- a/readme.md +++ b/readme.md @@ -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