@elaraai/east 0.0.1-beta.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/LICENSE.md +682 -0
- package/README.md +276 -0
- package/dist/src/analyze.d.ts +95 -0
- package/dist/src/analyze.d.ts.map +1 -0
- package/dist/src/analyze.js +1110 -0
- package/dist/src/analyze.js.map +1 -0
- package/dist/src/ast.d.ts +263 -0
- package/dist/src/ast.d.ts.map +1 -0
- package/dist/src/ast.js +151 -0
- package/dist/src/ast.js.map +1 -0
- package/dist/src/ast_to_ir.d.ts +24 -0
- package/dist/src/ast_to_ir.d.ts.map +1 -0
- package/dist/src/ast_to_ir.js +834 -0
- package/dist/src/ast_to_ir.js.map +1 -0
- package/dist/src/builtins.d.ts +18 -0
- package/dist/src/builtins.d.ts.map +1 -0
- package/dist/src/builtins.js +1105 -0
- package/dist/src/builtins.js.map +1 -0
- package/dist/src/comparison.d.ts +28 -0
- package/dist/src/comparison.d.ts.map +1 -0
- package/dist/src/comparison.js +1017 -0
- package/dist/src/comparison.js.map +1 -0
- package/dist/src/compile.d.ts +22 -0
- package/dist/src/compile.d.ts.map +1 -0
- package/dist/src/compile.js +3260 -0
- package/dist/src/compile.js.map +1 -0
- package/dist/src/containers/ref.d.ts +106 -0
- package/dist/src/containers/ref.d.ts.map +1 -0
- package/dist/src/containers/ref.js +100 -0
- package/dist/src/containers/ref.js.map +1 -0
- package/dist/src/containers/sortedmap.d.ts +165 -0
- package/dist/src/containers/sortedmap.d.ts.map +1 -0
- package/dist/src/containers/sortedmap.js +237 -0
- package/dist/src/containers/sortedmap.js.map +1 -0
- package/dist/src/containers/sortedset.d.ts +185 -0
- package/dist/src/containers/sortedset.d.ts.map +1 -0
- package/dist/src/containers/sortedset.js +312 -0
- package/dist/src/containers/sortedset.js.map +1 -0
- package/dist/src/containers/variant.d.ts +131 -0
- package/dist/src/containers/variant.d.ts.map +1 -0
- package/dist/src/containers/variant.js +68 -0
- package/dist/src/containers/variant.js.map +1 -0
- package/dist/src/datetime_format/parse.d.ts +50 -0
- package/dist/src/datetime_format/parse.d.ts.map +1 -0
- package/dist/src/datetime_format/parse.js +908 -0
- package/dist/src/datetime_format/parse.js.map +1 -0
- package/dist/src/datetime_format/print.d.ts +35 -0
- package/dist/src/datetime_format/print.d.ts.map +1 -0
- package/dist/src/datetime_format/print.js +157 -0
- package/dist/src/datetime_format/print.js.map +1 -0
- package/dist/src/datetime_format/tokenize.d.ts +76 -0
- package/dist/src/datetime_format/tokenize.d.ts.map +1 -0
- package/dist/src/datetime_format/tokenize.js +271 -0
- package/dist/src/datetime_format/tokenize.js.map +1 -0
- package/dist/src/datetime_format/types.d.ts +99 -0
- package/dist/src/datetime_format/types.d.ts.map +1 -0
- package/dist/src/datetime_format/types.js +103 -0
- package/dist/src/datetime_format/types.js.map +1 -0
- package/dist/src/datetime_format/validate.d.ts +51 -0
- package/dist/src/datetime_format/validate.d.ts.map +1 -0
- package/dist/src/datetime_format/validate.js +208 -0
- package/dist/src/datetime_format/validate.js.map +1 -0
- package/dist/src/default.d.ts +21 -0
- package/dist/src/default.d.ts.map +1 -0
- package/dist/src/default.js +82 -0
- package/dist/src/default.js.map +1 -0
- package/dist/src/eastir.d.ts +33 -0
- package/dist/src/eastir.d.ts.map +1 -0
- package/dist/src/eastir.js +92 -0
- package/dist/src/eastir.js.map +1 -0
- package/dist/src/error.d.ts +13 -0
- package/dist/src/error.d.ts.map +1 -0
- package/dist/src/error.js +8 -0
- package/dist/src/error.js.map +1 -0
- package/dist/src/expr/array.d.ts +1711 -0
- package/dist/src/expr/array.d.ts.map +1 -0
- package/dist/src/expr/array.js +1805 -0
- package/dist/src/expr/array.js.map +1 -0
- package/dist/src/expr/ast.d.ts +17 -0
- package/dist/src/expr/ast.d.ts.map +1 -0
- package/dist/src/expr/ast.js +302 -0
- package/dist/src/expr/ast.js.map +1 -0
- package/dist/src/expr/blob.d.ts +141 -0
- package/dist/src/expr/blob.d.ts.map +1 -0
- package/dist/src/expr/blob.js +198 -0
- package/dist/src/expr/blob.js.map +1 -0
- package/dist/src/expr/block.d.ts +201 -0
- package/dist/src/expr/block.d.ts.map +1 -0
- package/dist/src/expr/block.js +1505 -0
- package/dist/src/expr/block.js.map +1 -0
- package/dist/src/expr/boolean.d.ts +207 -0
- package/dist/src/expr/boolean.d.ts.map +1 -0
- package/dist/src/expr/boolean.js +261 -0
- package/dist/src/expr/boolean.js.map +1 -0
- package/dist/src/expr/datetime.d.ts +544 -0
- package/dist/src/expr/datetime.d.ts.map +1 -0
- package/dist/src/expr/datetime.js +980 -0
- package/dist/src/expr/datetime.js.map +1 -0
- package/dist/src/expr/dict.d.ts +1242 -0
- package/dist/src/expr/dict.d.ts.map +1 -0
- package/dist/src/expr/dict.js +1492 -0
- package/dist/src/expr/dict.js.map +1 -0
- package/dist/src/expr/expr.d.ts +95 -0
- package/dist/src/expr/expr.d.ts.map +1 -0
- package/dist/src/expr/expr.js +171 -0
- package/dist/src/expr/expr.js.map +1 -0
- package/dist/src/expr/float.d.ts +357 -0
- package/dist/src/expr/float.d.ts.map +1 -0
- package/dist/src/expr/float.js +637 -0
- package/dist/src/expr/float.js.map +1 -0
- package/dist/src/expr/function.d.ts +46 -0
- package/dist/src/expr/function.d.ts.map +1 -0
- package/dist/src/expr/function.js +58 -0
- package/dist/src/expr/function.js.map +1 -0
- package/dist/src/expr/index.d.ts +450 -0
- package/dist/src/expr/index.d.ts.map +1 -0
- package/dist/src/expr/index.js +423 -0
- package/dist/src/expr/index.js.map +1 -0
- package/dist/src/expr/integer.d.ts +256 -0
- package/dist/src/expr/integer.d.ts.map +1 -0
- package/dist/src/expr/integer.js +311 -0
- package/dist/src/expr/integer.js.map +1 -0
- package/dist/src/expr/libs/array.d.ts +106 -0
- package/dist/src/expr/libs/array.d.ts.map +1 -0
- package/dist/src/expr/libs/array.js +140 -0
- package/dist/src/expr/libs/array.js.map +1 -0
- package/dist/src/expr/libs/blob.d.ts +42 -0
- package/dist/src/expr/libs/blob.d.ts.map +1 -0
- package/dist/src/expr/libs/blob.js +70 -0
- package/dist/src/expr/libs/blob.js.map +1 -0
- package/dist/src/expr/libs/datetime.d.ts +479 -0
- package/dist/src/expr/libs/datetime.d.ts.map +1 -0
- package/dist/src/expr/libs/datetime.js +624 -0
- package/dist/src/expr/libs/datetime.js.map +1 -0
- package/dist/src/expr/libs/dict.d.ts +66 -0
- package/dist/src/expr/libs/dict.d.ts.map +1 -0
- package/dist/src/expr/libs/dict.js +77 -0
- package/dist/src/expr/libs/dict.js.map +1 -0
- package/dist/src/expr/libs/float.d.ts +299 -0
- package/dist/src/expr/libs/float.d.ts.map +1 -0
- package/dist/src/expr/libs/float.js +564 -0
- package/dist/src/expr/libs/float.js.map +1 -0
- package/dist/src/expr/libs/integer.d.ts +228 -0
- package/dist/src/expr/libs/integer.d.ts.map +1 -0
- package/dist/src/expr/libs/integer.js +398 -0
- package/dist/src/expr/libs/integer.js.map +1 -0
- package/dist/src/expr/libs/set.d.ts +59 -0
- package/dist/src/expr/libs/set.d.ts.map +1 -0
- package/dist/src/expr/libs/set.js +69 -0
- package/dist/src/expr/libs/set.js.map +1 -0
- package/dist/src/expr/libs/string.d.ts +71 -0
- package/dist/src/expr/libs/string.d.ts.map +1 -0
- package/dist/src/expr/libs/string.js +75 -0
- package/dist/src/expr/libs/string.js.map +1 -0
- package/dist/src/expr/never.d.ts +15 -0
- package/dist/src/expr/never.d.ts.map +1 -0
- package/dist/src/expr/never.js +12 -0
- package/dist/src/expr/never.js.map +1 -0
- package/dist/src/expr/null.d.ts +15 -0
- package/dist/src/expr/null.d.ts.map +1 -0
- package/dist/src/expr/null.js +12 -0
- package/dist/src/expr/null.js.map +1 -0
- package/dist/src/expr/ref.d.ts +103 -0
- package/dist/src/expr/ref.d.ts.map +1 -0
- package/dist/src/expr/ref.js +131 -0
- package/dist/src/expr/ref.js.map +1 -0
- package/dist/src/expr/regex_validation.d.ts +25 -0
- package/dist/src/expr/regex_validation.d.ts.map +1 -0
- package/dist/src/expr/regex_validation.js +130 -0
- package/dist/src/expr/regex_validation.js.map +1 -0
- package/dist/src/expr/set.d.ts +1071 -0
- package/dist/src/expr/set.d.ts.map +1 -0
- package/dist/src/expr/set.js +1137 -0
- package/dist/src/expr/set.js.map +1 -0
- package/dist/src/expr/string.d.ts +414 -0
- package/dist/src/expr/string.d.ts.map +1 -0
- package/dist/src/expr/string.js +683 -0
- package/dist/src/expr/string.js.map +1 -0
- package/dist/src/expr/struct.d.ts +48 -0
- package/dist/src/expr/struct.d.ts.map +1 -0
- package/dist/src/expr/struct.js +65 -0
- package/dist/src/expr/struct.js.map +1 -0
- package/dist/src/expr/types.d.ts +68 -0
- package/dist/src/expr/types.d.ts.map +1 -0
- package/dist/src/expr/types.js +6 -0
- package/dist/src/expr/types.js.map +1 -0
- package/dist/src/expr/variant.d.ts +137 -0
- package/dist/src/expr/variant.d.ts.map +1 -0
- package/dist/src/expr/variant.js +105 -0
- package/dist/src/expr/variant.js.map +1 -0
- package/dist/src/fuzz.d.ts +80 -0
- package/dist/src/fuzz.d.ts.map +1 -0
- package/dist/src/fuzz.js +300 -0
- package/dist/src/fuzz.js.map +1 -0
- package/dist/src/index.d.ts +21 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +21 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/internal.d.ts +36 -0
- package/dist/src/internal.d.ts.map +1 -0
- package/dist/src/internal.js +11 -0
- package/dist/src/internal.js.map +1 -0
- package/dist/src/ir.d.ts +1571 -0
- package/dist/src/ir.d.ts.map +1 -0
- package/dist/src/ir.js +56 -0
- package/dist/src/ir.js.map +1 -0
- package/dist/src/location.d.ts +48 -0
- package/dist/src/location.d.ts.map +1 -0
- package/dist/src/location.js +62 -0
- package/dist/src/location.js.map +1 -0
- package/dist/src/platform.d.ts +21 -0
- package/dist/src/platform.d.ts.map +1 -0
- package/dist/src/platform.js +8 -0
- package/dist/src/platform.js.map +1 -0
- package/dist/src/serialization/beast.d.ts +39 -0
- package/dist/src/serialization/beast.d.ts.map +1 -0
- package/dist/src/serialization/beast.js +555 -0
- package/dist/src/serialization/beast.js.map +1 -0
- package/dist/src/serialization/beast2-stream.d.ts +38 -0
- package/dist/src/serialization/beast2-stream.d.ts.map +1 -0
- package/dist/src/serialization/beast2-stream.js +665 -0
- package/dist/src/serialization/beast2-stream.js.map +1 -0
- package/dist/src/serialization/beast2.d.ts +41 -0
- package/dist/src/serialization/beast2.d.ts.map +1 -0
- package/dist/src/serialization/beast2.js +489 -0
- package/dist/src/serialization/beast2.js.map +1 -0
- package/dist/src/serialization/binary-utils.d.ts +151 -0
- package/dist/src/serialization/binary-utils.d.ts.map +1 -0
- package/dist/src/serialization/binary-utils.js +929 -0
- package/dist/src/serialization/binary-utils.js.map +1 -0
- package/dist/src/serialization/east.d.ts +84 -0
- package/dist/src/serialization/east.d.ts.map +1 -0
- package/dist/src/serialization/east.js +1802 -0
- package/dist/src/serialization/east.js.map +1 -0
- package/dist/src/serialization/index.d.ts +11 -0
- package/dist/src/serialization/index.d.ts.map +1 -0
- package/dist/src/serialization/index.js +12 -0
- package/dist/src/serialization/index.js.map +1 -0
- package/dist/src/serialization/json.d.ts +36 -0
- package/dist/src/serialization/json.d.ts.map +1 -0
- package/dist/src/serialization/json.js +849 -0
- package/dist/src/serialization/json.js.map +1 -0
- package/dist/src/type_of_type.d.ts +115 -0
- package/dist/src/type_of_type.d.ts.map +1 -0
- package/dist/src/type_of_type.js +362 -0
- package/dist/src/type_of_type.js.map +1 -0
- package/dist/src/types.d.ts +648 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +1631 -0
- package/dist/src/types.js.map +1 -0
- package/package.json +87 -0
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
import sorted_btree from "sorted-btree";
|
|
6
|
+
// Deal with CJS default import
|
|
7
|
+
const BTree = sorted_btree.default;
|
|
8
|
+
// Note: Enhanced SetIterator types from ES2024 aren't fully stabilized in TypeScript yet
|
|
9
|
+
// Using type assertions as temporary workaround until tooling catches up
|
|
10
|
+
/**
|
|
11
|
+
* A sorted set implementation using a B-tree data structure.
|
|
12
|
+
*
|
|
13
|
+
* @typeParam K - The type of keys stored in the set
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* Implements the ES6 `Set` interface with additional capabilities:
|
|
17
|
+
* - Maintains keys in sorted order based on a comparison function
|
|
18
|
+
* - Supports {@link minKey} and {@link maxKey} for accessing extrema
|
|
19
|
+
* - Provides range-based iteration starting from any key
|
|
20
|
+
* - Implements ES2024 set operations (union, intersection, difference, etc.)
|
|
21
|
+
* - Respects frozen state and throws errors on modification attempts
|
|
22
|
+
*
|
|
23
|
+
* Used to implement East's {@link SetType} with total ordering semantics.
|
|
24
|
+
*/
|
|
25
|
+
export class SortedSet {
|
|
26
|
+
compare;
|
|
27
|
+
btree;
|
|
28
|
+
/**
|
|
29
|
+
* Creates a new SortedSet.
|
|
30
|
+
*
|
|
31
|
+
* @param values - Optional initial values to add to the set
|
|
32
|
+
* @param compare - Optional comparison function for ordering keys
|
|
33
|
+
*
|
|
34
|
+
* @remarks
|
|
35
|
+
* If no comparison function is provided, keys are compared using default ordering.
|
|
36
|
+
*/
|
|
37
|
+
constructor(values, compare) {
|
|
38
|
+
this.compare = compare;
|
|
39
|
+
this.btree = new BTree(undefined, compare);
|
|
40
|
+
if (values !== undefined) {
|
|
41
|
+
for (const value of values) {
|
|
42
|
+
this.btree.set(value, undefined);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/** The number of elements in the set. */
|
|
47
|
+
get size() {
|
|
48
|
+
return this.btree.size;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Adds a value to the set.
|
|
52
|
+
*
|
|
53
|
+
* @param value - The value to add
|
|
54
|
+
* @returns This set for chaining
|
|
55
|
+
* @throws {TypeError} When the set is frozen
|
|
56
|
+
*/
|
|
57
|
+
add(value) {
|
|
58
|
+
if (Object.isFrozen(this)) {
|
|
59
|
+
throw new TypeError("Cannot modify frozen SortedSet");
|
|
60
|
+
}
|
|
61
|
+
this.btree.set(value, undefined);
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Removes all elements from the set.
|
|
66
|
+
*
|
|
67
|
+
* @throws {TypeError} When the set is frozen
|
|
68
|
+
*/
|
|
69
|
+
clear() {
|
|
70
|
+
if (Object.isFrozen(this)) {
|
|
71
|
+
throw new TypeError("Cannot modify frozen SortedSet");
|
|
72
|
+
}
|
|
73
|
+
this.btree.clear();
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Removes a value from the set.
|
|
77
|
+
*
|
|
78
|
+
* @param value - The value to remove
|
|
79
|
+
* @returns `true` if the value was present and removed, `false` otherwise
|
|
80
|
+
* @throws {TypeError} When the set is frozen
|
|
81
|
+
*/
|
|
82
|
+
delete(value) {
|
|
83
|
+
if (Object.isFrozen(this)) {
|
|
84
|
+
throw new TypeError("Cannot modify frozen SortedSet");
|
|
85
|
+
}
|
|
86
|
+
return this.btree.delete(value);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Checks if a value exists in the set.
|
|
90
|
+
*
|
|
91
|
+
* @param value - The value to check
|
|
92
|
+
* @returns `true` if the value is present, `false` otherwise
|
|
93
|
+
*/
|
|
94
|
+
has(value) {
|
|
95
|
+
return this.btree.has(value);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Executes a callback for each value in the set, in sorted order.
|
|
99
|
+
*
|
|
100
|
+
* @param callbackfn - Function to execute for each element
|
|
101
|
+
* @param thisArg - Value to use as `this` when executing the callback
|
|
102
|
+
*
|
|
103
|
+
* @remarks
|
|
104
|
+
* The callback receives the value twice (for ES6 Set compatibility) and the set itself.
|
|
105
|
+
*/
|
|
106
|
+
forEach(callbackfn, thisArg) {
|
|
107
|
+
for (const key of this.btree.keys()) {
|
|
108
|
+
callbackfn.call(thisArg, key, key, this);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Returns a new set containing all elements from this set and another.
|
|
113
|
+
*
|
|
114
|
+
* @typeParam U - The type of elements in the other set
|
|
115
|
+
* @param other - The set to union with
|
|
116
|
+
* @returns A new {@link SortedSet} containing all elements from both sets
|
|
117
|
+
*/
|
|
118
|
+
union(other) {
|
|
119
|
+
// Note: ReadonlySetLike.keys() returns an Iterator<U> (not Iterable),
|
|
120
|
+
// so we must consume it manually rather than using for..of.
|
|
121
|
+
const result = new SortedSet(undefined, this.compare);
|
|
122
|
+
for (const key of this.btree.keys()) {
|
|
123
|
+
result.add(key);
|
|
124
|
+
}
|
|
125
|
+
const it = other.keys();
|
|
126
|
+
for (let n = it.next(); !n.done; n = it.next()) {
|
|
127
|
+
result.add(n.value);
|
|
128
|
+
}
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Returns a new set containing only elements present in both sets.
|
|
133
|
+
*
|
|
134
|
+
* @typeParam U - The type of elements in the other set
|
|
135
|
+
* @param other - The set to intersect with
|
|
136
|
+
* @returns A new {@link SortedSet} containing common elements
|
|
137
|
+
*/
|
|
138
|
+
intersection(other) {
|
|
139
|
+
const result = new SortedSet(undefined, this.compare);
|
|
140
|
+
const it = other.keys();
|
|
141
|
+
for (let n = it.next(); !n.done; n = it.next()) {
|
|
142
|
+
const key = n.value;
|
|
143
|
+
if (this.has(key)) {
|
|
144
|
+
result.add(key);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return result;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Returns a new set containing elements in this set but not in another.
|
|
151
|
+
*
|
|
152
|
+
* @typeParam U - The type of elements in the other set
|
|
153
|
+
* @param other - The set to subtract
|
|
154
|
+
* @returns A new {@link SortedSet} with elements only in this set
|
|
155
|
+
*/
|
|
156
|
+
difference(other) {
|
|
157
|
+
const result = new SortedSet(undefined, this.compare);
|
|
158
|
+
for (const key of this.btree.keys()) {
|
|
159
|
+
if (!other.has(key)) {
|
|
160
|
+
result.add(key);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return result;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Returns a new set containing elements in either set but not both.
|
|
167
|
+
*
|
|
168
|
+
* @typeParam U - The type of elements in the other set
|
|
169
|
+
* @param other - The set to compare with
|
|
170
|
+
* @returns A new {@link SortedSet} with elements exclusive to each set
|
|
171
|
+
*/
|
|
172
|
+
symmetricDifference(other) {
|
|
173
|
+
const result = new SortedSet(undefined, this.compare);
|
|
174
|
+
for (const key of this.btree.keys()) {
|
|
175
|
+
if (!other.has(key)) {
|
|
176
|
+
result.add(key);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
const it = other.keys();
|
|
180
|
+
for (let n = it.next(); !n.done; n = it.next()) {
|
|
181
|
+
const key = n.value;
|
|
182
|
+
if (!this.has(key)) {
|
|
183
|
+
result.add(key);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return result;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Checks if this set is a subset of another set.
|
|
190
|
+
*
|
|
191
|
+
* @param other - The potential superset
|
|
192
|
+
* @returns `true` if all elements of this set are in the other set
|
|
193
|
+
*/
|
|
194
|
+
isSubsetOf(other) {
|
|
195
|
+
for (const key of this.btree.keys()) {
|
|
196
|
+
if (!other.has(key)) {
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Checks if this set is a superset of another set.
|
|
204
|
+
*
|
|
205
|
+
* @param other - The potential subset
|
|
206
|
+
* @returns `true` if all elements of the other set are in this set
|
|
207
|
+
*/
|
|
208
|
+
isSupersetOf(other) {
|
|
209
|
+
const it = other.keys();
|
|
210
|
+
for (let n = it.next(); !n.done; n = it.next()) {
|
|
211
|
+
if (!this.has(n.value)) {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return true;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Checks if this set has no elements in common with another set.
|
|
219
|
+
*
|
|
220
|
+
* @param other - The set to compare with
|
|
221
|
+
* @returns `true` if the sets share no elements, `false` otherwise
|
|
222
|
+
*/
|
|
223
|
+
isDisjointFrom(other) {
|
|
224
|
+
for (const key of this.btree.keys()) {
|
|
225
|
+
if (other.has(key)) {
|
|
226
|
+
return false;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return true;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Returns the smallest value in the set.
|
|
233
|
+
*
|
|
234
|
+
* @returns The minimum value, or `undefined` if the set is empty
|
|
235
|
+
*
|
|
236
|
+
* @remarks
|
|
237
|
+
* This is an O(log n) operation due to the B-tree structure.
|
|
238
|
+
*/
|
|
239
|
+
minKey() {
|
|
240
|
+
return this.btree.minKey();
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Returns the largest value in the set.
|
|
244
|
+
*
|
|
245
|
+
* @returns The maximum value, or `undefined` if the set is empty
|
|
246
|
+
*
|
|
247
|
+
* @remarks
|
|
248
|
+
* This is an O(log n) operation due to the B-tree structure.
|
|
249
|
+
*/
|
|
250
|
+
maxKey() {
|
|
251
|
+
return this.btree.maxKey();
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Returns an iterator over the set's keys in sorted order.
|
|
255
|
+
*
|
|
256
|
+
* @param firstKey - Optional starting key for range-based iteration
|
|
257
|
+
* @returns An iterator yielding keys in sorted order
|
|
258
|
+
*
|
|
259
|
+
* @remarks
|
|
260
|
+
* If `firstKey` is provided, iteration starts from that key (or the next key if not present).
|
|
261
|
+
* This enables efficient range queries over sorted data.
|
|
262
|
+
*/
|
|
263
|
+
keys(firstKey) {
|
|
264
|
+
return Iterator.from(this.btree.keys(firstKey));
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Returns an iterator over the set's values in sorted order.
|
|
268
|
+
*
|
|
269
|
+
* @param firstKey - Optional starting key for range-based iteration
|
|
270
|
+
* @returns An iterator yielding values in sorted order
|
|
271
|
+
*
|
|
272
|
+
* @remarks
|
|
273
|
+
* Identical to {@link keys} for sets (values and keys are the same).
|
|
274
|
+
*/
|
|
275
|
+
values(firstKey) {
|
|
276
|
+
return Iterator.from(this.btree.keys(firstKey));
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Returns an iterator over the set's entries in sorted order.
|
|
280
|
+
*
|
|
281
|
+
* @param firstKey - Optional starting key for range-based iteration
|
|
282
|
+
* @returns An iterator yielding `[key, key]` tuples in sorted order
|
|
283
|
+
*
|
|
284
|
+
* @remarks
|
|
285
|
+
* For ES6 Set compatibility, entries are `[key, key]` tuples.
|
|
286
|
+
* If `firstKey` is provided, iteration starts from that key.
|
|
287
|
+
*/
|
|
288
|
+
entries(firstKey) {
|
|
289
|
+
const gen = (function* (btree) {
|
|
290
|
+
for (const key of btree.keys(firstKey)) {
|
|
291
|
+
yield [key, key];
|
|
292
|
+
}
|
|
293
|
+
})(this.btree);
|
|
294
|
+
return Iterator.from(gen);
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Returns an iterator over the set's values in sorted order.
|
|
298
|
+
*
|
|
299
|
+
* @returns An iterator yielding values in sorted order
|
|
300
|
+
*
|
|
301
|
+
* @remarks
|
|
302
|
+
* Makes {@link SortedSet} iterable with `for...of` loops.
|
|
303
|
+
*/
|
|
304
|
+
[Symbol.iterator]() {
|
|
305
|
+
return Iterator.from(this.btree.keys());
|
|
306
|
+
}
|
|
307
|
+
/** Returns the string tag for this object type. */
|
|
308
|
+
get [Symbol.toStringTag]() {
|
|
309
|
+
return "SortedSet";
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
//# sourceMappingURL=sortedset.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sortedset.js","sourceRoot":"","sources":["../../../src/containers/sortedset.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,YAAY,MAAM,cAAc,CAAC;AAExC,+BAA+B;AAC/B,MAAM,KAAK,GAAG,YAAY,CAAC,OAAO,CAAC;AAGnC,yFAAyF;AACzF,yEAAyE;AAEzE;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,SAAS;IAYwB;IAXlC,KAAK,CAAsB;IAEnC;;;;;;;;OAQG;IACH,YAAY,MAAoB,EAAU,OAAgC;QAAhC,YAAO,GAAP,OAAO,CAAyB;QACtE,IAAI,CAAC,KAAK,GAAG,IAAI,KAAK,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAC3C,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACvB,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;gBACzB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;YACrC,CAAC;QACL,CAAC;IACL,CAAC;IAED,yCAAyC;IACzC,IAAI,IAAI;QACJ,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;IAC3B,CAAC;IAED;;;;;;OAMG;IACH,GAAG,CAAC,KAAQ;QACR,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YACxB,MAAM,IAAI,SAAS,CAAC,gCAAgC,CAAC,CAAC;QAC1D,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;QACjC,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;;;OAIG;IACH,KAAK;QACD,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YACxB,MAAM,IAAI,SAAS,CAA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;IACnD,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;QACpB,OAAO,WAAW,CAAC;IACvB,CAAC;CAEJ"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
*/
|
|
7
|
+
export declare const variant_symbol: unique symbol;
|
|
8
|
+
export type variant_symbol = typeof variant_symbol;
|
|
9
|
+
/**
|
|
10
|
+
* Represents a sum-type value with a type tag and associated value.
|
|
11
|
+
*
|
|
12
|
+
* @typeParam Type - The type of the discriminant tag
|
|
13
|
+
* @typeParam Value - The type of the associated value
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* Variants are immutable and use nominal typing via the brand symbol.
|
|
17
|
+
* This is the foundation for East's variant types (sum types).
|
|
18
|
+
*/
|
|
19
|
+
export type variant<Type = string, Value = any> = {
|
|
20
|
+
/** The discriminant tag identifying which variant case this is */
|
|
21
|
+
type: Type;
|
|
22
|
+
/** The value associated with this variant case */
|
|
23
|
+
value: Value;
|
|
24
|
+
/** Brand symbol for nominal typing */
|
|
25
|
+
[variant_symbol]: null;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Constructs a sum-type value with a specific type tag and associated value.
|
|
29
|
+
*
|
|
30
|
+
* @typeParam Type - The string literal type of the discriminant tag
|
|
31
|
+
* @typeParam Value - The type of the value to associate with this variant
|
|
32
|
+
* @param type - The discriminant tag for this variant
|
|
33
|
+
* @param value - The value to associate with this variant
|
|
34
|
+
* @returns A branded variant object
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* const success = variant("success", { data: [1, 2, 3] });
|
|
39
|
+
* const error = variant("error", "Connection failed");
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare function variant<Type extends string, Value = null>(type: Type, value?: Value): variant<Type, Value>;
|
|
43
|
+
/**
|
|
44
|
+
* Deconstructs a variant by pattern matching on its type tag.
|
|
45
|
+
*
|
|
46
|
+
* @typeParam V - The variant type to match against, must have `type` and `value` properties
|
|
47
|
+
* @typeParam Fs - Object type mapping each variant case to its handler function
|
|
48
|
+
* @typeParam Default - The type of the default value when handler is optional
|
|
49
|
+
*
|
|
50
|
+
* @param variant - The variant to match against
|
|
51
|
+
* @param fs - Object mapping type tags to handler functions
|
|
52
|
+
* @param defaultValue - Optional default value if no handler matches
|
|
53
|
+
* @returns The result of calling the matching handler function
|
|
54
|
+
*
|
|
55
|
+
* @remarks
|
|
56
|
+
* This function has two overloads:
|
|
57
|
+
* 1. All handlers required - returns the handler's return type
|
|
58
|
+
* 2. Handlers optional with default - returns handler return type or default type
|
|
59
|
+
*
|
|
60
|
+
* The type system ensures exhaustive matching when all handlers are provided,
|
|
61
|
+
* and allows partial matching when a default value is supplied.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* // Exhaustive matching (all cases required)
|
|
66
|
+
* const result = match(maybeValue, {
|
|
67
|
+
* some: (v) => v * 2,
|
|
68
|
+
* none: () => 0
|
|
69
|
+
* });
|
|
70
|
+
*
|
|
71
|
+
* // Partial matching with default
|
|
72
|
+
* const result = match(response, {
|
|
73
|
+
* success: (data) => data.length
|
|
74
|
+
* }, -1);
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export declare function match<V extends {
|
|
78
|
+
type: string;
|
|
79
|
+
value: any;
|
|
80
|
+
}, Fs extends {
|
|
81
|
+
[K in V["type"]]: (value: (V & {
|
|
82
|
+
type: K;
|
|
83
|
+
})["value"]) => any;
|
|
84
|
+
}>(variant: V, fs: Fs, defaultValue?: any): ReturnType<Fs[V["type"]]>;
|
|
85
|
+
export declare function match<V extends {
|
|
86
|
+
type: string;
|
|
87
|
+
value: any;
|
|
88
|
+
}, Fs extends {
|
|
89
|
+
[K in V["type"]]?: (value: (V & {
|
|
90
|
+
type: K;
|
|
91
|
+
})["value"]) => any;
|
|
92
|
+
}, Default extends any>(variant: V, fs: Fs, defaultValue: Default): ReturnType<Exclude<Fs[keyof Fs], undefined>> | Default;
|
|
93
|
+
/**
|
|
94
|
+
* Represents the absence of a value in an Option type.
|
|
95
|
+
*
|
|
96
|
+
* @remarks
|
|
97
|
+
* This is a singleton value representing the "none" case of the Option pattern.
|
|
98
|
+
*/
|
|
99
|
+
export declare const none: variant<"none", null>;
|
|
100
|
+
export type none = typeof none;
|
|
101
|
+
/**
|
|
102
|
+
* Wraps a value in the "some" case of an Option type.
|
|
103
|
+
*
|
|
104
|
+
* @typeParam T - The type of the value to wrap
|
|
105
|
+
* @param value - The value to wrap
|
|
106
|
+
* @returns A variant tagged as "some" containing the value
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```ts
|
|
110
|
+
* const maybeNumber = some(42);
|
|
111
|
+
* const result = match(maybeNumber, {
|
|
112
|
+
* some: (n) => n * 2,
|
|
113
|
+
* none: () => 0
|
|
114
|
+
* }); // returns 84
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
export declare function some<T>(value: T): variant<"some", T>;
|
|
118
|
+
export type some<T> = variant<"some", T>;
|
|
119
|
+
/**
|
|
120
|
+
* Represents an optional value that may be present (some) or absent (none).
|
|
121
|
+
*
|
|
122
|
+
* @typeParam T - The type of the value when present
|
|
123
|
+
*
|
|
124
|
+
* @remarks
|
|
125
|
+
* This is East's standard approach to representing nullable values safely.
|
|
126
|
+
* Use with the `match` function for exhaustive pattern matching.
|
|
127
|
+
*/
|
|
128
|
+
export type option<T> = none | some<T>;
|
|
129
|
+
/** Check if a value is a variant */
|
|
130
|
+
export declare function isVariant(v: any): v is variant;
|
|
131
|
+
//# sourceMappingURL=variant.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"variant.d.ts","sourceRoot":"","sources":["../../../src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C,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,GAAG;QAAE,IAAI,EAAE,CAAC,CAAA;KAAE,CAAC,CAAC,OAAO,CAAC,KAAK,GAAG;CAAE,EAC5E,OAAO,SAAS,GAAG,EACrB,OAAO,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,YAAY,EAAE,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,SAAS,CAAC,CAAC,GAAG,OAAO,CAAA;AAOpG;;;;;GAKG;AACH,eAAO,MAAM,IAAI,uBAAwB,CAAC;AAC1C,MAAM,MAAM,IAAI,GAAG,OAAO,IAAI,CAAC;AAE/B;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,sBAE/B;AACD,MAAM,MAAM,IAAI,CAAC,CAAC,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;AAEzC;;;;;;;;GAQG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;AAEvC,oCAAoC;AACpC,wBAAgB,SAAS,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,IAAI,OAAO,CAE9C"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
*/
|
|
7
|
+
export const variant_symbol = Symbol("variant");
|
|
8
|
+
/**
|
|
9
|
+
* Constructs a sum-type value with a specific type tag and associated value.
|
|
10
|
+
*
|
|
11
|
+
* @typeParam Type - The string literal type of the discriminant tag
|
|
12
|
+
* @typeParam Value - The type of the value to associate with this variant
|
|
13
|
+
* @param type - The discriminant tag for this variant
|
|
14
|
+
* @param value - The value to associate with this variant
|
|
15
|
+
* @returns A branded variant object
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const success = variant("success", { data: [1, 2, 3] });
|
|
20
|
+
* const error = variant("error", "Connection failed");
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export function variant(type, value = null) {
|
|
24
|
+
return {
|
|
25
|
+
type,
|
|
26
|
+
value,
|
|
27
|
+
[variant_symbol]: null,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
;
|
|
31
|
+
export function match(e, fs, d) {
|
|
32
|
+
const f = fs[e.type];
|
|
33
|
+
if (f === undefined)
|
|
34
|
+
return d;
|
|
35
|
+
return f(e.value);
|
|
36
|
+
}
|
|
37
|
+
;
|
|
38
|
+
/**
|
|
39
|
+
* Represents the absence of a value in an Option type.
|
|
40
|
+
*
|
|
41
|
+
* @remarks
|
|
42
|
+
* This is a singleton value representing the "none" case of the Option pattern.
|
|
43
|
+
*/
|
|
44
|
+
export const none = variant("none", null);
|
|
45
|
+
/**
|
|
46
|
+
* Wraps a value in the "some" case of an Option type.
|
|
47
|
+
*
|
|
48
|
+
* @typeParam T - The type of the value to wrap
|
|
49
|
+
* @param value - The value to wrap
|
|
50
|
+
* @returns A variant tagged as "some" containing the value
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* const maybeNumber = some(42);
|
|
55
|
+
* const result = match(maybeNumber, {
|
|
56
|
+
* some: (n) => n * 2,
|
|
57
|
+
* none: () => 0
|
|
58
|
+
* }); // returns 84
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export function some(value) {
|
|
62
|
+
return variant("some", value);
|
|
63
|
+
}
|
|
64
|
+
/** Check if a value is a variant */
|
|
65
|
+
export function isVariant(v) {
|
|
66
|
+
return typeof v === "object" && v !== null && v[variant_symbol] === null;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=variant.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"variant.js","sourceRoot":"","sources":["../../../src/containers/variant.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;AAsBhD;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,OAAO,CAAoC,IAAU,EAAE,QAAe,IAAa;IAC/F,OAAO;QACH,IAAI;QACJ,KAAK;QACL,CAAC,cAAc,CAAC,EAAE,IAAI;KACzB,CAAC;AACN,CAAC;AAAA,CAAC;AA6CF,MAAM,UAAU,KAAK,CAAC,CAAU,EAAE,EAA4C,EAAE,CAAO;IACnF,MAAM,CAAC,GAAI,EAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAC9B,IAAI,CAAC,KAAK,SAAS;QAAE,OAAO,CAAC,CAAC;IAC9B,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AACtB,CAAC;AAAA,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAG1C;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,IAAI,CAAI,KAAQ;IAC5B,OAAO,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAClC,CAAC;AAcD,oCAAoC;AACpC,MAAM,UAAU,SAAS,CAAC,CAAM;IAC5B,OAAO,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,cAAc,CAAC,KAAK,IAAI,CAAC;AAC7E,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Datetime parsing runtime implementation.
|
|
7
|
+
*
|
|
8
|
+
* This module provides the runtime parsing logic for converting strings
|
|
9
|
+
* to Date objects according to parsed format token arrays. This is called by the
|
|
10
|
+
* DateTimeParseFormat builtin.
|
|
11
|
+
*/
|
|
12
|
+
import type { DateTimeFormatToken } from "./types.js";
|
|
13
|
+
/**
|
|
14
|
+
* Result of parsing a datetime string.
|
|
15
|
+
*/
|
|
16
|
+
export type DateTimeParseResult = {
|
|
17
|
+
success: true;
|
|
18
|
+
value: Date;
|
|
19
|
+
} | {
|
|
20
|
+
success: false;
|
|
21
|
+
error: string;
|
|
22
|
+
position: number;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Parses a datetime string according to format tokens.
|
|
26
|
+
*
|
|
27
|
+
* @param input - The string to parse
|
|
28
|
+
* @param tokens - Array of format tokens specifying the expected format
|
|
29
|
+
* @returns Parse result containing either the Date or an error with position
|
|
30
|
+
*
|
|
31
|
+
* @remarks
|
|
32
|
+
* All dates are treated as UTC (naive datetimes with no timezone information).
|
|
33
|
+
* The parsed components are used to construct a Date using Date.UTC().
|
|
34
|
+
*
|
|
35
|
+
* Weekday tokens (dd, ddd, dddd) are currently ignored during parsing - they
|
|
36
|
+
* are consumed from the input but not validated against the actual weekday.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* const tokens = tokenizeDateTimeFormat("YYYY-MM-DD");
|
|
41
|
+
* const result = parseDateTimeFormatted("2025-01-15", tokens);
|
|
42
|
+
* if (result.success) {
|
|
43
|
+
* console.log(result.value); // Date object for 2025-01-15T00:00:00.000Z
|
|
44
|
+
* } else {
|
|
45
|
+
* console.log(`Parse error at position ${result.position}: ${result.error}`);
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare function parseDateTimeFormatted(input: string, tokens: DateTimeFormatToken[]): DateTimeParseResult;
|
|
50
|
+
//# sourceMappingURL=parse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../../src/datetime_format/parse.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtD;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAC3B;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,IAAI,CAAA;CAAE,GAC9B;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AA8BxD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,mBAAmB,EAAE,GAAG,mBAAmB,CAk3BxG"}
|