@noldova/context.json 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.
Files changed (2) hide show
  1. package/README.md +40 -0
  2. package/package.json +5 -4
package/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # noldova.context.json
2
+
3
+ Reads untrusted JSON into typed values in one place. `JsonReader` reads an
4
+ object's fields by name and type; every failure is a `JsonException` whose
5
+ `path`, such as `$.version`, names the field that is wrong.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @noldova/context.json
11
+ ```
12
+
13
+ ## Use
14
+
15
+ ```ts
16
+ import { JsonException, JsonReader } from "@noldova/context.json";
17
+
18
+ const reader = JsonReader.parse("{\"name\":\"Fixture\",\"version\":2}");
19
+ reader.readString("name"); // "Fixture"
20
+ reader.readInteger("version"); // 2
21
+ reader.readOptionalString("detail"); // undefined: the field is absent.
22
+
23
+ try {
24
+ reader.readString("version");
25
+ }
26
+ catch (error) {
27
+ if (!(error instanceof JsonException))
28
+ throw error;
29
+ error.path; // "$.version"
30
+ }
31
+ ```
32
+
33
+ A required field must be present and not `null`; an `optional` accessor
34
+ accepts an absent field, and a `nullable` one accepts `null`. Unknown fields
35
+ are ignored. The declaration file `api/index.d.ts` documents every member with
36
+ its contract and examples.
37
+
38
+ ## License
39
+
40
+ MIT; see `LICENSE`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noldova/context.json",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "type": "module",
5
5
  "main": "api/index.js",
6
6
  "types": "api/index.d.ts",
@@ -19,7 +19,8 @@
19
19
  "registry": "https://registry.npmjs.org/"
20
20
  },
21
21
  "dependencies": {
22
- "@noldova/context.core": "0.0.2",
23
- "@noldova/context.exceptions": "0.0.2"
24
- }
22
+ "@noldova/context.core": "0.0.4",
23
+ "@noldova/context.exceptions": "0.0.4"
24
+ },
25
+ "gitHead": "15e2532ec1c46998b0403aeb8c009bd903b15362"
25
26
  }