@o3co/ts.hocon 0.1.5 → 1.1.0
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/README.md +45 -0
- package/dist/index.cjs +1259 -516
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1259 -516
- package/dist/{parse-C1NDMzD5.d.cts → parse-nNbyqnOh.d.cts} +11 -6
- package/dist/{parse-C1NDMzD5.d.ts → parse-nNbyqnOh.d.ts} +11 -6
- package/dist/zod.cjs +1249 -514
- package/dist/zod.d.cts +1 -1
- package/dist/zod.d.ts +1 -1
- package/dist/zod.js +1249 -514
- package/package.json +10 -2
package/README.md
CHANGED
|
@@ -64,6 +64,7 @@ HOCON gives you the readability of YAML, the structure of JSON, and features tha
|
|
|
64
64
|
- `+=` append operator
|
|
65
65
|
- `include "file.conf"` and `include file("file.conf")` directives
|
|
66
66
|
- Triple-quoted strings (`"""..."""`)
|
|
67
|
+
- Duration and byte size parsing (`getDuration()`, `getBytes()`)
|
|
67
68
|
- Sync and async API (`parse` / `parseAsync` / `parseFile` / `parseFileAsync`)
|
|
68
69
|
- ESM + CJS dual package
|
|
69
70
|
- Optional [Zod](https://zod.dev/) integration for schema validation
|
|
@@ -71,6 +72,8 @@ HOCON gives you the readability of YAML, the structure of JSON, and features tha
|
|
|
71
72
|
|
|
72
73
|
## API
|
|
73
74
|
|
|
75
|
+
For full API documentation, see [o3co.github.io/ts.hocon](https://o3co.github.io/ts.hocon/) (generated with TypeDoc, updated on each minor/major release).
|
|
76
|
+
|
|
74
77
|
### Parse functions
|
|
75
78
|
|
|
76
79
|
```ts
|
|
@@ -101,6 +104,8 @@ parseFileAsync(path: string, opts?: ParseOptions): Promise<Config>
|
|
|
101
104
|
| `getBoolean(path)` | `boolean` | missing, wrong type |
|
|
102
105
|
| `getConfig(path)` | `Config` | missing, not an object |
|
|
103
106
|
| `getList(path)` | `unknown[]` | missing, not an array |
|
|
107
|
+
| `getDuration(path, unit?)` | `number` | missing, not a string, or invalid duration format |
|
|
108
|
+
| `getBytes(path, unit?)` | `number` | missing, not a string, or invalid byte size format |
|
|
104
109
|
| `has(path)` | `boolean` | — |
|
|
105
110
|
| `keys()` | `string[]` | — |
|
|
106
111
|
| `withFallback(fallback)` | `Config` | — |
|
|
@@ -175,13 +180,37 @@ description = """
|
|
|
175
180
|
"""
|
|
176
181
|
```
|
|
177
182
|
|
|
183
|
+
### Duration and Byte Sizes
|
|
184
|
+
|
|
185
|
+
```ts
|
|
186
|
+
const c = parse(`
|
|
187
|
+
timeout = "30s"
|
|
188
|
+
cache-ttl = "5m"
|
|
189
|
+
max-size = "512MiB"
|
|
190
|
+
`)
|
|
191
|
+
|
|
192
|
+
c.getDuration('timeout') // 30000 (ms)
|
|
193
|
+
c.getDuration('timeout', 's') // 30
|
|
194
|
+
c.getDuration('cache-ttl', 'm') // 5
|
|
195
|
+
|
|
196
|
+
c.getBytes('max-size') // 536870912 (bytes)
|
|
197
|
+
c.getBytes('max-size', 'MiB') // 512
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Supported duration units: `ns`, `us`, `ms`, `s`, `m`, `h`, `d` (and long forms like `seconds`, `minutes`).
|
|
201
|
+
Supported byte units: `B`, `KB`/`KiB`, `MB`/`MiB`, `GB`/`GiB`, `TB`/`TiB` (and long forms like `megabytes`, `mebibytes`).
|
|
202
|
+
|
|
178
203
|
## Spec Compliance
|
|
179
204
|
|
|
180
205
|
Tested against the [Lightbend official test suite](https://github.com/lightbend/config/tree/main/config/src/test/resources): **13/13 test groups pass**.
|
|
181
206
|
|
|
182
207
|
Not supported in v0.1.0:
|
|
208
|
+
|
|
183
209
|
- `include url(...)`
|
|
184
210
|
- `include classpath(...)`
|
|
211
|
+
|
|
212
|
+
Supported since v0.2.0 (P1):
|
|
213
|
+
|
|
185
214
|
- `.properties` file parsing
|
|
186
215
|
|
|
187
216
|
## Performance
|
|
@@ -296,6 +325,22 @@ const config = parseWithSchema(hoconInput, schema) // fails fast on startup
|
|
|
296
325
|
|
|
297
326
|
All implementations are full Lightbend HOCON spec compliant.
|
|
298
327
|
|
|
328
|
+
## Known Limitations
|
|
329
|
+
|
|
330
|
+
- **`include url(...)`** is not supported. Fetching remote configuration is outside the scope of this parser. Use your application's HTTP client to fetch the content, then pass it to `parse()`.
|
|
331
|
+
- **`include classpath(...)`** is not supported. This is a JVM-specific include form with no equivalent outside Java runtimes.
|
|
332
|
+
- **No watch/reload** — the library parses config at load time. For live-reloading, re-call `parse()` or `parseFile()` on change.
|
|
333
|
+
- **No streaming parser** — the entire input is loaded into memory. For very large configs, validate input size before parsing (see Security Considerations).
|
|
334
|
+
- **`.properties` include** — supports basic `key=value` / `key:value` syntax. Does not support multiline values (backslash continuation), Unicode escapes, or key escaping from the full Java .properties specification.
|
|
335
|
+
|
|
336
|
+
## Security Considerations
|
|
337
|
+
|
|
338
|
+
When parsing untrusted HOCON input, be aware of:
|
|
339
|
+
|
|
340
|
+
- **Path traversal in includes:** `include "../../../etc/passwd"` will resolve relative to `baseDir`. Use a custom `readFileSync`/`readFile` that validates paths if parsing untrusted input.
|
|
341
|
+
- **Input size:** The parser has no built-in input size limit. For untrusted input, validate size before calling `parse()`.
|
|
342
|
+
- **Include depth:** Limited to 50 levels to prevent stack overflow from deep include chains.
|
|
343
|
+
|
|
299
344
|
## License
|
|
300
345
|
|
|
301
346
|
Apache License 2.0 — see [LICENSE](LICENSE).
|