@xylabs/assert 3.0.15 → 3.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -36,11 +36,30 @@ Using yarn:
|
|
|
36
36
|
yarn add @xylabs/assert
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
-
##
|
|
40
|
-
[Developer Reference](https://xylabs.github.io/sdk-js)
|
|
39
|
+
## Usage
|
|
41
40
|
|
|
42
|
-
|
|
41
|
+
The `assertEx` function is a utility function for simple null/undefined checks for variables. It evaluates an expression for truthiness and throws an error if the expression is false.
|
|
42
|
+
|
|
43
|
+
Here are some examples of how to use `assertEx` in different scenarios:
|
|
44
|
+
|
|
45
|
+
- Basic usage:
|
|
46
|
+
|
|
47
|
+
```javascript
|
|
48
|
+
import { assertEx } from '@xylabs/assert';
|
|
49
|
+
|
|
50
|
+
const value = getValue(); // This is a function that may return null or undefined
|
|
51
|
+
assertEx(value); // Throws an AssertExError with a default message if value is null or undefined
|
|
52
|
+
```
|
|
43
53
|
|
|
54
|
+
- Using with a custom error message:
|
|
55
|
+
|
|
56
|
+
```javascript
|
|
57
|
+
import { assertEx } from '@xylabs/assert';
|
|
58
|
+
|
|
59
|
+
const value = getValue(); // This function may return null or undefined
|
|
60
|
+
assertEx(value, () => 'Dynamic error message based on some conditions'); // Throws an AssertExError with a dynamic message if value is null or undefined
|
|
61
|
+
|
|
62
|
+
## Maintainers
|
|
44
63
|
- [Arie Trouw](https://github.com/arietrouw) ([arietrouw.com](https://arietrouw.com))
|
|
45
64
|
- [Joel Carter](https://github.com/JoelBCarter)
|
|
46
65
|
- [Matt Jones](https://github.com/jonesmac)
|