@noldova/context.exceptions 0.0.2 → 0.0.3

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.
Files changed (2) hide show
  1. package/README.md +42 -0
  2. package/package.json +2 -2
package/README.md ADDED
@@ -0,0 +1,42 @@
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
+ new ArgumentNullException("input").message; // "Value cannot be null or undefined. (Parameter 'input')"
31
+ new InputException("Cannot read input.", new ExceptionOptions(new Error("Bad encoding."))).name; // "InputException"
32
+ ```
33
+
34
+ `ArgumentException`, `ArgumentNullException` and `ArgumentOutOfRangeException`
35
+ keep the parameter name as a field, and `ArgumentOutOfRangeException` also keeps
36
+ the rejected value. `IndexOutOfRangeException` carries a message and, where
37
+ given, a cause. The declaration file `api/index.d.ts` documents every member
38
+ with its contract and examples.
39
+
40
+ ## License
41
+
42
+ MIT; see `LICENSE`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noldova/context.exceptions",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "type": "module",
5
5
  "main": "api/index.js",
6
6
  "types": "api/index.d.ts",
@@ -19,6 +19,6 @@
19
19
  "registry": "https://registry.npmjs.org/"
20
20
  },
21
21
  "dependencies": {
22
- "@noldova/context.core": "0.0.2"
22
+ "@noldova/context.core": "0.0.3"
23
23
  }
24
24
  }