@thi.ng/errors 2.2.1 → 2.2.2
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/CHANGELOG.md +9 -1
- package/README.md +2 -2
- package/assert.d.ts +4 -4
- package/assert.js +9 -10
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2022-10-
|
|
3
|
+
- **Last updated**: 2022-10-04T17:35:45Z
|
|
4
4
|
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
5
|
|
|
6
6
|
All notable changes to this project will be documented in this file.
|
|
@@ -9,6 +9,14 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
9
9
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
10
10
|
and/or version bumps of transitive dependencies.
|
|
11
11
|
|
|
12
|
+
### [2.2.2](https://github.com/thi-ng/umbrella/tree/@thi.ng/errors@2.2.2) (2022-10-04)
|
|
13
|
+
|
|
14
|
+
#### 🩹 Bug fixes
|
|
15
|
+
|
|
16
|
+
- update assertion switch logic ([781470d](https://github.com/thi-ng/umbrella/commit/781470d))
|
|
17
|
+
- remove support for obsolete (& broken) snowpack setup
|
|
18
|
+
- add support for Vite's env var handling
|
|
19
|
+
|
|
12
20
|
## [2.2.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/errors@2.2.0) (2022-09-21)
|
|
13
21
|
|
|
14
22
|
#### 🚀 Features
|
package/README.md
CHANGED
|
@@ -63,7 +63,7 @@ node --experimental-repl-await
|
|
|
63
63
|
> const errors = await import("@thi.ng/errors");
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
-
Package sizes (gzipped, pre-treeshake): ESM:
|
|
66
|
+
Package sizes (gzipped, pre-treeshake): ESM: 581 bytes
|
|
67
67
|
|
|
68
68
|
## Dependencies
|
|
69
69
|
|
|
@@ -106,7 +106,7 @@ try {
|
|
|
106
106
|
|
|
107
107
|
### Environment variables
|
|
108
108
|
|
|
109
|
-
The `UMBRELLA_ASSERTS` or `
|
|
109
|
+
The `UMBRELLA_ASSERTS` or `VITE_UMBRELLA_ASSERTS` env variables are
|
|
110
110
|
used to control the behavior of the `assert()` function in production builds: If
|
|
111
111
|
either is set (to a non-empty string), the function will **always** be enabled.
|
|
112
112
|
Otherwise (by default), `assert()` will be **disabled for production builds**,
|
package/assert.d.ts
CHANGED
|
@@ -10,12 +10,12 @@ export declare const AssertionError: {
|
|
|
10
10
|
stackTraceLimit: number;
|
|
11
11
|
};
|
|
12
12
|
/**
|
|
13
|
-
* Takes a `test` result or predicate function without args and throws
|
|
14
|
-
*
|
|
13
|
+
* Takes a `test` result or predicate function without args and throws error
|
|
14
|
+
* with given `msg` if test failed (i.e. is falsy).
|
|
15
15
|
*
|
|
16
16
|
* @remarks
|
|
17
|
-
* The function is only enabled if `process.env.NODE_ENV != "production"`
|
|
18
|
-
*
|
|
17
|
+
* The function is only enabled if `process.env.NODE_ENV != "production"` or if
|
|
18
|
+
* the `UMBRELLA_ASSERTS` or `VITE_UMBRELLA_ASSERTS` env var is set to 1.
|
|
19
19
|
*/
|
|
20
20
|
export declare const assert: (test: boolean | (() => boolean), msg?: string | (() => string)) => void;
|
|
21
21
|
//# sourceMappingURL=assert.d.ts.map
|
package/assert.js
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
import { defError } from "./deferror.js";
|
|
2
2
|
export const AssertionError = defError(() => "Assertion failed");
|
|
3
3
|
/**
|
|
4
|
-
* Takes a `test` result or predicate function without args and throws
|
|
5
|
-
*
|
|
4
|
+
* Takes a `test` result or predicate function without args and throws error
|
|
5
|
+
* with given `msg` if test failed (i.e. is falsy).
|
|
6
6
|
*
|
|
7
7
|
* @remarks
|
|
8
|
-
* The function is only enabled if `process.env.NODE_ENV != "production"`
|
|
9
|
-
*
|
|
8
|
+
* The function is only enabled if `process.env.NODE_ENV != "production"` or if
|
|
9
|
+
* the `UMBRELLA_ASSERTS` or `VITE_UMBRELLA_ASSERTS` env var is set to 1.
|
|
10
10
|
*/
|
|
11
|
-
export const assert = (
|
|
11
|
+
export const assert = (typeof process !== "undefined"
|
|
12
12
|
? process.env.NODE_ENV !== "production" ||
|
|
13
13
|
!!process.env.UMBRELLA_ASSERTS
|
|
14
|
-
:
|
|
15
|
-
?
|
|
16
|
-
!!
|
|
17
|
-
|
|
18
|
-
: true)()
|
|
14
|
+
: import.meta.env
|
|
15
|
+
? import.meta.env.MODE !== "production" ||
|
|
16
|
+
!!import.meta.env.VITE_UMBRELLA_ASSERTS
|
|
17
|
+
: true)
|
|
19
18
|
? (test, msg) => {
|
|
20
19
|
if ((typeof test === "function" && !test()) || !test) {
|
|
21
20
|
throw new AssertionError(typeof msg === "function" ? msg() : msg);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/errors",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.2",
|
|
4
4
|
"description": "Custom error types and error factory functions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@microsoft/api-extractor": "^7.31.1",
|
|
38
|
-
"@thi.ng/testament": "^0.3.
|
|
38
|
+
"@thi.ng/testament": "^0.3.2",
|
|
39
39
|
"@types/node": "^18.7.18",
|
|
40
40
|
"rimraf": "^3.0.2",
|
|
41
41
|
"tools": "^0.0.1",
|
|
@@ -93,5 +93,5 @@
|
|
|
93
93
|
"thi.ng": {
|
|
94
94
|
"year": 2018
|
|
95
95
|
},
|
|
96
|
-
"gitHead": "
|
|
96
|
+
"gitHead": "c3f7d6598c7d7d0c61ba87150a56deac12649d7b\n"
|
|
97
97
|
}
|