@o3co/ts.hocon 1.13.0 → 1.14.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.
Files changed (43) hide show
  1. package/README.ja.md +253 -29
  2. package/README.md +161 -29
  3. package/dist/adapters/env.cjs +26 -2018
  4. package/dist/adapters/env.d.cts +1 -1
  5. package/dist/adapters/env.d.ts +1 -1
  6. package/dist/adapters/env.js +11 -1965
  7. package/dist/adapters/json5.cjs +15 -1969
  8. package/dist/adapters/json5.d.cts +1 -1
  9. package/dist/adapters/json5.d.ts +1 -1
  10. package/dist/adapters/json5.js +12 -1929
  11. package/dist/adapters/jsonc.cjs +17 -1972
  12. package/dist/adapters/jsonc.d.cts +1 -1
  13. package/dist/adapters/jsonc.d.ts +1 -1
  14. package/dist/adapters/jsonc.js +9 -1926
  15. package/dist/adapters/properties.cjs +7 -2113
  16. package/dist/adapters/properties.d.cts +1 -1
  17. package/dist/adapters/properties.d.ts +1 -1
  18. package/dist/adapters/properties.js +6 -2075
  19. package/dist/adapters/toml.cjs +12 -1966
  20. package/dist/adapters/toml.d.cts +1 -1
  21. package/dist/adapters/toml.d.ts +1 -1
  22. package/dist/adapters/toml.js +10 -1929
  23. package/dist/adapters/yaml.cjs +20 -1975
  24. package/dist/adapters/yaml.d.cts +1 -1
  25. package/dist/adapters/yaml.d.ts +1 -1
  26. package/dist/adapters/yaml.js +10 -1929
  27. package/dist/chunk-GOXMKYWS.js +3801 -0
  28. package/dist/chunk-JVABBNF5.js +158 -0
  29. package/dist/chunk-L3D2RE2U.cjs +3801 -0
  30. package/dist/chunk-OUPKYWL3.cjs +158 -0
  31. package/dist/chunk-PCAMDXJ4.cjs +83 -0
  32. package/dist/chunk-YRNDXYGQ.js +83 -0
  33. package/dist/{config-6sApTEMM.d.cts → config-OccaKqXu.d.cts} +126 -4
  34. package/dist/{config-6sApTEMM.d.ts → config-OccaKqXu.d.ts} +126 -4
  35. package/dist/index.cjs +34 -3793
  36. package/dist/index.d.cts +2 -2
  37. package/dist/index.d.ts +2 -2
  38. package/dist/index.js +25 -3728
  39. package/dist/zod.cjs +195 -3636
  40. package/dist/zod.d.cts +86 -3
  41. package/dist/zod.d.ts +86 -3
  42. package/dist/zod.js +182 -3589
  43. package/package.json +5 -5
@@ -0,0 +1,158 @@
1
+ import {
2
+ Config,
3
+ ConfigError,
4
+ ParseError,
5
+ buildTree,
6
+ buildTreeAsync,
7
+ containsPlaceholders,
8
+ guardStackDepth,
9
+ guardStackDepthAsync,
10
+ parseTokens,
11
+ resolve,
12
+ resolveAsync,
13
+ tokenize
14
+ } from "./chunk-GOXMKYWS.js";
15
+
16
+ // src/parse.ts
17
+ import * as fs from "fs";
18
+ import * as path from "path";
19
+ function defaultParseOptions() {
20
+ return { resolveSubstitutions: true };
21
+ }
22
+ function defaultResolveOptions() {
23
+ return { useSystemEnvironment: true, allowUnresolved: false };
24
+ }
25
+ function getEnv(opts) {
26
+ if (opts.env !== void 0) return opts.env;
27
+ if (typeof process !== "undefined" && process.env) return process.env;
28
+ return {};
29
+ }
30
+ function defaultReadFileSync(filePath) {
31
+ return fs.readFileSync(filePath, "utf-8");
32
+ }
33
+ async function defaultReadFile(filePath) {
34
+ return fs.promises.readFile(filePath, "utf-8");
35
+ }
36
+ function buildResolveContext(input, opts) {
37
+ const tokens = tokenize(input);
38
+ const ast = parseTokens(tokens);
39
+ if (ast.kind === "array") {
40
+ const origin = opts.originDescription ?? "input";
41
+ throw new ConfigError(
42
+ `${origin}: ${ast.pos.line}:${ast.pos.col}: document has type array rather than object at file root (HOCON.md L989-991); the Config API requires an object root`,
43
+ ""
44
+ );
45
+ }
46
+ const resolveOpts = {
47
+ env: getEnv(opts),
48
+ baseDir: opts.baseDir,
49
+ readFileSync: opts.readFileSync ?? defaultReadFileSync,
50
+ readFile: opts.readFile,
51
+ originDescription: opts.originDescription,
52
+ resolveFrom: opts.resolveFrom,
53
+ packageResolver: opts.packageResolver
54
+ };
55
+ return { ast, resolveOpts };
56
+ }
57
+ function parse(input, opts = {}) {
58
+ return parseStringWithOptions(input, opts);
59
+ }
60
+ var parseString = parse;
61
+ function parseStringWithOptions(input, opts = {}) {
62
+ return guardStackDepth(
63
+ () => parseStringInner(input, opts),
64
+ (msg) => new ParseError(msg, 1, 1, opts.originDescription)
65
+ );
66
+ }
67
+ function parseStringInner(input, opts) {
68
+ const resolveSubstitutions = opts.resolveSubstitutions ?? true;
69
+ const { ast, resolveOpts } = buildResolveContext(input, opts);
70
+ if (resolveSubstitutions) {
71
+ const value = resolve(ast, resolveOpts);
72
+ if (value.kind !== "object") throw new Error("resolved value is not an object");
73
+ return new Config(value, { resolved: true, originDescription: opts.originDescription });
74
+ }
75
+ const tree = buildTree(ast, resolveOpts);
76
+ const hasPlaceholders = containsPlaceholders(tree);
77
+ return Config._fromUnresolvedResObj(tree, {
78
+ parseBaseDir: opts.baseDir,
79
+ originDescription: opts.originDescription,
80
+ resolved: !hasPlaceholders,
81
+ resolveOpts
82
+ });
83
+ }
84
+ function parseFileWithOptions(filePath, opts = {}) {
85
+ if (typeof process === "undefined" && !opts.readFileSync) {
86
+ throw new Error("parseFileWithOptions is not supported in browser environments without opts.readFileSync.");
87
+ }
88
+ const resolvedPath = path.resolve(filePath);
89
+ const readFileSync2 = opts.readFileSync ?? defaultReadFileSync;
90
+ const input = readFileSync2(resolvedPath);
91
+ return parseStringWithOptions(input, {
92
+ ...opts,
93
+ baseDir: opts.baseDir ?? path.dirname(resolvedPath),
94
+ readFileSync: readFileSync2
95
+ });
96
+ }
97
+ async function parseAsync(input, opts = {}) {
98
+ return guardStackDepthAsync(
99
+ () => parseStringInnerAsync(input, opts),
100
+ (msg) => new ParseError(msg, 1, 1, opts.originDescription)
101
+ );
102
+ }
103
+ async function parseStringInnerAsync(input, opts) {
104
+ const resolveSubstitutions = opts.resolveSubstitutions ?? true;
105
+ const { ast, resolveOpts } = buildResolveContext(input, opts);
106
+ if (resolveSubstitutions) {
107
+ const value = await resolveAsync(ast, resolveOpts);
108
+ if (value.kind !== "object") throw new Error("resolved value is not an object");
109
+ return new Config(value, { resolved: true, originDescription: opts.originDescription });
110
+ }
111
+ const tree = await buildTreeAsync(ast, resolveOpts);
112
+ const hasPlaceholders = containsPlaceholders(tree);
113
+ return Config._fromUnresolvedResObj(tree, {
114
+ parseBaseDir: opts.baseDir,
115
+ originDescription: opts.originDescription,
116
+ resolved: !hasPlaceholders,
117
+ resolveOpts
118
+ });
119
+ }
120
+ function parseFile(filePath, opts = {}) {
121
+ if (typeof process === "undefined" && !opts.readFileSync) {
122
+ throw new Error("parseFile is not supported in browser environments. Provide opts.readFileSync or use parse() instead.");
123
+ }
124
+ const resolvedPath = path.resolve(filePath);
125
+ const readFileSync2 = opts.readFileSync ?? defaultReadFileSync;
126
+ const input = readFileSync2(resolvedPath);
127
+ return parse(input, {
128
+ ...opts,
129
+ baseDir: opts.baseDir ?? path.dirname(resolvedPath),
130
+ readFileSync: readFileSync2
131
+ });
132
+ }
133
+ async function parseFileAsync(filePath, opts = {}) {
134
+ if (typeof process === "undefined" && !opts.readFile) {
135
+ throw new Error("parseFileAsync is not supported in browser environments. Provide opts.readFile or use parseAsync() instead.");
136
+ }
137
+ const resolvedPath = path.resolve(filePath);
138
+ const readFile = opts.readFile ?? defaultReadFile;
139
+ const input = await readFile(resolvedPath);
140
+ return parseAsync(input, {
141
+ ...opts,
142
+ baseDir: opts.baseDir ?? path.dirname(resolvedPath),
143
+ readFile,
144
+ readFileSync: opts.readFileSync ?? defaultReadFileSync
145
+ });
146
+ }
147
+
148
+ export {
149
+ defaultParseOptions,
150
+ defaultResolveOptions,
151
+ parse,
152
+ parseString,
153
+ parseStringWithOptions,
154
+ parseFileWithOptions,
155
+ parseAsync,
156
+ parseFile,
157
+ parseFileAsync
158
+ };