metano-runtime 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.
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/system/collections/hash-set.d.ts +29 -0
- package/dist/system/collections/hash-set.js +138 -0
- package/dist/system/collections/immutable-collection.d.ts +31 -0
- package/dist/system/collections/immutable-collection.js +58 -0
- package/dist/system/collections/index.d.ts +3 -0
- package/dist/system/collections/index.js +3 -0
- package/dist/system/collections/list-helpers.d.ts +43 -0
- package/dist/system/collections/list-helpers.js +58 -0
- package/dist/system/equality.d.ts +38 -0
- package/dist/system/equality.js +178 -0
- package/dist/system/hash-code.d.ts +35 -0
- package/dist/system/hash-code.js +177 -0
- package/dist/system/index.d.ts +6 -0
- package/dist/system/index.js +6 -0
- package/dist/system/json/converters.d.ts +22 -0
- package/dist/system/json/converters.js +261 -0
- package/dist/system/json/index.d.ts +5 -0
- package/dist/system/json/index.js +4 -0
- package/dist/system/json/json-serializer.d.ts +39 -0
- package/dist/system/json/json-serializer.js +57 -0
- package/dist/system/json/property-naming-policy.d.ts +14 -0
- package/dist/system/json/property-naming-policy.js +116 -0
- package/dist/system/json/serializer-context.d.ts +30 -0
- package/dist/system/json/serializer-context.js +38 -0
- package/dist/system/json/types.d.ts +85 -0
- package/dist/system/json/types.js +1 -0
- package/dist/system/linq/append-enumerable.d.ts +8 -0
- package/dist/system/linq/append-enumerable.js +15 -0
- package/dist/system/linq/compare-keys.d.ts +7 -0
- package/dist/system/linq/compare-keys.js +31 -0
- package/dist/system/linq/concat-enumerable.d.ts +8 -0
- package/dist/system/linq/concat-enumerable.js +15 -0
- package/dist/system/linq/distinct-by-enumerable.d.ts +8 -0
- package/dist/system/linq/distinct-by-enumerable.js +21 -0
- package/dist/system/linq/distinct-enumerable.d.ts +7 -0
- package/dist/system/linq/distinct-enumerable.js +19 -0
- package/dist/system/linq/enumerable-base.d.ts +98 -0
- package/dist/system/linq/enumerable-base.js +306 -0
- package/dist/system/linq/enumerable.d.ts +16 -0
- package/dist/system/linq/enumerable.js +33 -0
- package/dist/system/linq/except-enumerable.d.ts +8 -0
- package/dist/system/linq/except-enumerable.js +22 -0
- package/dist/system/linq/group-by-enumerable.d.ts +8 -0
- package/dist/system/linq/group-by-enumerable.js +31 -0
- package/dist/system/linq/index.d.ts +23 -0
- package/dist/system/linq/index.js +70 -0
- package/dist/system/linq/intersect-enumerable.d.ts +8 -0
- package/dist/system/linq/intersect-enumerable.js +22 -0
- package/dist/system/linq/order-by-enumerable.d.ts +9 -0
- package/dist/system/linq/order-by-enumerable.js +22 -0
- package/dist/system/linq/prepend-enumerable.d.ts +8 -0
- package/dist/system/linq/prepend-enumerable.js +15 -0
- package/dist/system/linq/reverse-enumerable.d.ts +7 -0
- package/dist/system/linq/reverse-enumerable.js +15 -0
- package/dist/system/linq/select-enumerable.d.ts +8 -0
- package/dist/system/linq/select-enumerable.js +17 -0
- package/dist/system/linq/select-many-enumerable.d.ts +8 -0
- package/dist/system/linq/select-many-enumerable.js +17 -0
- package/dist/system/linq/skip-enumerable.d.ts +8 -0
- package/dist/system/linq/skip-enumerable.js +21 -0
- package/dist/system/linq/skip-while-enumerable.d.ts +8 -0
- package/dist/system/linq/skip-while-enumerable.js +21 -0
- package/dist/system/linq/source-enumerable.d.ts +7 -0
- package/dist/system/linq/source-enumerable.js +12 -0
- package/dist/system/linq/take-enumerable.d.ts +8 -0
- package/dist/system/linq/take-enumerable.js +20 -0
- package/dist/system/linq/take-while-enumerable.d.ts +8 -0
- package/dist/system/linq/take-while-enumerable.js +19 -0
- package/dist/system/linq/then-by-enumerable.d.ts +9 -0
- package/dist/system/linq/then-by-enumerable.js +61 -0
- package/dist/system/linq/union-enumerable.d.ts +8 -0
- package/dist/system/linq/union-enumerable.js +27 -0
- package/dist/system/linq/where-enumerable.d.ts +8 -0
- package/dist/system/linq/where-enumerable.js +18 -0
- package/dist/system/linq/zip-enumerable.d.ts +9 -0
- package/dist/system/linq/zip-enumerable.js +24 -0
- package/dist/system/temporal-helpers.d.ts +10 -0
- package/dist/system/temporal-helpers.js +12 -0
- package/dist/type-checking/index.d.ts +1 -0
- package/dist/type-checking/index.js +1 -0
- package/dist/type-checking/primitive-type-checks.d.ts +33 -0
- package/dist/type-checking/primitive-type-checks.js +74 -0
- package/package.json +44 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { EnumerableBase } from "./enumerable-base.ts";
|
|
2
|
+
/** Projects each element to an iterable and flattens. Equivalent to C# .SelectMany() */
|
|
3
|
+
export declare class SelectManyEnumerable<T, R> extends EnumerableBase<R> {
|
|
4
|
+
readonly source: EnumerableBase<T>;
|
|
5
|
+
readonly selector: (item: T, index: number) => Iterable<R>;
|
|
6
|
+
constructor(source: EnumerableBase<T>, selector: (item: T, index: number) => Iterable<R>);
|
|
7
|
+
[Symbol.iterator](): Iterator<R>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { EnumerableBase } from "./enumerable-base.js";
|
|
2
|
+
/** Projects each element to an iterable and flattens. Equivalent to C# .SelectMany() */
|
|
3
|
+
export class SelectManyEnumerable extends EnumerableBase {
|
|
4
|
+
source;
|
|
5
|
+
selector;
|
|
6
|
+
constructor(source, selector) {
|
|
7
|
+
super();
|
|
8
|
+
this.source = source;
|
|
9
|
+
this.selector = selector;
|
|
10
|
+
}
|
|
11
|
+
*[Symbol.iterator]() {
|
|
12
|
+
let i = 0;
|
|
13
|
+
for (const item of this.source) {
|
|
14
|
+
yield* this.selector(item, i++);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { EnumerableBase } from "./enumerable-base.ts";
|
|
2
|
+
/** Skips a specified number of elements from the start. */
|
|
3
|
+
export declare class SkipEnumerable<T> extends EnumerableBase<T> {
|
|
4
|
+
readonly source: EnumerableBase<T>;
|
|
5
|
+
readonly skipCount: number;
|
|
6
|
+
constructor(source: EnumerableBase<T>, skipCount: number);
|
|
7
|
+
[Symbol.iterator](): Iterator<T>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { EnumerableBase } from "./enumerable-base.js";
|
|
2
|
+
/** Skips a specified number of elements from the start. */
|
|
3
|
+
export class SkipEnumerable extends EnumerableBase {
|
|
4
|
+
source;
|
|
5
|
+
skipCount;
|
|
6
|
+
constructor(source, skipCount) {
|
|
7
|
+
super();
|
|
8
|
+
this.source = source;
|
|
9
|
+
this.skipCount = skipCount;
|
|
10
|
+
}
|
|
11
|
+
*[Symbol.iterator]() {
|
|
12
|
+
let skipped = 0;
|
|
13
|
+
for (const item of this.source) {
|
|
14
|
+
if (skipped < this.skipCount) {
|
|
15
|
+
skipped++;
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
yield item;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { EnumerableBase } from "./enumerable-base.ts";
|
|
2
|
+
/** Skips elements while a predicate is true, then yields the rest. Equivalent to C# .SkipWhile() */
|
|
3
|
+
export declare class SkipWhileEnumerable<T> extends EnumerableBase<T> {
|
|
4
|
+
readonly source: EnumerableBase<T>;
|
|
5
|
+
readonly predicate: (item: T, index: number) => boolean;
|
|
6
|
+
constructor(source: EnumerableBase<T>, predicate: (item: T, index: number) => boolean);
|
|
7
|
+
[Symbol.iterator](): Iterator<T>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { EnumerableBase } from "./enumerable-base.js";
|
|
2
|
+
/** Skips elements while a predicate is true, then yields the rest. Equivalent to C# .SkipWhile() */
|
|
3
|
+
export class SkipWhileEnumerable extends EnumerableBase {
|
|
4
|
+
source;
|
|
5
|
+
predicate;
|
|
6
|
+
constructor(source, predicate) {
|
|
7
|
+
super();
|
|
8
|
+
this.source = source;
|
|
9
|
+
this.predicate = predicate;
|
|
10
|
+
}
|
|
11
|
+
*[Symbol.iterator]() {
|
|
12
|
+
let skipping = true;
|
|
13
|
+
let i = 0;
|
|
14
|
+
for (const item of this.source) {
|
|
15
|
+
if (skipping && this.predicate(item, i++))
|
|
16
|
+
continue;
|
|
17
|
+
skipping = false;
|
|
18
|
+
yield item;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { EnumerableBase } from "./enumerable-base.ts";
|
|
2
|
+
/** Wraps an existing Iterable as the source of a LINQ chain. */
|
|
3
|
+
export declare class SourceEnumerable<T> extends EnumerableBase<T> {
|
|
4
|
+
readonly source: Iterable<T>;
|
|
5
|
+
constructor(source: Iterable<T>);
|
|
6
|
+
[Symbol.iterator](): Iterator<T>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { EnumerableBase } from "./enumerable-base.js";
|
|
2
|
+
/** Wraps an existing Iterable as the source of a LINQ chain. */
|
|
3
|
+
export class SourceEnumerable extends EnumerableBase {
|
|
4
|
+
source;
|
|
5
|
+
constructor(source) {
|
|
6
|
+
super();
|
|
7
|
+
this.source = source;
|
|
8
|
+
}
|
|
9
|
+
*[Symbol.iterator]() {
|
|
10
|
+
yield* this.source;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { EnumerableBase } from "./enumerable-base.ts";
|
|
2
|
+
/** Returns a specified number of elements from the start. */
|
|
3
|
+
export declare class TakeEnumerable<T> extends EnumerableBase<T> {
|
|
4
|
+
readonly source: EnumerableBase<T>;
|
|
5
|
+
readonly takeCount: number;
|
|
6
|
+
constructor(source: EnumerableBase<T>, takeCount: number);
|
|
7
|
+
[Symbol.iterator](): Iterator<T>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { EnumerableBase } from "./enumerable-base.js";
|
|
2
|
+
/** Returns a specified number of elements from the start. */
|
|
3
|
+
export class TakeEnumerable extends EnumerableBase {
|
|
4
|
+
source;
|
|
5
|
+
takeCount;
|
|
6
|
+
constructor(source, takeCount) {
|
|
7
|
+
super();
|
|
8
|
+
this.source = source;
|
|
9
|
+
this.takeCount = takeCount;
|
|
10
|
+
}
|
|
11
|
+
*[Symbol.iterator]() {
|
|
12
|
+
let taken = 0;
|
|
13
|
+
for (const item of this.source) {
|
|
14
|
+
if (taken >= this.takeCount)
|
|
15
|
+
break;
|
|
16
|
+
yield item;
|
|
17
|
+
taken++;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { EnumerableBase } from "./enumerable-base.ts";
|
|
2
|
+
/** Yields elements while a predicate is true. Equivalent to C# .TakeWhile() */
|
|
3
|
+
export declare class TakeWhileEnumerable<T> extends EnumerableBase<T> {
|
|
4
|
+
readonly source: EnumerableBase<T>;
|
|
5
|
+
readonly predicate: (item: T, index: number) => boolean;
|
|
6
|
+
constructor(source: EnumerableBase<T>, predicate: (item: T, index: number) => boolean);
|
|
7
|
+
[Symbol.iterator](): Iterator<T>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { EnumerableBase } from "./enumerable-base.js";
|
|
2
|
+
/** Yields elements while a predicate is true. Equivalent to C# .TakeWhile() */
|
|
3
|
+
export class TakeWhileEnumerable extends EnumerableBase {
|
|
4
|
+
source;
|
|
5
|
+
predicate;
|
|
6
|
+
constructor(source, predicate) {
|
|
7
|
+
super();
|
|
8
|
+
this.source = source;
|
|
9
|
+
this.predicate = predicate;
|
|
10
|
+
}
|
|
11
|
+
*[Symbol.iterator]() {
|
|
12
|
+
let i = 0;
|
|
13
|
+
for (const item of this.source) {
|
|
14
|
+
if (!this.predicate(item, i++))
|
|
15
|
+
break;
|
|
16
|
+
yield item;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { EnumerableBase } from "./enumerable-base.ts";
|
|
2
|
+
/** Secondary sort: sorts elements by a key, preserving the order of the previous sort for equal keys. */
|
|
3
|
+
export declare class ThenByEnumerable<T, K> extends EnumerableBase<T> {
|
|
4
|
+
readonly source: EnumerableBase<T>;
|
|
5
|
+
readonly keySelector: (item: T) => K;
|
|
6
|
+
readonly descending: boolean;
|
|
7
|
+
constructor(source: EnumerableBase<T>, keySelector: (item: T) => K, descending: boolean);
|
|
8
|
+
[Symbol.iterator](): Iterator<T>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { EnumerableBase } from "./enumerable-base.js";
|
|
2
|
+
import { compareKeys } from "./compare-keys.js";
|
|
3
|
+
/** Secondary sort: sorts elements by a key, preserving the order of the previous sort for equal keys. */
|
|
4
|
+
export class ThenByEnumerable extends EnumerableBase {
|
|
5
|
+
source;
|
|
6
|
+
keySelector;
|
|
7
|
+
descending;
|
|
8
|
+
constructor(source, keySelector, descending) {
|
|
9
|
+
super();
|
|
10
|
+
this.source = source;
|
|
11
|
+
this.keySelector = keySelector;
|
|
12
|
+
this.descending = descending;
|
|
13
|
+
}
|
|
14
|
+
*[Symbol.iterator]() {
|
|
15
|
+
// Materialize and collect all comparators from the chain
|
|
16
|
+
const comparators = collectComparators(this);
|
|
17
|
+
const items = materializeSource(this);
|
|
18
|
+
items.sort((a, b) => {
|
|
19
|
+
for (const cmp of comparators) {
|
|
20
|
+
const result = cmp(a, b);
|
|
21
|
+
if (result !== 0)
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
return 0;
|
|
25
|
+
});
|
|
26
|
+
yield* items;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/** Walks the chain of OrderBy/ThenBy to collect all comparators in order. */
|
|
30
|
+
function collectComparators(node) {
|
|
31
|
+
const comparators = [];
|
|
32
|
+
let current = node;
|
|
33
|
+
while (current instanceof ThenByEnumerable) {
|
|
34
|
+
const thenBy = current;
|
|
35
|
+
comparators.unshift(makeComparator(thenBy.keySelector, thenBy.descending));
|
|
36
|
+
current = thenBy.source;
|
|
37
|
+
}
|
|
38
|
+
// The root should be an OrderByEnumerable-like (has keySelector + descending)
|
|
39
|
+
if ("keySelector" in current && "descending" in current) {
|
|
40
|
+
const orderBy = current;
|
|
41
|
+
comparators.unshift(makeComparator(orderBy.keySelector, orderBy.descending));
|
|
42
|
+
}
|
|
43
|
+
return comparators;
|
|
44
|
+
}
|
|
45
|
+
/** Walks to the root source (past all OrderBy/ThenBy) and materializes it. */
|
|
46
|
+
function materializeSource(node) {
|
|
47
|
+
let current = node;
|
|
48
|
+
while (current instanceof ThenByEnumerable) {
|
|
49
|
+
current = current.source;
|
|
50
|
+
}
|
|
51
|
+
if ("source" in current) {
|
|
52
|
+
return [...current.source];
|
|
53
|
+
}
|
|
54
|
+
return [...current];
|
|
55
|
+
}
|
|
56
|
+
function makeComparator(keySelector, descending) {
|
|
57
|
+
return (a, b) => {
|
|
58
|
+
const cmp = compareKeys(keySelector(a), keySelector(b));
|
|
59
|
+
return descending ? -cmp : cmp;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { EnumerableBase } from "./enumerable-base.ts";
|
|
2
|
+
/** Produces the set union of two sequences. Equivalent to C# .Union() */
|
|
3
|
+
export declare class UnionEnumerable<T> extends EnumerableBase<T> {
|
|
4
|
+
readonly source: EnumerableBase<T>;
|
|
5
|
+
readonly second: Iterable<T>;
|
|
6
|
+
constructor(source: EnumerableBase<T>, second: Iterable<T>);
|
|
7
|
+
[Symbol.iterator](): Iterator<T>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { EnumerableBase } from "./enumerable-base.js";
|
|
2
|
+
import { HashSet } from "../collections/hash-set.js";
|
|
3
|
+
/** Produces the set union of two sequences. Equivalent to C# .Union() */
|
|
4
|
+
export class UnionEnumerable extends EnumerableBase {
|
|
5
|
+
source;
|
|
6
|
+
second;
|
|
7
|
+
constructor(source, second) {
|
|
8
|
+
super();
|
|
9
|
+
this.source = source;
|
|
10
|
+
this.second = second;
|
|
11
|
+
}
|
|
12
|
+
*[Symbol.iterator]() {
|
|
13
|
+
const seen = new HashSet();
|
|
14
|
+
for (const item of this.source) {
|
|
15
|
+
if (!seen.has(item)) {
|
|
16
|
+
seen.add(item);
|
|
17
|
+
yield item;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
for (const item of this.second) {
|
|
21
|
+
if (!seen.has(item)) {
|
|
22
|
+
seen.add(item);
|
|
23
|
+
yield item;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { EnumerableBase } from "./enumerable-base.ts";
|
|
2
|
+
/** Filters elements based on a predicate. Equivalent to C# .Where() */
|
|
3
|
+
export declare class WhereEnumerable<T> extends EnumerableBase<T> {
|
|
4
|
+
readonly source: EnumerableBase<T>;
|
|
5
|
+
readonly predicate: (item: T, index: number) => boolean;
|
|
6
|
+
constructor(source: EnumerableBase<T>, predicate: (item: T, index: number) => boolean);
|
|
7
|
+
[Symbol.iterator](): Iterator<T>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { EnumerableBase } from "./enumerable-base.js";
|
|
2
|
+
/** Filters elements based on a predicate. Equivalent to C# .Where() */
|
|
3
|
+
export class WhereEnumerable extends EnumerableBase {
|
|
4
|
+
source;
|
|
5
|
+
predicate;
|
|
6
|
+
constructor(source, predicate) {
|
|
7
|
+
super();
|
|
8
|
+
this.source = source;
|
|
9
|
+
this.predicate = predicate;
|
|
10
|
+
}
|
|
11
|
+
*[Symbol.iterator]() {
|
|
12
|
+
let i = 0;
|
|
13
|
+
for (const item of this.source) {
|
|
14
|
+
if (this.predicate(item, i++))
|
|
15
|
+
yield item;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { EnumerableBase } from "./enumerable-base.ts";
|
|
2
|
+
/** Combines two sequences element-by-element using a result selector. Equivalent to C# .Zip() */
|
|
3
|
+
export declare class ZipEnumerable<T, U, R> extends EnumerableBase<R> {
|
|
4
|
+
readonly source: EnumerableBase<T>;
|
|
5
|
+
readonly second: Iterable<U>;
|
|
6
|
+
readonly resultSelector: (first: T, second: U) => R;
|
|
7
|
+
constructor(source: EnumerableBase<T>, second: Iterable<U>, resultSelector: (first: T, second: U) => R);
|
|
8
|
+
[Symbol.iterator](): Iterator<R>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { EnumerableBase } from "./enumerable-base.js";
|
|
2
|
+
/** Combines two sequences element-by-element using a result selector. Equivalent to C# .Zip() */
|
|
3
|
+
export class ZipEnumerable extends EnumerableBase {
|
|
4
|
+
source;
|
|
5
|
+
second;
|
|
6
|
+
resultSelector;
|
|
7
|
+
constructor(source, second, resultSelector) {
|
|
8
|
+
super();
|
|
9
|
+
this.source = source;
|
|
10
|
+
this.second = second;
|
|
11
|
+
this.resultSelector = resultSelector;
|
|
12
|
+
}
|
|
13
|
+
*[Symbol.iterator]() {
|
|
14
|
+
const iter1 = this.source[Symbol.iterator]();
|
|
15
|
+
const iter2 = this.second[Symbol.iterator]();
|
|
16
|
+
while (true) {
|
|
17
|
+
const a = iter1.next();
|
|
18
|
+
const b = iter2.next();
|
|
19
|
+
if (a.done || b.done)
|
|
20
|
+
break;
|
|
21
|
+
yield this.resultSelector(a.value, b.value);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
2
|
+
/**
|
|
3
|
+
* Computes the day number (days since 0001-01-01) for a date.
|
|
4
|
+
* Equivalent to C# DateOnly.DayNumber.
|
|
5
|
+
*
|
|
6
|
+
* Accepts any object with a toString() returning an ISO date string (e.g., Temporal.PlainDate).
|
|
7
|
+
*/
|
|
8
|
+
export declare function dayNumber(date: Temporal.PlainDate | {
|
|
9
|
+
toString(): string;
|
|
10
|
+
}): number;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
2
|
+
const referenceDate = Temporal.PlainDate.from("0001-01-01");
|
|
3
|
+
/**
|
|
4
|
+
* Computes the day number (days since 0001-01-01) for a date.
|
|
5
|
+
* Equivalent to C# DateOnly.DayNumber.
|
|
6
|
+
*
|
|
7
|
+
* Accepts any object with a toString() returning an ISO date string (e.g., Temporal.PlainDate).
|
|
8
|
+
*/
|
|
9
|
+
export function dayNumber(date) {
|
|
10
|
+
const current = Temporal.PlainDate.from(date instanceof Temporal.PlainDate ? date : date.toString());
|
|
11
|
+
return referenceDate.until(current, { largestUnit: "days" }).days;
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./primitive-type-checks";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./primitive-type-checks";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Specialized runtime type checks for C# numeric and string types.
|
|
3
|
+
* Used by Metano-generated overload dispatchers to differentiate
|
|
4
|
+
* types that map to the same JS primitive (e.g., int vs long → both number).
|
|
5
|
+
*/
|
|
6
|
+
/** C# `char` → single-character string */
|
|
7
|
+
export declare function isChar(value: unknown): value is string;
|
|
8
|
+
/** C# `string` */
|
|
9
|
+
export declare function isString(value: unknown): value is string;
|
|
10
|
+
/** C# `byte` (0..255) */
|
|
11
|
+
export declare function isByte(value: unknown): value is number;
|
|
12
|
+
/** C# `sbyte` (-128..127) */
|
|
13
|
+
export declare function isSByte(value: unknown): value is number;
|
|
14
|
+
/** C# `short` / `Int16` (-32768..32767) */
|
|
15
|
+
export declare function isInt16(value: unknown): value is number;
|
|
16
|
+
/** C# `ushort` / `UInt16` (0..65535) */
|
|
17
|
+
export declare function isUInt16(value: unknown): value is number;
|
|
18
|
+
/** C# `int` / `Int32` (-2147483648..2147483647) */
|
|
19
|
+
export declare function isInt32(value: unknown): value is number;
|
|
20
|
+
/** C# `uint` / `UInt32` (0..4294967295) */
|
|
21
|
+
export declare function isUInt32(value: unknown): value is number;
|
|
22
|
+
/** C# `long` / `Int64` (safe integer range) */
|
|
23
|
+
export declare function isInt64(value: unknown): value is number;
|
|
24
|
+
/** C# `ulong` / `UInt64` (0..safe integer range) */
|
|
25
|
+
export declare function isUInt64(value: unknown): value is number;
|
|
26
|
+
/** C# `float` / `Single` */
|
|
27
|
+
export declare function isFloat32(value: unknown): value is number;
|
|
28
|
+
/** C# `double` / `Double` */
|
|
29
|
+
export declare function isFloat64(value: unknown): value is number;
|
|
30
|
+
/** C# `bool` */
|
|
31
|
+
export declare function isBool(value: unknown): value is boolean;
|
|
32
|
+
/** C# `BigInteger` */
|
|
33
|
+
export declare function isBigInt(value: unknown): value is bigint;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Specialized runtime type checks for C# numeric and string types.
|
|
3
|
+
* Used by Metano-generated overload dispatchers to differentiate
|
|
4
|
+
* types that map to the same JS primitive (e.g., int vs long → both number).
|
|
5
|
+
*/
|
|
6
|
+
// ─── String types ───────────────────────────────────────
|
|
7
|
+
/** C# `char` → single-character string */
|
|
8
|
+
export function isChar(value) {
|
|
9
|
+
return typeof value === "string" && value.length === 1;
|
|
10
|
+
}
|
|
11
|
+
/** C# `string` */
|
|
12
|
+
export function isString(value) {
|
|
13
|
+
return typeof value === "string";
|
|
14
|
+
}
|
|
15
|
+
// ─── Integer types ──────────────────────────────────────
|
|
16
|
+
/** C# `byte` (0..255) */
|
|
17
|
+
export function isByte(value) {
|
|
18
|
+
return typeof value === "number" && Number.isInteger(value) && value >= 0 && value <= 255;
|
|
19
|
+
}
|
|
20
|
+
/** C# `sbyte` (-128..127) */
|
|
21
|
+
export function isSByte(value) {
|
|
22
|
+
return typeof value === "number" && Number.isInteger(value) && value >= -128 && value <= 127;
|
|
23
|
+
}
|
|
24
|
+
/** C# `short` / `Int16` (-32768..32767) */
|
|
25
|
+
export function isInt16(value) {
|
|
26
|
+
return typeof value === "number" && Number.isInteger(value) && value >= -32768 && value <= 32767;
|
|
27
|
+
}
|
|
28
|
+
/** C# `ushort` / `UInt16` (0..65535) */
|
|
29
|
+
export function isUInt16(value) {
|
|
30
|
+
return typeof value === "number" && Number.isInteger(value) && value >= 0 && value <= 65535;
|
|
31
|
+
}
|
|
32
|
+
/** C# `int` / `Int32` (-2147483648..2147483647) */
|
|
33
|
+
export function isInt32(value) {
|
|
34
|
+
return (typeof value === "number" &&
|
|
35
|
+
Number.isInteger(value) &&
|
|
36
|
+
value >= -2147483648 &&
|
|
37
|
+
value <= 2147483647);
|
|
38
|
+
}
|
|
39
|
+
/** C# `uint` / `UInt32` (0..4294967295) */
|
|
40
|
+
export function isUInt32(value) {
|
|
41
|
+
return typeof value === "number" && Number.isInteger(value) && value >= 0 && value <= 4294967295;
|
|
42
|
+
}
|
|
43
|
+
/** C# `long` / `Int64` (safe integer range) */
|
|
44
|
+
export function isInt64(value) {
|
|
45
|
+
return (typeof value === "number" &&
|
|
46
|
+
Number.isInteger(value) &&
|
|
47
|
+
value >= Number.MIN_SAFE_INTEGER &&
|
|
48
|
+
value <= Number.MAX_SAFE_INTEGER);
|
|
49
|
+
}
|
|
50
|
+
/** C# `ulong` / `UInt64` (0..safe integer range) */
|
|
51
|
+
export function isUInt64(value) {
|
|
52
|
+
return (typeof value === "number" &&
|
|
53
|
+
Number.isInteger(value) &&
|
|
54
|
+
value >= 0 &&
|
|
55
|
+
value <= Number.MAX_SAFE_INTEGER);
|
|
56
|
+
}
|
|
57
|
+
// ─── Floating-point types ───────────────────────────────
|
|
58
|
+
/** C# `float` / `Single` */
|
|
59
|
+
export function isFloat32(value) {
|
|
60
|
+
return typeof value === "number";
|
|
61
|
+
}
|
|
62
|
+
/** C# `double` / `Double` */
|
|
63
|
+
export function isFloat64(value) {
|
|
64
|
+
return typeof value === "number";
|
|
65
|
+
}
|
|
66
|
+
// ─── Other primitive types ──────────────────────────────
|
|
67
|
+
/** C# `bool` */
|
|
68
|
+
export function isBool(value) {
|
|
69
|
+
return typeof value === "boolean";
|
|
70
|
+
}
|
|
71
|
+
/** C# `BigInteger` */
|
|
72
|
+
export function isBigInt(value) {
|
|
73
|
+
return typeof value === "bigint";
|
|
74
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "metano-runtime",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"module": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"description": "Runtime support library for Metano-generated TypeScript code",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/danfma/metano.git",
|
|
12
|
+
"directory": "js/metano-runtime"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist/**/*",
|
|
16
|
+
"README.md"
|
|
17
|
+
],
|
|
18
|
+
"exports": {
|
|
19
|
+
".": "./dist/index.js",
|
|
20
|
+
"./system/json": "./dist/system/json/index.js",
|
|
21
|
+
"./*": "./dist/*"
|
|
22
|
+
},
|
|
23
|
+
"imports": {
|
|
24
|
+
"#/*": [
|
|
25
|
+
"./dist/*",
|
|
26
|
+
"./src/*"
|
|
27
|
+
]
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tsgo -b .",
|
|
31
|
+
"test": "bun test"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/bun": "^1.3.11",
|
|
35
|
+
"@typescript/native-preview": "^7.0.0-dev.20260225.1",
|
|
36
|
+
"bun-types": "^1.3.11"
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"@typescript/native-preview": "^7"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@js-temporal/polyfill": "^0.5.1"
|
|
43
|
+
}
|
|
44
|
+
}
|