@o3co/ts.hocon 0.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.
Files changed (97) hide show
  1. package/.github/ISSUE_TEMPLATE/bug_report.md +29 -0
  2. package/.github/ISSUE_TEMPLATE/feature_request.md +23 -0
  3. package/.github/pull_request_template.md +17 -0
  4. package/.github/workflows/lint.yml +33 -0
  5. package/.github/workflows/release.yml +41 -0
  6. package/.github/workflows/test.yml +53 -0
  7. package/CHANGELOG.md +22 -0
  8. package/CONTRIBUTING.md +62 -0
  9. package/LICENSE +202 -0
  10. package/README.ja.md +195 -0
  11. package/README.md +195 -0
  12. package/SECURITY.md +20 -0
  13. package/docs/superpowers/plans/2026-03-20-ts-hocon.md +2412 -0
  14. package/docs/superpowers/specs/2026-03-20-ts-hocon-design.md +368 -0
  15. package/package.json +44 -0
  16. package/src/config.ts +108 -0
  17. package/src/errors.ts +34 -0
  18. package/src/index.ts +5 -0
  19. package/src/internal/lexer/lexer.ts +168 -0
  20. package/src/internal/lexer/token.ts +20 -0
  21. package/src/internal/parser/ast.ts +17 -0
  22. package/src/internal/parser/parser.ts +229 -0
  23. package/src/internal/resolver/resolver.ts +428 -0
  24. package/src/parse.ts +79 -0
  25. package/src/value.ts +5 -0
  26. package/src/zod.ts +12 -0
  27. package/tests/config.test.ts +100 -0
  28. package/tests/errors.test.ts +43 -0
  29. package/tests/lexer.test.ts +141 -0
  30. package/tests/lightbend/lightbend.test.ts +39 -0
  31. package/tests/lightbend/testdata/a_1.conf +1 -0
  32. package/tests/lightbend/testdata/b_2.conf +1 -0
  33. package/tests/lightbend/testdata/beanconfig/beanconfig01.conf +131 -0
  34. package/tests/lightbend/testdata/bom.conf +2 -0
  35. package/tests/lightbend/testdata/cycle.conf +1 -0
  36. package/tests/lightbend/testdata/env-variables.conf +16 -0
  37. package/tests/lightbend/testdata/equiv01/comments.conf +45 -0
  38. package/tests/lightbend/testdata/equiv01/equals.conf +41 -0
  39. package/tests/lightbend/testdata/equiv01/no-commas.conf +55 -0
  40. package/tests/lightbend/testdata/equiv01/no-root-braces.conf +40 -0
  41. package/tests/lightbend/testdata/equiv01/no-whitespace.json +1 -0
  42. package/tests/lightbend/testdata/equiv01/omit-colons.conf +44 -0
  43. package/tests/lightbend/testdata/equiv01/original.json +41 -0
  44. package/tests/lightbend/testdata/equiv01/path-keys.conf +29 -0
  45. package/tests/lightbend/testdata/equiv01/properties-style.conf +37 -0
  46. package/tests/lightbend/testdata/equiv01/substitutions.conf +41 -0
  47. package/tests/lightbend/testdata/equiv01/unquoted.conf +41 -0
  48. package/tests/lightbend/testdata/equiv02/original.json +17 -0
  49. package/tests/lightbend/testdata/equiv02/path-keys-weird-whitespace.conf +32 -0
  50. package/tests/lightbend/testdata/equiv02/path-keys.conf +9 -0
  51. package/tests/lightbend/testdata/equiv03/includes.conf +7 -0
  52. package/tests/lightbend/testdata/equiv03/letters/a.conf +6 -0
  53. package/tests/lightbend/testdata/equiv03/letters/b.json +3 -0
  54. package/tests/lightbend/testdata/equiv03/letters/c.conf +2 -0
  55. package/tests/lightbend/testdata/equiv03/letters/c.properties +1 -0
  56. package/tests/lightbend/testdata/equiv03/letters/numbers/1.conf +1 -0
  57. package/tests/lightbend/testdata/equiv03/letters/numbers/2.properties +1 -0
  58. package/tests/lightbend/testdata/equiv03/original.json +15 -0
  59. package/tests/lightbend/testdata/equiv03/root/foo.conf +1 -0
  60. package/tests/lightbend/testdata/equiv04/missing-substitutions.conf +4 -0
  61. package/tests/lightbend/testdata/equiv04/original.json +3 -0
  62. package/tests/lightbend/testdata/equiv05/original.json +16 -0
  63. package/tests/lightbend/testdata/equiv05/triple-quotes.conf +20 -0
  64. package/tests/lightbend/testdata/file-include.conf +5 -0
  65. package/tests/lightbend/testdata/include-from-list.conf +5 -0
  66. package/tests/lightbend/testdata/onclasspath.conf +2 -0
  67. package/tests/lightbend/testdata/subdir/bar-file.conf +1 -0
  68. package/tests/lightbend/testdata/subdir/bar.conf +1 -0
  69. package/tests/lightbend/testdata/subdir/baz.conf +1 -0
  70. package/tests/lightbend/testdata/subdir/foo.conf +5 -0
  71. package/tests/lightbend/testdata/test01.conf +96 -0
  72. package/tests/lightbend/testdata/test01.json +4 -0
  73. package/tests/lightbend/testdata/test01.properties +5 -0
  74. package/tests/lightbend/testdata/test02.conf +13 -0
  75. package/tests/lightbend/testdata/test03-included.conf +9 -0
  76. package/tests/lightbend/testdata/test03.conf +36 -0
  77. package/tests/lightbend/testdata/test04.conf +305 -0
  78. package/tests/lightbend/testdata/test05.conf +154 -0
  79. package/tests/lightbend/testdata/test06.conf +14 -0
  80. package/tests/lightbend/testdata/test07.conf +4 -0
  81. package/tests/lightbend/testdata/test08.conf +6 -0
  82. package/tests/lightbend/testdata/test09.conf +17 -0
  83. package/tests/lightbend/testdata/test10.conf +11 -0
  84. package/tests/lightbend/testdata/test11.conf +7 -0
  85. package/tests/lightbend/testdata/test12.conf +43 -0
  86. package/tests/lightbend/testdata/test13-application-override-substitutions.conf +1 -0
  87. package/tests/lightbend/testdata/test13-reference-bad-substitutions.conf +1 -0
  88. package/tests/lightbend/testdata/test13-reference-with-substitutions.conf +2 -0
  89. package/tests/lightbend/testdata/validate-invalid.conf +30 -0
  90. package/tests/lightbend/testdata/validate-reference.conf +32 -0
  91. package/tests/parse.test.ts +44 -0
  92. package/tests/parser.test.ts +154 -0
  93. package/tests/resolver.test.ts +159 -0
  94. package/tests/zod.test.ts +57 -0
  95. package/tsconfig.json +16 -0
  96. package/tsup.config.ts +12 -0
  97. package/vitest.config.ts +7 -0
@@ -0,0 +1,29 @@
1
+ ---
2
+ name: Bug report
3
+ about: Report a bug in ts.hocon
4
+ labels: bug
5
+ ---
6
+
7
+ ## Describe the bug
8
+
9
+ <!-- A clear and concise description of the bug. -->
10
+
11
+ ## HOCON input
12
+
13
+ ```hocon
14
+ # Minimal example that reproduces the issue
15
+ ```
16
+
17
+ ## Expected behavior
18
+
19
+ <!-- What you expected to happen. -->
20
+
21
+ ## Actual behavior
22
+
23
+ <!-- What actually happened. Include error messages or incorrect output. -->
24
+
25
+ ## Environment
26
+
27
+ - @o3co/ts.hocon version:
28
+ - Node.js version (`node --version`):
29
+ - OS:
@@ -0,0 +1,23 @@
1
+ ---
2
+ name: Feature request
3
+ about: Suggest a new feature or improvement
4
+ labels: enhancement
5
+ ---
6
+
7
+ ## Summary
8
+
9
+ <!-- One sentence describing what you want. -->
10
+
11
+ ## Motivation
12
+
13
+ <!-- Why is this needed? What problem does it solve? -->
14
+
15
+ ## Proposed API / behavior
16
+
17
+ ```ts
18
+ // Example usage
19
+ ```
20
+
21
+ ## Alternatives considered
22
+
23
+ <!-- Any other approaches you considered. -->
@@ -0,0 +1,17 @@
1
+ ## Summary
2
+
3
+ <!-- What does this PR do? -->
4
+
5
+ ## Related issue
6
+
7
+ <!-- Closes #123 -->
8
+
9
+ ## Changes
10
+
11
+ <!-- Bullet list of what changed. -->
12
+
13
+ ## Test plan
14
+
15
+ - [ ] `npm test` passes
16
+ - [ ] `npm run typecheck` passes
17
+ - [ ] New tests added for new behavior
@@ -0,0 +1,33 @@
1
+ name: Lint
2
+
3
+ on:
4
+ pull_request:
5
+ branches: [develop, main]
6
+ push:
7
+ branches: [develop, main]
8
+
9
+ jobs:
10
+ typecheck:
11
+ name: TypeScript type check
12
+ runs-on: ubuntu-latest
13
+
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+
17
+ - name: Set up pnpm
18
+ uses: pnpm/action-setup@v4
19
+
20
+ - name: Set up Node.js
21
+ uses: actions/setup-node@v4
22
+ with:
23
+ node-version: "22"
24
+ cache: pnpm
25
+
26
+ - name: Install dependencies
27
+ run: pnpm install --frozen-lockfile
28
+
29
+ - name: Type check
30
+ run: pnpm typecheck
31
+
32
+ - name: Build
33
+ run: pnpm build
@@ -0,0 +1,41 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - "v*"
7
+
8
+ jobs:
9
+ publish:
10
+ name: Publish to npm
11
+ runs-on: ubuntu-latest
12
+
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+
16
+ - name: Set up pnpm
17
+ uses: pnpm/action-setup@v4
18
+
19
+ - name: Set up Node.js
20
+ uses: actions/setup-node@v4
21
+ with:
22
+ node-version: "22"
23
+ cache: pnpm
24
+ registry-url: "https://registry.npmjs.org"
25
+
26
+ - name: Install dependencies
27
+ run: pnpm install --frozen-lockfile
28
+
29
+ - name: Type check
30
+ run: pnpm typecheck
31
+
32
+ - name: Test
33
+ run: pnpm test
34
+
35
+ - name: Build
36
+ run: pnpm build
37
+
38
+ - name: Publish
39
+ run: pnpm publish --access public --no-git-checks
40
+ env:
41
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
@@ -0,0 +1,53 @@
1
+ name: Test
2
+
3
+ on:
4
+ pull_request:
5
+ branches: [develop, main]
6
+ push:
7
+ branches: [develop, main]
8
+
9
+ jobs:
10
+ test:
11
+ name: node${{ matrix.node }} / ${{ matrix.os }}
12
+ runs-on: ${{ matrix.os }}
13
+ strategy:
14
+ fail-fast: false
15
+ matrix:
16
+ node: ["18", "20", "22"]
17
+ os: [ubuntu-latest]
18
+ include:
19
+ - node: "22"
20
+ os: macos-latest
21
+
22
+ steps:
23
+ - uses: actions/checkout@v4
24
+
25
+ - name: Set up pnpm
26
+ uses: pnpm/action-setup@v4
27
+
28
+ - name: Set up Node.js
29
+ uses: actions/setup-node@v4
30
+ with:
31
+ node-version: ${{ matrix.node }}
32
+ cache: pnpm
33
+
34
+ - name: Install dependencies
35
+ run: pnpm install --frozen-lockfile
36
+
37
+ - name: Type check
38
+ run: pnpm typecheck
39
+
40
+ - name: Test
41
+ run: pnpm test
42
+
43
+ - name: Test with coverage
44
+ if: matrix.node == '22' && matrix.os == 'ubuntu-latest'
45
+ run: pnpm coverage
46
+
47
+ - name: Upload coverage to Codecov
48
+ if: matrix.node == '22' && matrix.os == 'ubuntu-latest'
49
+ uses: codecov/codecov-action@v5
50
+ with:
51
+ token: ${{ secrets.CODECOV_TOKEN }}
52
+ slug: o3co/ts.hocon
53
+ fail_ci_if_error: false
package/CHANGELOG.md ADDED
@@ -0,0 +1,22 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.1.0] — 2026-03-20
9
+
10
+ ### Added
11
+
12
+ - Full HOCON parser: Lexer → Parser → Resolver → Config pipeline
13
+ - Two-pass resolver with substitution (`${path}`, `${?path}`), concat, env fallback, self-referential substitution, cycle detection
14
+ - `include "file"` and `include file("file")` directives with circular include detection
15
+ - `parse()`, `parseAsync()`, `parseFile()`, `parseFileAsync()` public API
16
+ - `Config` class: `get`, `getString`, `getNumber`, `getBoolean`, `getConfig`, `getList`, `has`, `keys`, `withFallback`, `toObject`
17
+ - Zod integration: `validate(config, schema)` and `getValidated(config, path, schema)` via `@o3co/ts.hocon/zod`
18
+ - ESM + CJS dual package via tsup
19
+ - Browser compatible (`parse`/`parseAsync`)
20
+ - TypeScript strict mode throughout
21
+ - Lightbend official test suite: 13/13 test groups passing
22
+ - 109 tests total
@@ -0,0 +1,62 @@
1
+ # Contributing to ts.hocon
2
+
3
+ Thank you for your interest in contributing!
4
+
5
+ ## Reporting Bugs
6
+
7
+ Please open a [GitHub Issue](https://github.com/o3co/ts.hocon/issues) and include:
8
+
9
+ - Node.js version (`node --version`)
10
+ - @o3co/ts.hocon version
11
+ - A minimal reproducing HOCON snippet
12
+ - Expected vs. actual behavior
13
+
14
+ ## Proposing Features
15
+
16
+ Open an issue first to discuss the proposal before sending a PR. This avoids wasted effort if the direction doesn't fit the project scope.
17
+
18
+ ## Development Setup
19
+
20
+ ```bash
21
+ git clone https://github.com/o3co/ts.hocon.git
22
+ cd ts.hocon
23
+ pnpm install
24
+ pnpm test
25
+ ```
26
+
27
+ ## Running Tests
28
+
29
+ ```bash
30
+ # All tests
31
+ pnpm test
32
+
33
+ # Watch mode
34
+ pnpm test:watch
35
+
36
+ # With coverage
37
+ pnpm coverage
38
+
39
+ # Type check only
40
+ pnpm typecheck
41
+
42
+ # Lightbend spec compliance suite
43
+ pnpm vitest run tests/lightbend/
44
+ ```
45
+
46
+ ## Code Style
47
+
48
+ - TypeScript strict mode throughout — no `any` unless unavoidable
49
+ - Keep public API consistent with the existing throwing / `undefined`-return dual pattern
50
+ - New features must include tests
51
+ - Internal modules (`src/internal/`) are not part of the public API
52
+
53
+ ## Submitting a Pull Request
54
+
55
+ 1. Fork the repository and create a branch from `develop`
56
+ 2. Write tests for your change
57
+ 3. Ensure `pnpm test` and `pnpm typecheck` pass
58
+ 4. Open a PR against `develop` with a clear description of what and why
59
+
60
+ ## License
61
+
62
+ By contributing, you agree that your contributions will be licensed under the [Apache License 2.0](LICENSE).
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 o3co Inc.
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.ja.md ADDED
@@ -0,0 +1,195 @@
1
+ # ts.hocon
2
+
3
+ [![npm](https://img.shields.io/npm/v/@o3co/ts.hocon.svg)](https://www.npmjs.com/package/@o3co/ts.hocon)
4
+ [![CI](https://github.com/o3co/ts.hocon/actions/workflows/test.yml/badge.svg)](https://github.com/o3co/ts.hocon/actions/workflows/test.yml)
5
+ [![codecov](https://codecov.io/gh/o3co/ts.hocon/branch/main/graph/badge.svg)](https://codecov.io/gh/o3co/ts.hocon)
6
+ [![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](LICENSE)
7
+
8
+ [Lightbend HOCON](https://github.com/lightbend/config/blob/main/HOCON.md) 仕様に完全準拠した TypeScript ライブラリです。
9
+
10
+ > **[Claude](https://claude.ai/)(Anthropic)による実装** — Claude Code を用いて設計・実装されました。
11
+
12
+ [English](README.md)
13
+
14
+ ---
15
+
16
+ ## 特徴
17
+
18
+ - 完全な HOCON パース:オブジェクト、配列、スカラー値、代入(`${path}`、`${?path}`)
19
+ - 自己参照代入(`path = ${path}:/extra`)
20
+ - 重複キーのディープマージ(後勝ち)
21
+ - `+=` 追加演算子
22
+ - `include "file.conf"` および `include file("file.conf")` ディレクティブ
23
+ - トリプルクォート文字列(`"""..."""`)
24
+ - 同期・非同期 API(`parse` / `parseAsync` / `parseFile` / `parseFileAsync`)
25
+ - ESM + CJS デュアルパッケージ
26
+ - [Zod](https://zod.dev/) スキーマバリデーション統合(オプション)
27
+ - ブラウザ対応(`parse`/`parseAsync` — Node.js 不要)
28
+
29
+ ## インストール
30
+
31
+ ```bash
32
+ npm install @o3co/ts.hocon
33
+ ```
34
+
35
+ Node.js 18 以上が必要です。
36
+
37
+ ## クイックスタート
38
+
39
+ ```ts
40
+ import { parse, parseFile } from '@o3co/ts.hocon'
41
+
42
+ // 文字列からパース
43
+ const cfg = parse(`
44
+ server {
45
+ host = "localhost"
46
+ port = 8080
47
+ }
48
+ `)
49
+
50
+ // ファイルからパース
51
+ const cfg = parseFile('application.conf')
52
+
53
+ // スカラーゲッター(存在しない・型が違う場合は ConfigError をスロー)
54
+ const host = cfg.getString('server.host') // "localhost"
55
+ const port = cfg.getNumber('server.port') // 8080
56
+
57
+ // 安全なアクセス
58
+ const host = cfg.get('server.host') // unknown | undefined
59
+ const exists = cfg.has('server.host') // true
60
+ ```
61
+
62
+ ## API
63
+
64
+ ### パース関数
65
+
66
+ ```ts
67
+ import { parse, parseAsync, parseFile, parseFileAsync } from '@o3co/ts.hocon'
68
+ import type { ParseOptions } from '@o3co/ts.hocon'
69
+
70
+ parse(input: string, opts?: ParseOptions): Config
71
+ parseAsync(input: string, opts?: ParseOptions): Promise<Config>
72
+ parseFile(path: string, opts?: ParseOptions): Config
73
+ parseFileAsync(path: string, opts?: ParseOptions): Promise<Config>
74
+ ```
75
+
76
+ `ParseOptions`:
77
+ | オプション | 型 | 説明 |
78
+ |----------|-----|------|
79
+ | `baseDir` | `string` | `include` 解決のベースディレクトリ |
80
+ | `env` | `Record<string, string>` | 代入で使用する環境変数(デフォルト: `process.env`) |
81
+ | `readFileSync` | `(path: string) => string` | カスタムファイルリーダー(同期) |
82
+ | `readFile` | `(path: string) => Promise<string>` | カスタムファイルリーダー(非同期) |
83
+
84
+ ### Config メソッド
85
+
86
+ | メソッド | 戻り値 | スローする条件 |
87
+ |---------|--------|--------------|
88
+ | `get(path)` | `unknown \| undefined` | — |
89
+ | `getString(path)` | `string` | 存在しない、型が違う |
90
+ | `getNumber(path)` | `number` | 存在しない、型が違う |
91
+ | `getBoolean(path)` | `boolean` | 存在しない、型が違う |
92
+ | `getConfig(path)` | `Config` | 存在しない、オブジェクトでない |
93
+ | `getList(path)` | `unknown[]` | 存在しない、配列でない |
94
+ | `has(path)` | `boolean` | — |
95
+ | `keys()` | `string[]` | — |
96
+ | `withFallback(fallback)` | `Config` | — |
97
+ | `toObject()` | `unknown` | — |
98
+
99
+ ### Zod 統合
100
+
101
+ ```ts
102
+ import { validate, getValidated } from '@o3co/ts.hocon/zod'
103
+ import { z } from 'zod'
104
+
105
+ const Schema = z.object({
106
+ server: z.object({
107
+ host: z.string(),
108
+ port: z.number().int(),
109
+ }),
110
+ })
111
+
112
+ // 設定全体をバリデート
113
+ const app = validate(cfg, Schema)
114
+
115
+ // 特定パスをバリデート
116
+ const port = getValidated(cfg, 'server.port', z.number().int())
117
+ ```
118
+
119
+ Zod をピア依存としてインストール:
120
+ ```bash
121
+ npm install zod
122
+ ```
123
+
124
+ ### エラー型
125
+
126
+ ```ts
127
+ import { ParseError, ResolveError, ConfigError } from '@o3co/ts.hocon'
128
+
129
+ // ParseError — 字句解析・構文解析エラー: .line, .col, .file?
130
+ // ResolveError — 代入・include 解決エラー: .path, .line, .col, .file?
131
+ // ConfigError — 型不一致・パス不存在エラー: .path
132
+ ```
133
+
134
+ ## HOCON の例
135
+
136
+ ```hocon
137
+ # # または // でコメント
138
+ database {
139
+ host = "db.example.com"
140
+ port = 5432
141
+ url = "jdbc:"${database.host}":"${database.port}
142
+ }
143
+
144
+ # 重複キーはディープマージ(スカラーは後勝ち)
145
+ server { host = localhost }
146
+ server { port = 8080 } // 結果: { host: "localhost", port: 8080 }
147
+
148
+ # 自己参照による追記
149
+ path = "/usr/bin"
150
+ path = ${path}":/usr/local/bin"
151
+
152
+ # += 短縮構文
153
+ items = [1]
154
+ items += 2
155
+ items += 3 // [1, 2, 3]
156
+
157
+ # Include
158
+ include "defaults.conf"
159
+ include file("overrides.conf")
160
+
161
+ # トリプルクォート複数行文字列
162
+ description = """
163
+ これは
164
+ 複数行の文字列です。
165
+ """
166
+ ```
167
+
168
+ ## 仕様準拠
169
+
170
+ [Lightbend 公式テストスイート](https://github.com/lightbend/config/tree/main/config/src/test/resources)でテスト済み: **13/13 テストグループ合格**。
171
+
172
+ v0.1.0 で未対応の機能:
173
+ - `include url(...)`
174
+ - `include classpath(...)`
175
+ - `.properties` ファイルのパース
176
+
177
+ ## ブラウザ対応
178
+
179
+ `parse()` と `parseAsync()` はブラウザで動作します。`parseFile()` と `parseFileAsync()` は Node.js(またはカスタムの `readFileSync`/`readFile` オプション)が必要です。
180
+
181
+ ```ts
182
+ // カスタムファイルローダーを使ったブラウザ利用
183
+ const cfg = await parseAsync(hoconString, {
184
+ readFile: async (path) => {
185
+ const res = await fetch(`/config/${path}`)
186
+ return res.text()
187
+ },
188
+ })
189
+ ```
190
+
191
+ ## ライセンス
192
+
193
+ Apache License 2.0 — [LICENSE](LICENSE) を参照。
194
+
195
+ Copyright 2026 o3co Inc.