fat-json 0.0.4 → 0.0.5

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 +15 -5
  2. package/package.json +7 -4
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Fat Json
2
2
 
3
- Stringify and parse non-standard JSON data types: _reviver_ and _replacer_ functions for the built-in `JSON` object
3
+ Stringify and parse non-standard JSON [data types](#from-wikipedia): _reviver_ and _replacer_ functions for the built-in `JSON` object
4
4
 
5
5
  ## Install
6
6
 
@@ -12,7 +12,11 @@ npm i fat-json
12
12
 
13
13
  Transforming _standard data types_ using the built-in `JSON` object is simple, but the JavaScript language now features other types like `BigInt` which don't serialise/cannot be coerced to another type without potential data loss
14
14
 
15
- Serialising and de-serialising with `JSON.stringify()` and `JSON.parse()` provides _some_ opportunity to safely transform data from one type to another with _replacer_ and _reviver_ functions, but while it's not hard to argue with the simplicity of transforming from a `BigInt` to a `String` ...
15
+ Serialising and de-serialising with `JSON.stringify()` and `JSON.parse()` provides _some_ opportunity to safely transform data from one type to another with _replacer_ and _reviver_ functions
16
+
17
+ #### A typical replacer function for `BigInt`
18
+
19
+ We can test the `value` and transform based on its type
16
20
 
17
21
  ```javascript
18
22
  function replacer (key, value) {
@@ -22,7 +26,11 @@ function replacer (key, value) {
22
26
  }
23
27
  ```
24
28
 
25
- ... it's harder to see how to transform back from a `String` to a `BigInt` without additional information
29
+ It's hard to argue with the simplicity of transforming from a `BigInt` to a `String` but it's harder to see how we should transform back from a `String` to a `BigInt` without some _additional information_
30
+
31
+ #### A typical reviver function
32
+
33
+ Should we transform every `String`?
26
34
 
27
35
  ```javascript
28
36
  function reviver (key, value) {
@@ -32,9 +40,11 @@ function reviver (key, value) {
32
40
  }
33
41
  ```
34
42
 
35
- Should we use a catch block? Format the _key_ or _value_ in such away that we can test them, and then decide what to do?
43
+ We could use a catch block. Or else format the _key_ or _value_ such that we can test one or both of them, and then decide what to do
44
+
45
+ ## Fat Json's third argument
36
46
 
37
- _Fat Json_ will supply a _[JSONPath](https://en.wikipedia.org/wiki/JSONPath)_ as the third argument to your _replacer_ or _reviver_ function. If you know the structure of your data in advance you can serialise and de-serialise safely and in one step
47
+ _Fat Json_ supplies a _[JSONPath](https://en.wikipedia.org/wiki/JSONPath)_ as the third argument to your _replacer_ or _reviver_ function so you can decide _whether to transform a value by its position in the JSON document_, not just by its `key` or `value`. If you know the structure of your data in advance you can serialise and de-serialise safely and in one step
38
48
 
39
49
  ```javascript
40
50
  import {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fat-json",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "keywords": [
5
5
  "JSON",
6
6
  "stringify",
@@ -30,11 +30,11 @@
30
30
  "test": "mocha test --recursive"
31
31
  },
32
32
  "devDependencies": {
33
- "@sequencemedia/eslint-config-standard": "^0.2.82",
34
- "@sequencemedia/eslint-config-typescript": "^0.1.141",
33
+ "@sequencemedia/eslint-config-standard": "^0.2.83",
34
+ "@sequencemedia/eslint-config-typescript": "^0.1.142",
35
35
  "@types/chai": "^5.2.2",
36
36
  "@types/mocha": "^10.0.10",
37
- "@types/node": "^24.5.0",
37
+ "@types/node": "^24.5.1",
38
38
  "@types/sinon": "^17.0.4",
39
39
  "chai": "^6.0.1",
40
40
  "eslint": "^9.35.0",
@@ -48,5 +48,8 @@
48
48
  "#common": "./src/common/index.mjs",
49
49
  "#fat-json": "./src/index.mjs",
50
50
  "#transformers": "./src/transformers/index.mjs"
51
+ },
52
+ "exports": {
53
+ "./transformers": "./src/transformers/index.mjs"
51
54
  }
52
55
  }