soml-lang 0.0.1 → 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.
- package/distribution/edit.d.ts +56 -0
- package/distribution/edit.js +635 -0
- package/distribution/error.d.ts +49 -0
- package/distribution/error.js +156 -0
- package/distribution/format.d.ts +62 -0
- package/distribution/format.js +403 -0
- package/distribution/index.d.ts +8 -0
- package/distribution/index.js +10 -0
- package/distribution/parse.d.ts +131 -0
- package/distribution/parse.js +1587 -0
- package/distribution/shared.d.ts +102 -0
- package/distribution/shared.js +285 -0
- package/distribution/stringify.d.ts +115 -0
- package/distribution/stringify.js +473 -0
- package/distribution/tree.d.ts +264 -0
- package/distribution/tree.js +468 -0
- package/package.json +34 -34
- package/readme.md +326 -39
- package/index.d.ts +0 -151
- package/index.js +0 -3
- package/source/error.js +0 -130
- package/source/parse.js +0 -1574
- package/source/shared.js +0 -166
- package/source/stringify.js +0 -439
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// The types use the global `Temporal` types, which TypeScript has in the `esnext.temporal` lib, so a consumer whose `lib` is older gets them too.
|
|
2
|
+
// eslint-disable-next-line @typescript-eslint/triple-slash-reference -- A lib can only be loaded with a directive, and `preserve` keeps it in the emitted types.
|
|
3
|
+
/// <reference lib="esnext.temporal" preserve="true" />
|
|
4
|
+
export { parse, } from "./parse.js";
|
|
5
|
+
export { parseTree, visitorKeys, } from "./tree.js";
|
|
6
|
+
export { format, formatEdits } from "./format.js";
|
|
7
|
+
export { edit } from "./edit.js";
|
|
8
|
+
export { stringify, stringifyValue, compareKeys, } from "./stringify.js";
|
|
9
|
+
export { isBareKey } from "./shared.js";
|
|
10
|
+
export { ParseError } from "./error.js";
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
A value in a document.
|
|
3
|
+
|
|
4
|
+
| Format | JavaScript |
|
|
5
|
+
|---|---|
|
|
6
|
+
| string | `string` |
|
|
7
|
+
| int | `bigint`, or `number` with `integers: 'number'` |
|
|
8
|
+
| float | `number` |
|
|
9
|
+
| bool | `boolean` |
|
|
10
|
+
| null | `null` |
|
|
11
|
+
| instant | `Temporal.Instant` |
|
|
12
|
+
| duration | `Temporal.Duration`, in hours and smaller units |
|
|
13
|
+
| array | `Array` |
|
|
14
|
+
| object | plain `Object` |
|
|
15
|
+
*/
|
|
16
|
+
export type Value<Integer extends bigint | number = bigint> = string | Integer | number | boolean | null | Temporal.Instant | Temporal.Duration | Value<Integer>[] | ObjectValue<Integer>;
|
|
17
|
+
/**
|
|
18
|
+
An object in a document.
|
|
19
|
+
*/
|
|
20
|
+
export type ObjectValue<Integer extends bigint | number = bigint> = {
|
|
21
|
+
[key: string]: Value<Integer>;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
A whole document, which is always an object or an array.
|
|
25
|
+
*/
|
|
26
|
+
export type Document<Integer extends bigint | number = bigint> = ObjectValue<Integer> | Array<Value<Integer>>;
|
|
27
|
+
/**
|
|
28
|
+
Options for `parse()`.
|
|
29
|
+
*/
|
|
30
|
+
export type ParseOptions = {
|
|
31
|
+
/**
|
|
32
|
+
How an int is represented.
|
|
33
|
+
|
|
34
|
+
- `'bigint'`: Every int is a `bigint`, and every float is a `number`, so `3` and `3.0` stay different, and every 64-bit int is exact. This is the only conforming mode.
|
|
35
|
+
- `'number'`: Every int is a `number`. An int outside `Number.MIN_SAFE_INTEGER` to `Number.MAX_SAFE_INTEGER` throws a `ParseError` rather than being rounded. `3` and `3.0` both become `3`, so `stringify()` cannot tell them apart afterwards.
|
|
36
|
+
|
|
37
|
+
@default 'bigint'
|
|
38
|
+
*/
|
|
39
|
+
readonly integers?: 'bigint' | 'number';
|
|
40
|
+
};
|
|
41
|
+
export type ParsedValue = Value<bigint | number> | Time | ParsedValue[] | ParsedObject;
|
|
42
|
+
type ParsedObject = {
|
|
43
|
+
[key: string]: ParsedValue;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
Parse a document. Returns an object or an array, because a document is always a collection.
|
|
47
|
+
|
|
48
|
+
@param text - The document, as a string or as UTF-8 bytes. Invalid UTF-8 is reported with its position.
|
|
49
|
+
@returns The object or array the document contains.
|
|
50
|
+
@throws {ParseError} When the document is not valid.
|
|
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'`.
|
|
52
|
+
|
|
53
|
+
@example
|
|
54
|
+
```
|
|
55
|
+
import {parse} from 'soml-lang';
|
|
56
|
+
|
|
57
|
+
parse(`
|
|
58
|
+
name: 'api-gateway'
|
|
59
|
+
replicas: 3
|
|
60
|
+
timeout: 30.0
|
|
61
|
+
postgres.host: 'db.internal'
|
|
62
|
+
`);
|
|
63
|
+
//=> {name: 'api-gateway', replicas: 3n, timeout: 30, postgres: {host: 'db.internal'}}
|
|
64
|
+
|
|
65
|
+
parse('port: 8080', {integers: 'number'});
|
|
66
|
+
//=> {port: 8080}
|
|
67
|
+
```
|
|
68
|
+
*/
|
|
69
|
+
export declare function parse(text: string | Uint8Array, options?: ParseOptions & {
|
|
70
|
+
readonly integers?: 'bigint';
|
|
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
|
+
*/
|
|
96
|
+
export declare function parse(text: string | Uint8Array, options: ParseOptions & {
|
|
97
|
+
readonly integers: 'number';
|
|
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
|
+
*/
|
|
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 {};
|