@toon-format/spec 3.0.0 → 3.0.1
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/CONTRIBUTING.md +13 -5
- package/README.md +1 -1
- package/SPEC.md +3 -1
- package/package.json +1 -1
- package/tests/fixtures/decode/numbers.json +33 -0
package/CONTRIBUTING.md
CHANGED
|
@@ -95,12 +95,20 @@ Follow [SPEC.md](./SPEC.md) conventions:
|
|
|
95
95
|
- **Structure**: Number sections, cross-reference related rules
|
|
96
96
|
- **Line length**: 80-120 characters for readability
|
|
97
97
|
|
|
98
|
-
##
|
|
98
|
+
## Communication
|
|
99
99
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
100
|
+
- **GitHub Issues**: For bug reports and feature requests
|
|
101
|
+
- **GitHub Discussions**: For questions and general discussion
|
|
102
|
+
- **Pull Requests**: For code reviews and implementation discussion
|
|
103
|
+
|
|
104
|
+
## Maintainers
|
|
105
|
+
|
|
106
|
+
This is a collaborative project. Current maintainers:
|
|
107
|
+
|
|
108
|
+
- [@johannschopplich](https://github.com/johannschopplich)
|
|
109
|
+
|
|
110
|
+
All maintainers have equal and consensual decision-making power. For major architectural decisions, please open a discussion issue first.
|
|
103
111
|
|
|
104
112
|
## License
|
|
105
113
|
|
|
106
|
-
By contributing, you agree your contributions will be licensed under the MIT License.
|
|
114
|
+
By contributing, you agree your contributions will be licensed under the MIT License.
|
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# TOON Format Specification
|
|
2
2
|
|
|
3
3
|
[](./SPEC.md)
|
|
4
|
-
[](./tests/fixtures/)
|
|
5
5
|
[](./LICENSE)
|
|
6
6
|
|
|
7
7
|
This repository contains the official specification for **Token-Oriented Object Notation (TOON)**, a compact, human-readable encoding of the JSON data model for LLM prompts. It provides a lossless serialization of the same objects, arrays, and primitives as JSON, but in a syntax that minimizes tokens and makes structure easy for models to follow.
|
package/SPEC.md
CHANGED
|
@@ -217,7 +217,7 @@ Implementations that fail to conform to any MUST or REQUIRED level requirement a
|
|
|
217
217
|
- Encoders SHOULD provide an option to choose lossless stringification for out-of-range numbers.
|
|
218
218
|
- Numbers (decoding):
|
|
219
219
|
- Decoders MUST accept decimal and exponent forms on input (e.g., 42, -3.14, 1e-6, -1E+9).
|
|
220
|
-
- Decoders MUST treat tokens with forbidden leading zeros (e.g., "05"
|
|
220
|
+
- Decoders MUST treat tokens with forbidden leading zeros in the integer part (e.g., `"05"`, `"0001"`, `"-05"`, `"-0001"`) as strings, not numbers. This rule does **not** apply to a single zero integer part followed by a fractional or exponent part (e.g., `0.5`, `0e1`, `-0.5`, `-0e1`), which are valid numbers.
|
|
221
221
|
- If a decoded numeric token is not representable in the host's default numeric type without loss, implementations MAY:
|
|
222
222
|
- Return a higher-precision numeric type (e.g., arbitrary-precision integer or decimal), OR
|
|
223
223
|
- Return a string, OR
|
|
@@ -232,6 +232,7 @@ Encoders MUST normalize non-JSON values to the JSON data model before encoding.
|
|
|
232
232
|
- Number:
|
|
233
233
|
- Finite → number (canonical decimal form per Section 2). -0 → 0.
|
|
234
234
|
- NaN, +Infinity, -Infinity → null.
|
|
235
|
+
- Implementations MAY honor host-language–specific serialization hooks (for example, a `toJSON()` method in JavaScript or an equivalent mechanism) as part of host-type normalization. When supported, such hooks SHOULD be applied before other host-type mappings and their behavior MUST be documented by the implementation.
|
|
235
236
|
- Examples of host-type normalization (non-normative):
|
|
236
237
|
- Date/time objects → ISO 8601 string representation.
|
|
237
238
|
- Set-like collections → array.
|
|
@@ -1334,6 +1335,7 @@ Collection Types:
|
|
|
1334
1335
|
- `Map`: Convert to object using `String(key)` for keys and normalizing values recursively. Non-string keys are coerced to strings.
|
|
1335
1336
|
|
|
1336
1337
|
Object Types:
|
|
1338
|
+
- Objects with a `toJSON()` method: Call `value.toJSON()` and then normalize the returned value recursively before encoding. This allows domain objects to override default normalization behavior in a controlled, deterministic way (similar to `JSON.stringify`). Implementations SHOULD guard against `toJSON()` returning the same object (to avoid infinite recursion) and MAY fall back to default normalization in that case.
|
|
1337
1339
|
- Plain objects: Enumerate own enumerable string keys in encounter order; normalize values recursively.
|
|
1338
1340
|
|
|
1339
1341
|
Non-Serializable Types:
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toon-format/spec",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "3.0.
|
|
4
|
+
"version": "3.0.1",
|
|
5
5
|
"packageManager": "pnpm@10.19.0",
|
|
6
6
|
"description": "Official specification for Token-Oriented Object Notation (TOON)",
|
|
7
7
|
"author": "Johann Schopplich <hello@johannschopplich.com>",
|
|
@@ -89,6 +89,24 @@
|
|
|
89
89
|
"specSection": "4",
|
|
90
90
|
"note": "Exponent +00 results in the integer 5"
|
|
91
91
|
},
|
|
92
|
+
{
|
|
93
|
+
"name": "parses zero with exponent as number",
|
|
94
|
+
"input": "value: 0e1",
|
|
95
|
+
"expected": {
|
|
96
|
+
"value": 0
|
|
97
|
+
},
|
|
98
|
+
"specSection": "4",
|
|
99
|
+
"note": "Exponent forms with a zero integer part (0e1) are valid numbers"
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
"name": "parses negative zero with exponent as number",
|
|
103
|
+
"input": "value: -0e1",
|
|
104
|
+
"expected": {
|
|
105
|
+
"value": 0
|
|
106
|
+
},
|
|
107
|
+
"specSection": "4",
|
|
108
|
+
"note": "Negative zero with exponent (-0e1) decodes to numeric 0"
|
|
109
|
+
},
|
|
92
110
|
{
|
|
93
111
|
"name": "parses exponent notation",
|
|
94
112
|
"input": "1e6",
|
|
@@ -137,6 +155,21 @@
|
|
|
137
155
|
"input": "nums[3]: 05,007,0123",
|
|
138
156
|
"expected": { "nums": ["05", "007", "0123"] },
|
|
139
157
|
"specSection": "4"
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
"name": "treats unquoted negative leading-zero number as string",
|
|
161
|
+
"input": "-05",
|
|
162
|
+
"expected": "-05",
|
|
163
|
+
"specSection": "4",
|
|
164
|
+
"note": "Negative numbers with leading zeros in the integer part are treated as strings"
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
"name": "treats negative leading-zeros in array as strings",
|
|
168
|
+
"input": "nums[2]: -05,-007",
|
|
169
|
+
"expected": {
|
|
170
|
+
"nums": ["-05", "-007"]
|
|
171
|
+
},
|
|
172
|
+
"specSection": "4"
|
|
140
173
|
}
|
|
141
174
|
]
|
|
142
175
|
}
|