@o3co/ts.hocon 0.1.4 → 1.0.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.ja.md CHANGED
@@ -1,4 +1,4 @@
1
- # ts.hocon
1
+ # ts.hocon — TypeScript 向け HOCON パーサー
2
2
 
3
3
  [![npm](https://img.shields.io/npm/v/@o3co/ts.hocon.svg)](https://www.npmjs.com/package/@o3co/ts.hocon)
4
4
  [![CI](https://github.com/o3co/ts.hocon/actions/workflows/test.yml/badge.svg)](https://github.com/o3co/ts.hocon/actions/workflows/test.yml)
@@ -288,11 +288,11 @@ const config = parseWithSchema(hoconInput, schema) // 起動時に即座に失
288
288
 
289
289
  ## 関連プロジェクト
290
290
 
291
- | プロジェクト | 言語 | 説明 |
292
- |---------|----------|-------------|
293
- | [go.hocon](https://github.com/o3co/go.hocon) | Go | Go 向け HOCON パーサー |
294
- | [rs.hocon](https://github.com/o3co/rs.hocon) | Rust | Rust 向け HOCON パーサー |
295
- | [hocon2](https://github.com/o3co/hocon2) | Go | HOCON → JSON/YAML/TOML/Properties 変換 CLI ツール |
291
+ | プロジェクト | 言語 | レジストリ | 説明 |
292
+ |---------|----------|----------|-------------|
293
+ | [go.hocon](https://github.com/o3co/go.hocon) | Go | [pkg.go.dev](https://pkg.go.dev/github.com/o3co/go.hocon) | Go 向け HOCON パーサー |
294
+ | [rs.hocon](https://github.com/o3co/rs.hocon) | Rust | [crates.io](https://crates.io/crates/o3co-hocon) | Rust 向け HOCON パーサー |
295
+ | [hocon2](https://github.com/o3co/hocon2) | Go | [pkg.go.dev](https://pkg.go.dev/github.com/o3co/hocon2) | HOCON → JSON/YAML/TOML/Properties 変換 CLI |
296
296
 
297
297
  すべての実装が Lightbend HOCON 仕様に完全準拠しています。
298
298
 
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # ts.hocon
1
+ # ts.hocon — HOCON Parser for TypeScript
2
2
 
3
3
  [![npm](https://img.shields.io/npm/v/@o3co/ts.hocon.svg)](https://www.npmjs.com/package/@o3co/ts.hocon)
4
4
  [![CI](https://github.com/o3co/ts.hocon/actions/workflows/test.yml/badge.svg)](https://github.com/o3co/ts.hocon/actions/workflows/test.yml)
@@ -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
@@ -288,14 +317,30 @@ const config = parseWithSchema(hoconInput, schema) // fails fast on startup
288
317
 
289
318
  ## Related Projects
290
319
 
291
- | Project | Language | Description |
292
- |---------|----------|-------------|
293
- | [go.hocon](https://github.com/o3co/go.hocon) | Go | HOCON parser for Go |
294
- | [rs.hocon](https://github.com/o3co/rs.hocon) | Rust | HOCON parser for Rust |
295
- | [hocon2](https://github.com/o3co/hocon2) | Go | CLI tools to convert HOCON → JSON/YAML/TOML/Properties |
320
+ | Project | Language | Registry | Description |
321
+ |---------|----------|----------|-------------|
322
+ | [go.hocon](https://github.com/o3co/go.hocon) | Go | [pkg.go.dev](https://pkg.go.dev/github.com/o3co/go.hocon) | HOCON parser for Go |
323
+ | [rs.hocon](https://github.com/o3co/rs.hocon) | Rust | [crates.io](https://crates.io/crates/o3co-hocon) | HOCON parser for Rust |
324
+ | [hocon2](https://github.com/o3co/hocon2) | Go | [pkg.go.dev](https://pkg.go.dev/github.com/o3co/hocon2) | HOCON → JSON/YAML/TOML/Properties CLI |
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).