soml-lang 0.0.2 → 0.0.3

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.
@@ -24,6 +24,9 @@ export type ObjectValue<Integer extends bigint | number = bigint> = {
24
24
  A whole document, which is always an object or an array.
25
25
  */
26
26
  export type Document<Integer extends bigint | number = bigint> = ObjectValue<Integer> | Array<Value<Integer>>;
27
+ /**
28
+ Options for `parse()`.
29
+ */
27
30
  export type ParseOptions = {
28
31
  /**
29
32
  How an int is represented.
@@ -35,13 +38,17 @@ export type ParseOptions = {
35
38
  */
36
39
  readonly integers?: 'bigint' | 'number';
37
40
  };
41
+ export type ParsedValue = Value<bigint | number> | Time | ParsedValue[] | ParsedObject;
42
+ type ParsedObject = {
43
+ [key: string]: ParsedValue;
44
+ };
38
45
  /**
39
- Parse a document.
46
+ Parse a document. Returns an object or an array, because a document is always a collection.
40
47
 
41
- @param text - The document, as a string or as UTF-8 bytes.
48
+ @param text - The document, as a string or as UTF-8 bytes. Invalid UTF-8 is reported with its position.
42
49
  @returns The object or array the document contains.
43
50
  @throws {ParseError} When the document is not valid.
44
- @throws {TypeError} When `text` is not a string or a `Uint8Array`, or `options.integers` is not `'bigint'` or `'number'`.
51
+ @throws {TypeError} When `text` is not a string or a `Uint8Array`, or `options` is not an object or its `integers` is not `'bigint'` or `'number'`.
45
52
 
46
53
  @example
47
54
  ```
@@ -55,14 +62,70 @@ postgres.host: 'db.internal'
55
62
  `);
56
63
  //=> {name: 'api-gateway', replicas: 3n, timeout: 30, postgres: {host: 'db.internal'}}
57
64
 
58
- parse('replicas: 3', {integers: 'number'});
59
- //=> {replicas: 3}
65
+ parse('port: 8080', {integers: 'number'});
66
+ //=> {port: 8080}
60
67
  ```
61
68
  */
62
69
  export declare function parse(text: string | Uint8Array, options?: ParseOptions & {
63
70
  readonly integers?: 'bigint';
64
71
  }): Document;
72
+ /**
73
+ Parse a document. Returns an object or an array, because a document is always a collection.
74
+
75
+ @param text - The document, as a string or as UTF-8 bytes. Invalid UTF-8 is reported with its position.
76
+ @returns The object or array the document contains.
77
+ @throws {ParseError} When the document is not valid.
78
+ @throws {TypeError} When `text` is not a string or a `Uint8Array`, or `options` is not an object or its `integers` is not `'bigint'` or `'number'`.
79
+
80
+ @example
81
+ ```
82
+ import {parse} from 'soml-lang';
83
+
84
+ parse(`
85
+ name: 'api-gateway'
86
+ replicas: 3
87
+ timeout: 30.0
88
+ postgres.host: 'db.internal'
89
+ `);
90
+ //=> {name: 'api-gateway', replicas: 3n, timeout: 30, postgres: {host: 'db.internal'}}
91
+
92
+ parse('port: 8080', {integers: 'number'});
93
+ //=> {port: 8080}
94
+ ```
95
+ */
65
96
  export declare function parse(text: string | Uint8Array, options: ParseOptions & {
66
97
  readonly integers: 'number';
67
98
  }): Document<number>;
99
+ /**
100
+ Parse a document. Returns an object or an array, because a document is always a collection.
101
+
102
+ @param text - The document, as a string or as UTF-8 bytes. Invalid UTF-8 is reported with its position.
103
+ @returns The object or array the document contains.
104
+ @throws {ParseError} When the document is not valid.
105
+ @throws {TypeError} When `text` is not a string or a `Uint8Array`, or `options` is not an object or its `integers` is not `'bigint'` or `'number'`.
106
+
107
+ @example
108
+ ```
109
+ import {parse} from 'soml-lang';
110
+
111
+ parse(`
112
+ name: 'api-gateway'
113
+ replicas: 3
114
+ timeout: 30.0
115
+ postgres.host: 'db.internal'
116
+ `);
117
+ //=> {name: 'api-gateway', replicas: 3n, timeout: 30, postgres: {host: 'db.internal'}}
118
+
119
+ parse('port: 8080', {integers: 'number'});
120
+ //=> {port: 8080}
121
+ ```
122
+ */
68
123
  export declare function parse(text: string | Uint8Array, options?: ParseOptions): Document | Document<number>;
124
+ export declare class Time {
125
+ readonly type: 'Instant' | 'Duration';
126
+ readonly nanoseconds: bigint;
127
+ constructor(type: 'Instant' | 'Duration', nanoseconds: bigint);
128
+ toTemporal(): Temporal.Instant | Temporal.Duration;
129
+ }
130
+ export declare function parseWithTimes(text: string): ParsedObject | ParsedValue[];
131
+ export {};