Skip to content

Commit 9b0e88b

Browse files
authored
development (#13)
* Approximately 3–4 times faster parsing than 5.0.x versions. * JSON-Z will now honor an object’s `toJSON5()` method, if present, at higher priority than `toJSON()`, and lower priority than `toJSONZ()`. * Updated the allowed CLI arguments to match the latest JSON5 CLI.
1 parent 83be2fc commit 9b0e88b

23 files changed

Lines changed: 2483 additions & 2156 deletions

.eslintrc.json

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
"plugins": ["chai-friendly", "@typescript-eslint"],
55
"extends": [
66
"standard",
7-
"plugin:node/recommended"
7+
"plugin:n/recommended"
88
],
99
"parserOptions": {
1010
"sourceType": "module",
1111
"ecmaVersion": 2023
1212
},
13+
"ignorePatterns": ["*.d.ts"],
1314
"rules": {
1415
"array-bracket-spacing": [
1516
"error",
@@ -20,6 +21,10 @@
2021
"as-needed"
2122
],
2223
"brace-style": ["error", "stroustrup", { "allowSingleLine": true }],
24+
"camelcase": [
25+
"error",
26+
{ "allow": ["^LOWER_[a-z]", "^_\\$"] }
27+
],
2328
"comma-dangle": [
2429
"error",
2530
"never"
@@ -31,9 +36,10 @@
3136
],
3237
"no-process-exit": "off",
3338
"no-prototype-builtins": "off",
34-
"node/no-unpublished-require": "off",
35-
"node/no-unsupported-features/es-syntax": "off",
36-
"node/shebang": "off",
39+
"n/no-process-exit": "off",
40+
"n/no-unpublished-require": "off",
41+
"n/no-unsupported-features/es-syntax": "off",
42+
"n/shebang": "off",
3743
"no-unused-expressions": "off",
3844
"chai-friendly/no-unused-expressions": "error",
3945
"object-curly-spacing": [
@@ -51,6 +57,11 @@
5157
"named": "never",
5258
"asyncArrow": "always"
5359
}
60+
],
61+
"yoda": [
62+
"error",
63+
"never",
64+
{ "exceptRange": true }
5465
]
5566
},
5667
"overrides": [

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
### 5.1.0
2+
3+
* Approximately 3–4 times faster parsing than 5.0.x versions.
4+
* JSON-Z will now honor an object’s `toJSON5()` method, if present, at higher priority than `toJSON()`, and lower priority than `toJSONZ()`.
5+
* Updated the allowed CLI arguments to match the latest JSON5 CLI.
6+
17
### 5.0.1
28

39
* Eliminated `minimist` dependency. (Package is now dependency-free.)

GRAMMAR.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ decimal-sequence = decimal-digit, { [ "_" ], decimal-digit } ;
113113
114114
non-octal-sequence = non-octal-digit, { [ "_" ], non-octal-digit } ;
115115
116-
hex = "0x", hex-digit, { [ "_" ], hex-digit } ;
116+
hex (* JSON5 *) = "0x", hex-digit, { [ "_" ], hex-digit } ;
117117
118118
floating = ( ( ( decimal-sequence, ".", [ decimal-sequence ] | ".", decimal-sequence ), [ exponent ] ) | decimal-sequence, exponent ), [ "d" (* JSON-Z *) | "n" (* JSON-Z / integer only *) | "m" (* JSON-Z *) ] ;
119119
@@ -141,7 +141,7 @@ octal (* JSON-Z *) = "0o", { octal-digit }- ;
141141
142142
decimal = { decimal-digit }- ;
143143
144-
hex = "0x", { hex-digit }- ;
144+
hex (* JSON5 *) = "0x", { hex-digit }- ;
145145
146146
floating = { decimal-digit }-, ( ( ".", { decimal-digit }-, [ exponent ]) | ( exponent ) ), [ "d" (* JSON-Z *) | "n" (* JSON-Z / integer only *) | "m" (* JSON-Z *) ] ;
147147
@@ -155,13 +155,13 @@ exponent = ("E" | 'e'), [ sign ], { decimal-digit }- ;
155155
```plantuml
156156
@startebnf
157157
158-
string = double-quoted-string | single-quoted-string | backtick-quoted-string (* JSON-Z *) ;
158+
string = double-quoted-string | single-quoted-string (* JSON5 *) | backtick-quoted-string (* JSON-Z *) ;
159159
160160
double-quoted-string = '"', { safe-string-character | "'" | "`" | escape }, '"';
161161
162-
single-quoted-string = "'", { safe-string-character | '"' | "`" | escape }, "'";
162+
single-quoted-string (* JSON5 *) = "'", { safe-string-character | '"' | "`" | escape }, "'";
163163
164-
backtick-quoted-string = "`", { safe-string-character (* Note: the sequence ${ must be escaped as $\{ *) | "'" | '"' | escape }, "`";
164+
backtick-quoted-string (* JSON-Z *) = "`", { safe-string-character (* Note: the sequence ${ must be escaped as $\{ *) | "'" | '"' | escape }, "`";
165165
166166
escape = "\", ( simple-escape | short-escape (* JSON5 *) | unicode-escape ) ;
167167

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ This JavaScript library is the official reference implementation for JSON-Z pars
4040
4141
## Summary of Features
4242

43-
The following features, which are not supported in standard JSON, have been added to JSON-Z. Items in **bold** are unique to JSON-Z.
43+
The following features, which are not supported in standard JSON, have been added to JSON-Z, with many inherited from JSON5. Items in **bold** are unique to JSON-Z.
4444

4545
### Objects
4646

@@ -270,17 +270,18 @@ This works very much like [`JSON.stringify`](https://developer.mozilla.org/en-US
270270

271271
A JSON-Z string representing the value.
272272

273-
#### Using obj.toJSON() and obj.toJSONZ()
273+
#### Using obj.toJSON(), obj.toJSON5(), and obj.toJSONZ()
274274

275275
For use with the standard `JSON.stringify()`, any object being stringified can have an optional `toJSON()` method. This way an object can explicitly tell `JSON.stringify()` how its value should be represented.
276276

277277
JSON-Z can also use an object's `toJSON()` method, but other factors might take priority as follows:
278278

279279
1. If an object has a `toJSONZ()` method, this takes the highest priority. The value returned by `toJSONZ()` can be further modified by any replacer function in effect. Note that when `toJSONZ()` is called, two arguments are passed to this function: `key` (an array index or object property name) and `holder` (the parent array or parent object (if any) of the object).
280-
2. If an object can be converted by an extended type handler, that has the next priority. When `ExtendedTypeMode.AS_FUNCTIONS` is in effect, a conversion handled by an extended type handler is final. Replacer functions can, however, further act upon extended type conversions when `ExtendedTypeMode.AS_OBJECTS` is in effect.
281-
3. `toJSON()` is the next possible value conversion, but only if `toJSONZ()` has not already taken priority.
282-
4. Any active replacer function is then applied.
283-
5. Finally, special handling for `BigInt` and "big decimal" numbers takes place.
280+
2. An object’s `toJSON5()` method has the next priority if no `toJSONZ()` method exists.
281+
3. If an object can be converted by an extended type handler, that has the next priority. When `ExtendedTypeMode.AS_FUNCTIONS` is in effect, a conversion handled by an extended type handler is final. Replacer functions can, however, further act upon extended type conversions when `ExtendedTypeMode.AS_OBJECTS` is in effect.
282+
4. `toJSON()` is the next possible value conversion if none of the three above conditions apply.
283+
5. Any active replacer function is then applied.
284+
6. Finally, special handling for `BigInt` and "big decimal" numbers takes place.
284285

285286
### JSONZ.hasBigDecimal()
286287

docs/characters.png

1.07 KB
Loading

docs/comments.png

3.73 KB
Loading

docs/extended-types.png

696 Bytes
Loading

docs/numbers.png

3.01 KB
Loading

docs/overview.png

1.26 KB
Loading

docs/simplified-numbers.png

10.4 KB
Loading

0 commit comments

Comments
 (0)