@noldova/context.exceptions 0.0.2 → 0.0.4
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 +43 -0
- package/package.json +4 -3
package/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# noldova.context.exceptions
|
|
2
|
+
|
|
3
|
+
The exceptions CONTEXT libraries throw: an abstract `Exception` base that names
|
|
4
|
+
itself after its concrete class, argument exceptions with guards that check a
|
|
5
|
+
value and narrow its type in one call, and an index exception.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @noldova/context.exceptions
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Use
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { ArgumentException, ArgumentNullException, Exception, ExceptionOptions } from "@noldova/context.exceptions";
|
|
17
|
+
|
|
18
|
+
class InputException extends Exception {
|
|
19
|
+
public constructor(message: string, options?: ExceptionOptions) {
|
|
20
|
+
super(message, options);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function readName(values: Map<string, string>): string {
|
|
25
|
+
const name = values.get("name");
|
|
26
|
+
ArgumentException.throwIfNullOrWhitespace(name, "name");
|
|
27
|
+
return name; // Narrowed to string by the guard.
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
readName(new Map([["name", "Fixture"]])); // "Fixture"
|
|
31
|
+
new ArgumentNullException("input").message; // "Value cannot be null or undefined. (Parameter 'input')"
|
|
32
|
+
new InputException("Cannot read input.", new ExceptionOptions(new Error("Bad encoding."))).name; // "InputException"
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
`ArgumentException`, `ArgumentNullException` and `ArgumentOutOfRangeException`
|
|
36
|
+
keep the parameter name as a field, and `ArgumentOutOfRangeException` also keeps
|
|
37
|
+
the rejected value. `IndexOutOfRangeException` carries a message and, where
|
|
38
|
+
given, a cause. The declaration file `api/index.d.ts` documents every member
|
|
39
|
+
with its contract and examples.
|
|
40
|
+
|
|
41
|
+
## License
|
|
42
|
+
|
|
43
|
+
MIT; see `LICENSE`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noldova/context.exceptions",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "api/index.js",
|
|
6
6
|
"types": "api/index.d.ts",
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"registry": "https://registry.npmjs.org/"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@noldova/context.core": "0.0.
|
|
23
|
-
}
|
|
22
|
+
"@noldova/context.core": "0.0.4"
|
|
23
|
+
},
|
|
24
|
+
"gitHead": "15e2532ec1c46998b0403aeb8c009bd903b15362"
|
|
24
25
|
}
|