@jalvin/runtime 2.0.1 → 2.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/dist/bibi.d.ts +9 -0
- package/dist/bibi.d.ts.map +1 -1
- package/dist/bibi.js +42 -25
- package/dist/bibi.js.map +1 -1
- package/dist/index.d.ts +14 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +174 -177
- package/dist/index.js.map +1 -1
- package/dist/stdlib/collections.d.ts +73 -0
- package/dist/stdlib/collections.d.ts.map +1 -0
- package/dist/stdlib/collections.js +414 -0
- package/dist/stdlib/collections.js.map +1 -0
- package/dist/stdlib/conversions.d.ts +48 -0
- package/dist/stdlib/conversions.d.ts.map +1 -0
- package/dist/stdlib/conversions.js +153 -0
- package/dist/stdlib/conversions.js.map +1 -0
- package/dist/stdlib/delegates.d.ts +41 -0
- package/dist/stdlib/delegates.d.ts.map +1 -0
- package/dist/stdlib/delegates.js +116 -0
- package/dist/stdlib/delegates.js.map +1 -0
- package/dist/stdlib/equality.d.ts +9 -0
- package/dist/stdlib/equality.d.ts.map +1 -0
- package/dist/stdlib/equality.js +29 -0
- package/dist/stdlib/equality.js.map +1 -0
- package/dist/stdlib/index.d.ts +13 -0
- package/dist/stdlib/index.d.ts.map +1 -0
- package/dist/stdlib/index.js +74 -0
- package/dist/stdlib/index.js.map +1 -0
- package/dist/stdlib/io.d.ts +3 -0
- package/dist/stdlib/io.d.ts.map +1 -0
- package/dist/stdlib/io.js +14 -0
- package/dist/stdlib/io.js.map +1 -0
- package/dist/stdlib/math.d.ts +38 -0
- package/dist/stdlib/math.d.ts.map +1 -0
- package/dist/stdlib/math.js +68 -0
- package/dist/stdlib/math.js.map +1 -0
- package/dist/stdlib/random.d.ts +23 -0
- package/dist/stdlib/random.d.ts.map +1 -0
- package/dist/stdlib/random.js +41 -0
- package/dist/stdlib/random.js.map +1 -0
- package/dist/stdlib/regex.d.ts +30 -0
- package/dist/stdlib/regex.d.ts.map +1 -0
- package/dist/stdlib/regex.js +80 -0
- package/dist/stdlib/regex.js.map +1 -0
- package/dist/stdlib/result.d.ts +29 -0
- package/dist/stdlib/result.d.ts.map +1 -0
- package/dist/stdlib/result.js +96 -0
- package/dist/stdlib/result.js.map +1 -0
- package/dist/stdlib/strings.d.ts +35 -0
- package/dist/stdlib/strings.d.ts.map +1 -0
- package/dist/stdlib/strings.js +161 -0
- package/dist/stdlib/strings.js.map +1 -0
- package/dist/stdlib/timing.d.ts +12 -0
- package/dist/stdlib/timing.d.ts.map +1 -0
- package/dist/stdlib/timing.js +27 -0
- package/dist/stdlib/timing.js.map +1 -0
- package/dist/stdlib/types.d.ts +34 -0
- package/dist/stdlib/types.d.ts.map +1 -0
- package/dist/stdlib/types.js +82 -0
- package/dist/stdlib/types.js.map +1 -0
- package/package.json +7 -3
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
3
|
+
// stdlib/regex.ts — Regex — thin, ergonomic wrapper over JS RegExp
|
|
4
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.JalvinRegex = exports.Regex = exports.RegexResult = void 0;
|
|
7
|
+
class RegexResult {
|
|
8
|
+
value;
|
|
9
|
+
range;
|
|
10
|
+
groupValues;
|
|
11
|
+
constructor(value, range, groupValues) {
|
|
12
|
+
this.value = value;
|
|
13
|
+
this.range = range;
|
|
14
|
+
this.groupValues = groupValues;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.RegexResult = RegexResult;
|
|
18
|
+
class Regex {
|
|
19
|
+
_re;
|
|
20
|
+
constructor(pattern, options = "") {
|
|
21
|
+
// Map Jalvin option names to JS flags
|
|
22
|
+
const flags = options
|
|
23
|
+
.replace("IGNORE_CASE", "i")
|
|
24
|
+
.replace("MULTILINE", "m")
|
|
25
|
+
.replace("DOT_MATCHES_ALL", "s")
|
|
26
|
+
.replace(/[^gimsuy]/g, "");
|
|
27
|
+
this._re = new RegExp(pattern, flags || undefined);
|
|
28
|
+
}
|
|
29
|
+
/** Returns true if the **entire** input matches this regex (anchored). */
|
|
30
|
+
matches(input) {
|
|
31
|
+
const anchored = new RegExp(`^(?:${this._re.source})$`, this._re.flags.replace("g", ""));
|
|
32
|
+
return anchored.test(input);
|
|
33
|
+
}
|
|
34
|
+
/** Returns true if any part of the input matches. */
|
|
35
|
+
containsMatchIn(input) {
|
|
36
|
+
const unanchored = new RegExp(this._re.source, this._re.flags.replace("g", ""));
|
|
37
|
+
return unanchored.test(input);
|
|
38
|
+
}
|
|
39
|
+
find(input, startIndex = 0) {
|
|
40
|
+
const re = new RegExp(this._re.source, "g" + this._re.flags.replace("g", ""));
|
|
41
|
+
re.lastIndex = startIndex;
|
|
42
|
+
const m = re.exec(input);
|
|
43
|
+
if (!m)
|
|
44
|
+
return null;
|
|
45
|
+
return new RegexResult(m[0], { start: m.index, endInclusive: m.index + m[0].length - 1 }, m.slice(1).map((g) => g ?? ""));
|
|
46
|
+
}
|
|
47
|
+
findAll(input, startIndex = 0) {
|
|
48
|
+
const re = new RegExp(this._re.source, "g" + this._re.flags.replace("g", ""));
|
|
49
|
+
re.lastIndex = startIndex;
|
|
50
|
+
const results = [];
|
|
51
|
+
let m;
|
|
52
|
+
while ((m = re.exec(input)) !== null) {
|
|
53
|
+
results.push(new RegexResult(m[0], { start: m.index, endInclusive: m.index + m[0].length - 1 }, m.slice(1).map((g) => g ?? "")));
|
|
54
|
+
}
|
|
55
|
+
return results;
|
|
56
|
+
}
|
|
57
|
+
replace(input, replacement) {
|
|
58
|
+
const re = new RegExp(this._re.source, "g" + this._re.flags.replace("g", ""));
|
|
59
|
+
if (typeof replacement === "string")
|
|
60
|
+
return input.replace(re, replacement);
|
|
61
|
+
return input.replace(re, (match, ...groups) => {
|
|
62
|
+
const index = groups[groups.length - 2];
|
|
63
|
+
const r = new RegexResult(match, { start: index, endInclusive: index + match.length - 1 }, groups.slice(0, -2).map(String));
|
|
64
|
+
return replacement(r);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
replaceFirst(input, replacement) {
|
|
68
|
+
const re = new RegExp(this._re.source, this._re.flags.replace("g", ""));
|
|
69
|
+
return input.replace(re, replacement);
|
|
70
|
+
}
|
|
71
|
+
split(input, limit) {
|
|
72
|
+
const parts = input.split(this._re);
|
|
73
|
+
return limit !== undefined ? parts.slice(0, limit) : parts;
|
|
74
|
+
}
|
|
75
|
+
toPattern() { return this._re.source; }
|
|
76
|
+
toString() { return this._re.toString(); }
|
|
77
|
+
}
|
|
78
|
+
exports.Regex = Regex;
|
|
79
|
+
exports.JalvinRegex = Regex;
|
|
80
|
+
//# sourceMappingURL=regex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"regex.js","sourceRoot":"","sources":["../../src/stdlib/regex.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,mEAAmE;AACnE,gFAAgF;;;AAEhF,MAAa,WAAW;IAEX;IACA;IACA;IAHX,YACW,KAAmB,EACnB,KAAoD,EACpD,WAAkC;QAFlC,UAAK,GAAL,KAAK,CAAc;QACnB,UAAK,GAAL,KAAK,CAA+C;QACpD,gBAAW,GAAX,WAAW,CAAuB;IACzC,CAAC;CACN;AAND,kCAMC;AAED,MAAa,KAAK;IACC,GAAG,CAAS;IAE7B,YAAY,OAAe,EAAE,OAAO,GAAG,EAAE;QACvC,sCAAsC;QACtC,MAAM,KAAK,GAAG,OAAO;aAClB,OAAO,CAAC,aAAa,EAAO,GAAG,CAAC;aAChC,OAAO,CAAC,WAAW,EAAS,GAAG,CAAC;aAChC,OAAO,CAAC,iBAAiB,EAAG,GAAG,CAAC;aAChC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;QAC7B,IAAI,CAAC,GAAG,GAAG,IAAI,MAAM,CAAC,OAAO,EAAE,KAAK,IAAI,SAAS,CAAC,CAAC;I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|
3
|
+
private readonly _error;
|
|
4
|
+
private readonly _ok;
|
|
5
|
+
private constructor();
|
|
6
|
+
static success<T>(value: T): Result<T>;
|
|
7
|
+
static failure<T>(error: unknown): Result<T>;
|
|
8
|
+
get isSuccess(): boolean;
|
|
9
|
+
get isFailure(): boolean;
|
|
10
|
+
getOrNull(): T | null;
|
|
11
|
+
getOrUndefined(): T | undefined;
|
|
12
|
+
getOrThrow(): T;
|
|
13
|
+
getOrDefault(default_: T): T;
|
|
14
|
+
getOrElse(fn: (e: unknown) => T): T;
|
|
15
|
+
exceptionOrNull(): unknown | null;
|
|
16
|
+
map<U>(fn: (value: T) => U): Result<U>;
|
|
17
|
+
/** Alias for `map` — always wraps the transform in a try/catch. */
|
|
18
|
+
mapCatching<U>(fn: (value: T) => U): Result<U>;
|
|
19
|
+
recover(fn: (e: unknown) => T): Result<T>;
|
|
20
|
+
onSuccess(fn: (value: T) => void): this;
|
|
21
|
+
onFailure(fn: (error: unknown) => void): this;
|
|
22
|
+
fold<R>(onSuccess: (value: T) => R, onFailure: (error: unknown) => R): R;
|
|
23
|
+
toString(): string;
|
|
24
|
+
}
|
|
25
|
+
/** Wraps a throwing synchronous call in a Result. */
|
|
26
|
+
export declare function runCatching<T>(fn: () => T): Result<T>;
|
|
27
|
+
/** Wraps a throwing async call in a Result. */
|
|
28
|
+
export declare function runCatchingAsync<T>(fn: () => Promise<T>): Promise<Result<T>>;
|
|
29
|
+
//# sourceMappingURL=result.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../../src/stdlib/result.ts"],"names":[],"mappings":"AAIA,qBAAa,MAAM,CAAC,CAAC;IAEjB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,GAAG;IAHtB,OAAO;IAMP,MAAM,CAAC,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,CA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AAC,CAAC,CAGrD;AAED,+CAA+C;AAC/C,wBAAsB,gBAAgB,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAGlF"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
3
|
+
// stdlib/result.ts — Result<T> — wraps a success value or a failure exception
|
|
4
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Result = void 0;
|
|
7
|
+
exports.runCatching = runCatching;
|
|
8
|
+
exports.runCatchingAsync = runCatchingAsync;
|
|
9
|
+
class Result {
|
|
10
|
+
_value;
|
|
11
|
+
_error;
|
|
12
|
+
_ok;
|
|
13
|
+
constructor(_value, _error, _ok) {
|
|
14
|
+
this._value = _value;
|
|
15
|
+
this._error = _error;
|
|
16
|
+
this._ok = _ok;
|
|
17
|
+
}
|
|
18
|
+
static success(value) { return new Result(value, undefined, true); }
|
|
19
|
+
static failure(error) { return new Result(undefined, error, false); }
|
|
20
|
+
get isSuccess() { return this._ok; }
|
|
21
|
+
get isFailure() { return !this._ok; }
|
|
22
|
+
getOrNull() { return this._ok ? this._value : null; }
|
|
23
|
+
getOrUndefined() { return this._ok ? this._value : undefined; }
|
|
24
|
+
getOrThrow() {
|
|
25
|
+
if (this._ok)
|
|
26
|
+
return this._value;
|
|
27
|
+
throw this._error;
|
|
28
|
+
}
|
|
29
|
+
getOrDefault(default_) {
|
|
30
|
+
return this._ok ? this._value : default_;
|
|
31
|
+
}
|
|
32
|
+
getOrElse(fn) {
|
|
33
|
+
return this._ok ? this._value : fn(this._error);
|
|
34
|
+
}
|
|
35
|
+
exceptionOrNull() { return this._ok ? null : this._error; }
|
|
36
|
+
map(fn) {
|
|
37
|
+
if (!this._ok)
|
|
38
|
+
return Result.failure(this._error);
|
|
39
|
+
try {
|
|
40
|
+
return Result.success(fn(this._value));
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
return Result.failure(e);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/** Alias for `map` — always wraps the transform in a try/catch. */
|
|
47
|
+
mapCatching(fn) { return this.map(fn); }
|
|
48
|
+
recover(fn) {
|
|
49
|
+
if (this._ok)
|
|
50
|
+
return this;
|
|
51
|
+
try {
|
|
52
|
+
return Result.success(fn(this._error));
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
return Result.failure(e);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
onSuccess(fn) {
|
|
59
|
+
if (this._ok)
|
|
60
|
+
fn(this._value);
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
onFailure(fn) {
|
|
64
|
+
if (!this._ok)
|
|
65
|
+
fn(this._error);
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
fold(onSuccess, onFailure) {
|
|
69
|
+
return this._ok ? onSuccess(this._value) : onFailure(this._error);
|
|
70
|
+
}
|
|
71
|
+
toString() {
|
|
72
|
+
return this._ok
|
|
73
|
+
? `Result.success(${this._value})`
|
|
74
|
+
: `Result.failure(${this._error})`;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.Result = Result;
|
|
78
|
+
/** Wraps a throwing synchronous call in a Result. */
|
|
79
|
+
function runCatching(fn) {
|
|
80
|
+
try {
|
|
81
|
+
return Result.success(fn());
|
|
82
|
+
}
|
|
83
|
+
catch (e) {
|
|
84
|
+
return Result.failure(e);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/** Wraps a throwing async call in a Result. */
|
|
88
|
+
async function runCatchingAsync(fn) {
|
|
89
|
+
try {
|
|
90
|
+
return Result.success(await fn());
|
|
91
|
+
}
|
|
92
|
+
catch (e) {
|
|
93
|
+
return Result.failure(e);
|
|
94
|
+
}
|
|
95
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AAC;IAED,SAAS,CAAC,EAA4B;QACpC,IAAI,CAAC,IAAI,CAAC,GAAG;YAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC/B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,CAAI,SAA0B,EAAE,SAAgC;QAClE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,MAAW,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACzE,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,GAAG;YACb,CAAC,CAAC,kBAAkB,IAAI,CAAC,MAAM,GAAG;YAClC,CAAC,CAAC,kBAAkB,IAAI,CAAC,MAAM,GAAG,CAAC;IACvC,CAAC;CACF;AAjED,wBAiEC;AAED,qDAAqD;AACrD,SAAgB,WAAW,CAAI,EAAW;IACxC,IAAS,CAAC;QAAC,OAAO,MAAM,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC;IAAC,CAAC;IACzC,OAAO,CAAC,EAAE,CAAC;QAAC,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAAC,CAAC;AACzC,CAAC;AAED,+CAA+C;AACxC,KAAK,UAAU,gBAAgB,CAAI,EAAoB;IAC5D,IAAS,CAAC;QAAC,OAAO,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAAC,CAAC;IAC/C,OAAO,CAAC,EAAE,CAAC;QAAC,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAAC,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export declare function isBlank(s: string): boolean;
|
|
2
|
+
export declare function isNotBlank(s: string): boolean;
|
|
3
|
+
export declare function isNullOrBlank(s: string | null | undefined): boolean;
|
|
4
|
+
export declare function toIntOrNull(s: string): number | null;
|
|
5
|
+
export declare function toDoubleOrNull(s: string): number | null;
|
|
6
|
+
export declare function toBooleanOrNull(s: string): boolean | null;
|
|
7
|
+
export declare function padStart(s: string, length: number, padChar?: string): string;
|
|
8
|
+
export declare function padEnd(s: string, length: number, padChar?: string): string;
|
|
9
|
+
export declare function repeat_(s: string, n: number): string;
|
|
10
|
+
export declare function capitalize(s: string): string;
|
|
11
|
+
export declare function decapitalize(s: string): string;
|
|
12
|
+
export declare function substringBefore(s: string, delimiter: string): string;
|
|
13
|
+
export declare function substringAfter(s: string, delimiter: string): string;
|
|
14
|
+
export declare function substringBeforeLast(s: string, delimiter: string): string;
|
|
15
|
+
export declare function substringAfterLast(s: string, delimiter: string): string;
|
|
16
|
+
export declare function removePrefix(s: string, prefix: string): string;
|
|
17
|
+
export declare function removeSuffix(s: string, suffix: string): string;
|
|
18
|
+
export declare function lines(s: string): string[];
|
|
19
|
+
export declare function lineSequence(s: string): string[];
|
|
20
|
+
export declare function ifEmpty<T extends string | null | undefined>(value: T, default_: () => T): T;
|
|
21
|
+
export declare function ifBlank<T extends string | null | undefined>(value: T, default_: () => T): T;
|
|
22
|
+
export declare function trimIndent(s: string): string;
|
|
23
|
+
export declare class StringBuilder {
|
|
24
|
+
private readonly _parts;
|
|
25
|
+
append(s: unknown): this;
|
|
26
|
+
appendLine(s?: unknown): this;
|
|
27
|
+
prepend(s: unknown): this;
|
|
28
|
+
clear(): this;
|
|
29
|
+
get length(): number;
|
|
30
|
+
isEmpty(): boolean;
|
|
31
|
+
isNotEmpty(): boolean;
|
|
32
|
+
toString(): string;
|
|
33
|
+
}
|
|
34
|
+
export declare function buildString(fn: (sb: StringBuilder) => void): string;
|
|
35
|
+
//# sourceMappingURL=strings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strings.d.ts","sourceRoot":"","sources":["../../src/stdlib/strings.ts"],"names":[],"mappings":"AAQA,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAE1C;AAED,wBAAgB,U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AgB,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAE9D;AAMD,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAEzC;AAED,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAEhD;AAMD,wBAAgB,OAAO,CAAC,CAAC,SAAS,MAAM,GAAG,IAAI,GAAG,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,CAAC,CAE3F;AAED,wBAAgB,OAAO,CAAC,CAAC,SAAS,MAAM,GAAG,IAAI,GAAG,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,CAAC,CAE3F;AAMD,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAa5C;AAMD,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;IAEvC,MAAM,CAAC,CAAC,EAAE,OAAO,GAAO,IAAI;IAC5B,UAAU,CAAC,CAAC,GAAE,OAAY,GAAG,IAAI;IACjC,OAAO,CAAC,CAAC,EAAE,OAAO,GAAM,IAAI;IAC5B,KAAK,IAAmB,IAAI;IAE5B,IAAI,MAAM,IAAI,MAAM,CAAgE;IACpF,OAAO,IAAM,OAAO;IACpB,UAAU,IAAI,OAAO;IACrB,QAAQ,IAAK,MAAM;CACpB;AAED,wBAAgB,WAAW,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,aAAa,KAAK,IAAI,GAAG,MAAM,CAInE"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
3
|
+
// stdlib/strings.ts — String utilities and StringBuilder
|
|
4
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.StringBuilder = void 0;
|
|
7
|
+
exports.isBlank = isBlank;
|
|
8
|
+
exports.isNotBlank = isNotBlank;
|
|
9
|
+
exports.isNullOrBlank = isNullOrBlank;
|
|
10
|
+
exports.toIntOrNull = toIntOrNull;
|
|
11
|
+
exports.toDoubleOrNull = toDoubleOrNull;
|
|
12
|
+
exports.toBooleanOrNull = toBooleanOrNull;
|
|
13
|
+
exports.padStart = padStart;
|
|
14
|
+
exports.padEnd = padEnd;
|
|
15
|
+
exports.repeat_ = repeat_;
|
|
16
|
+
exports.capitalize = capitalize;
|
|
17
|
+
exports.decapitalize = decapitalize;
|
|
18
|
+
exports.substringBefore = substringBefore;
|
|
19
|
+
exports.substringAfter = substringAfter;
|
|
20
|
+
exports.substringBeforeLast = substringBeforeLast;
|
|
21
|
+
exports.substringAfterLast = substringAfterLast;
|
|
22
|
+
exports.removePrefix = removePrefix;
|
|
23
|
+
exports.removeSuffix = removeSuffix;
|
|
24
|
+
exports.lines = lines;
|
|
25
|
+
exports.lineSequence = lineSequence;
|
|
26
|
+
exports.ifEmpty = ifEmpty;
|
|
27
|
+
exports.ifBlank = ifBlank;
|
|
28
|
+
exports.trimIndent = trimIndent;
|
|
29
|
+
exports.buildString = buildString;
|
|
30
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
31
|
+
// String predicates
|
|
32
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
33
|
+
function isBlank(s) {
|
|
34
|
+
return s.trim().length === 0;
|
|
35
|
+
}
|
|
36
|
+
function isNotBlank(s) {
|
|
37
|
+
return s.trim().length > 0;
|
|
38
|
+
}
|
|
39
|
+
function isNullOrBlank(s) {
|
|
40
|
+
return s == null || s.trim().length === 0;
|
|
41
|
+
}
|
|
42
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
43
|
+
// Parsing with fallback
|
|
44
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
45
|
+
function toIntOrNull(s) {
|
|
46
|
+
const n = parseInt(s, 10);
|
|
47
|
+
return isNaN(n) ? null : n;
|
|
48
|
+
}
|
|
49
|
+
function toDoubleOrNull(s) {
|
|
50
|
+
const n = parseFloat(s);
|
|
51
|
+
return isNaN(n) ? null : n;
|
|
52
|
+
}
|
|
53
|
+
function toBooleanOrNull(s) {
|
|
54
|
+
if (s.toLowerCase() === "true")
|
|
55
|
+
return true;
|
|
56
|
+
if (s.toLowerCase() === "false")
|
|
57
|
+
return false;
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
61
|
+
// Padding and repetition
|
|
62
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
63
|
+
function padStart(s, length, padChar = " ") {
|
|
64
|
+
return s.padStart(length, padChar);
|
|
65
|
+
}
|
|
66
|
+
function padEnd(s, length, padChar = " ") {
|
|
67
|
+
return s.padEnd(length, padChar);
|
|
68
|
+
}
|
|
69
|
+
function repeat_(s, n) {
|
|
70
|
+
return s.repeat(n);
|
|
71
|
+
}
|
|
72
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
73
|
+
// Case and casing helpers
|
|
74
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
75
|
+
function capitalize(s) {
|
|
76
|
+
return s.length === 0 ? s : s[0].toUpperCase() + s.slice(1);
|
|
77
|
+
}
|
|
78
|
+
function decapitalize(s) {
|
|
79
|
+
return s.length === 0 ? s : s[0].toLowerCase() + s.slice(1);
|
|
80
|
+
}
|
|
81
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
82
|
+
// Substring extraction
|
|
83
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
84
|
+
function substringBefore(s, delimiter) {
|
|
85
|
+
const idx = s.indexOf(delimiter);
|
|
86
|
+
return idx === -1 ? s : s.slice(0, idx);
|
|
87
|
+
}
|
|
88
|
+
function substringAfter(s, delimiter) {
|
|
89
|
+
const idx = s.indexOf(delimiter);
|
|
90
|
+
return idx === -1 ? "" : s.slice(idx + delimiter.length);
|
|
91
|
+
}
|
|
92
|
+
function substringBeforeLast(s, delimiter) {
|
|
93
|
+
const idx = s.lastIndexOf(delimiter);
|
|
94
|
+
return idx === -1 ? s : s.slice(0, idx);
|
|
95
|
+
}
|
|
96
|
+
function substringAfterLast(s, delimiter) {
|
|
97
|
+
const idx = s.lastIndexOf(delimiter);
|
|
98
|
+
return idx === -1 ? "" : s.slice(idx + delimiter.length);
|
|
99
|
+
}
|
|
100
|
+
function removePrefix(s, prefix) {
|
|
101
|
+
return s.startsWith(prefix) ? s.slice(prefix.length) : s;
|
|
102
|
+
}
|
|
103
|
+
function removeSuffix(s, suffix) {
|
|
104
|
+
return s.endsWith(suffix) ? s.slice(0, s.length - suffix.length) : s;
|
|
105
|
+
}
|
|
106
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
107
|
+
// Line splitting
|
|
108
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
109
|
+
function lines(s) {
|
|
110
|
+
return s.split(/\r?\n/);
|
|
111
|
+
}
|
|
112
|
+
function lineSequence(s) {
|
|
113
|
+
return lines(s);
|
|
114
|
+
}
|
|
115
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
116
|
+
// Default-if-empty helpers
|
|
117
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
118
|
+
function ifEmpty(value, default_) {
|
|
119
|
+
return (value == null || value.length === 0) ? default_() : value;
|
|
120
|
+
}
|
|
121
|
+
function ifBlank(value, default_) {
|
|
122
|
+
return (value == null || value.trim().length === 0) ? default_() : value;
|
|
123
|
+
}
|
|
124
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
125
|
+
// Indent trimming — strips the common leading whitespace from all lines
|
|
126
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
127
|
+
function trimIndent(s) {
|
|
128
|
+
const allLines = s.split("\n");
|
|
129
|
+
const nonEmpty = allLines.filter((l) => l.trim().length > 0);
|
|
130
|
+
const minIndent = nonEmpty.reduce((min, l) => {
|
|
131
|
+
const match = l.match(/^(\s*)/);
|
|
132
|
+
return Math.min(min, match?.[1]?.length ?? 0);
|
|
133
|
+
}, Infinity);
|
|
134
|
+
const indentToStrip = isFinite(minIndent) ? minIndent : 0;
|
|
135
|
+
return allLines
|
|
136
|
+
.map((l) => l.slice(indentToStrip))
|
|
137
|
+
.join("\n")
|
|
138
|
+
.replace(/^\n/, "")
|
|
139
|
+
.replace(/\n$/, "");
|
|
140
|
+
}
|
|
141
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
142
|
+
// StringBuilder — mutable string builder for efficient concatenation
|
|
143
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
144
|
+
class StringBuilder {
|
|
145
|
+
_parts = [];
|
|
146
|
+
append(s) { this._parts.push(String(s ?? "")); return this; }
|
|
147
|
+
appendLine(s = "") { this._parts.push(String(s), "\n"); return this; }
|
|
148
|
+
prepend(s) { this._parts.unshift(String(s ?? "")); return this; }
|
|
149
|
+
clear() { this._parts.length = 0; return this; }
|
|
150
|
+
get length() { return this._parts.reduce((sum, p) => sum + p.length, 0); }
|
|
151
|
+
isEmpty() { return this.length === 0; }
|
|
152
|
+
isNotEmpty() { return this.length > 0; }
|
|
153
|
+
toString() { return this._parts.join(""); }
|
|
154
|
+
}
|
|
155
|
+
exports.StringBuilder = StringBuilder;
|
|
156
|
+
function buildString(fn) {
|
|
157
|
+
const sb = new StringBuilder();
|
|
158
|
+
fn(sb);
|
|
159
|
+
return sb.toString();
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=strings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strings.js","sourceRoot":"","sources":["../../src/stdlib/strings.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yDAAyD;AACzD,gFAAgF;;;AAMhF,0BAEC;AAED,gCAEC;AAED,sCAEC;AAMD,kCAGC;AAED,wCAGC;AAED,0CAIC;AAMD,4BAEC;AAED,wBAEC;AAED,0BAEC;AAMD,gCAEC;AAED,o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AAK,CAAC,CAAC,CAAC,CAAC;IACpD,UAAU,KAAe,OAAO,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;IAClD,QAAQ,KAAiB,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;CACxD;AAZD,sCAYC;AAED,SAAgB,WAAW,CAAC,EAA+B;IACzD,MAAM,EAAE,GAAG,IAAI,aAAa,EAAE,CAAC;IAC/B,EAAE,CAAC,EAAE,CAAC,CAAC;IACP,OAAO,EAAE,CAAC,QAAQ,EAAE,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface TimedValue<T> {
|
|
2
|
+
value: T;
|
|
3
|
+
/** Elapsed time in milliseconds */
|
|
4
|
+
duration: number;
|
|
5
|
+
}
|
|
6
|
+
/** Measures how long a synchronous block takes in milliseconds. */
|
|
7
|
+
export declare function measureTimeMillis(fn: () => void): number;
|
|
8
|
+
/** Measures how long an async block takes in milliseconds. */
|
|
9
|
+
export declare function measureTimeMillisAsync(fn: () => Promise<void>): Promise<number>;
|
|
10
|
+
/** Runs a block and returns both its result and the elapsed time. */
|
|
11
|
+
export declare function measureTimedValue<T>(fn: () => T): TimedValue<T>;
|
|
12
|
+
//# sourceMappingURL=timing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timing.d.ts","sourceRoot":"","sources":["../../src/stdlib/timing.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,UAAU,CAAC,CAAC;IAC3B,KAAK,EAAK,CAAC,CAAC;IACZ,mCAAmC;IACnC,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,mEAAmE;AACnE,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,MAAM,CAIxD;AAED,8DAA8D;AAC9D,wBAAsB,sBAAsB,CAAC,EAAE,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAIrF;AAED,qEAAqE;AACrE,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAI/D"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
3
|
+
// stdlib/timing.ts — Performance measurement utilities
|
|
4
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.measureTimeMillis = measureTimeMillis;
|
|
7
|
+
exports.measureTimeMillisAsync = measureTimeMillisAsync;
|
|
8
|
+
exports.measureTimedValue = measureTimedValue;
|
|
9
|
+
/** Measures how long a synchronous block takes in milliseconds. */
|
|
10
|
+
function measureTimeMillis(fn) {
|
|
11
|
+
const start = performance.now();
|
|
12
|
+
fn();
|
|
13
|
+
return Math.round(performance.now() - start);
|
|
14
|
+
}
|
|
15
|
+
/** Measures how long an async block takes in milliseconds. */
|
|
16
|
+
async function measureTimeMillisAsync(fn) {
|
|
17
|
+
const start = performance.now();
|
|
18
|
+
await fn();
|
|
19
|
+
return Math.round(performance.now() - start);
|
|
20
|
+
}
|
|
21
|
+
/** Runs a block and returns both its result and the elapsed time. */
|
|
22
|
+
function measureTimedValue(fn) {
|
|
23
|
+
const start = performance.now();
|
|
24
|
+
const value = fn();
|
|
25
|
+
return { value, duration: Math.round(performance.now() - start) };
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=timing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timing.js","sourceRoot":"","sources":["../../src/stdlib/timing.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,uDAAuD;AACvD,gFAAgF;;AAShF,8CAIC;AAGD,wDAIC;AAGD,8CAIC;AAnBD,mEAAmE;AACnE,SAAgB,iBAAiB,CAAC,EAAc;IAC9C,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;IAChC,EAAE,EAAE,CAAC;IACL,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,CAAC;AAC/C,CAAC;AAED,8DAA8D;AACvD,KAAK,UAAU,sBAAsB,CAAC,EAAuB;IAClE,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;IAChC,MAAM,EAAE,EAAE,CAAC;IACX,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,CAAC;AAC/C,CAAC;AAED,qEAAqE;AACrE,SAAgB,iBAAiB,CAAI,EAAW;IAC9C,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;IAChC,MAAM,KAAK,GAAG,EAAE,EAAE,CAAC;IACnB,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,EAAE,CAAC;AACpE,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `notNull(value)` — emitted for Jalvin's `!!` operator.
|
|
3
|
+
* Throws if value is null/undefined, otherwise returns the value.
|
|
4
|
+
*/
|
|
5
|
+
export declare function notNull<T>(value: T | null | undefined): T;
|
|
6
|
+
export declare class NullPointerException extends Error {
|
|
7
|
+
constructor(message?: string);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* `safeCast<T>(value, Type)` — emitted for Jalvin's `as?` operator.
|
|
11
|
+
* Returns the value if it's an instanceof Type, otherwise returns null.
|
|
12
|
+
*/
|
|
13
|
+
export declare function safeCast<T>(value: unknown, Type: new (...args: any[]) => T): T | null;
|
|
14
|
+
export declare function checkNotNull<T>(value: T | null | undefined, message?: string): T;
|
|
15
|
+
export declare function requireNotNull<T>(value: T | null | undefined, message?: string): T;
|
|
16
|
+
export declare function requireCondition(condition: boolean, message?: string | (() => string)): void;
|
|
17
|
+
export declare function check(condition: boolean, message?: string | (() => string)): void;
|
|
18
|
+
export declare function error(message: string): never;
|
|
19
|
+
export declare class IllegalArgumentException extends Error {
|
|
20
|
+
constructor(message: string);
|
|
21
|
+
}
|
|
22
|
+
export declare class IllegalStateException extends Error {
|
|
23
|
+
constructor(message: string);
|
|
24
|
+
}
|
|
25
|
+
export declare class UnsupportedOperationException extends Error {
|
|
26
|
+
constructor(message?: string);
|
|
27
|
+
}
|
|
28
|
+
export declare class IndexOutOfBoundsException extends Error {
|
|
29
|
+
constructor(message?: string);
|
|
30
|
+
}
|
|
31
|
+
export declare class NoSuchElementException extends Error {
|
|
32
|
+
constructor(message?: string);
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/stdlib/types.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,GAAG,CAAC,CAKzD;AAED,qBAAa,oBAAqB,SAAQ,KAAK;gBACjC,OAAO,SAAmB;CAIvC;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EACxB,KAAK,EAAE,OAAO,EAEd,IAAI,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,GAC9B,CAAC,GAAG,IAAI,CAEV;AAED,wBAAgB,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,EAAE,OAAO,SAA2B,GAAG,CAAC,CAElG;AAED,wBAAgB,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,EAAE,OAAO,SAA4B,GAAG,CAAC,CAErG;AAED,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,GAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAwB,GAAG,IAAI,CAIlH;AAED,wBAAgB,KAAK,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,GAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAkB,GAAG,IAAI,CAIjG;AAED,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,CAE5C;AAMD,qBAAa,wBAAyB,SAAQ,KAAK;gBACrC,OAAO,EAAE,MAAM;CAC5B;AAED,qBAAa,qBAAsB,SAAQ,KAAK;gBAClC,OAAO,EAAE,MAAM;CAC5B;AAED,qBAAa,6BAA8B,SAAQ,KAAK;gBAC1C,OAAO,SAA+B;CACnD;AAED,qBAAa,yBAA0B,SAAQ,KAAK;gBACtC,OAAO,SAAwB;CAC5C;AAED,qBAAa,sBAAuB,SAAQ,KAAK;gBACnC,OAAO,SAAoB;CACxC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
3
|
+
// stdlib/types.ts — Null safety, preconditions, and exception classes
|
|
4
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.NoSuchElementException = exports.IndexOutOfBoundsException = exports.UnsupportedOperationException = exports.IllegalStateException = exports.IllegalArgumentException = exports.NullPointerException = void 0;
|
|
7
|
+
exports.notNull = notNull;
|
|
8
|
+
exports.safeCast = safeCast;
|
|
9
|
+
exports.checkNotNull = checkNotNull;
|
|
10
|
+
exports.requireNotNull = requireNotNull;
|
|
11
|
+
exports.requireCondition = requireCondition;
|
|
12
|
+
exports.check = check;
|
|
13
|
+
exports.error = error;
|
|
14
|
+
/**
|
|
15
|
+
* `notNull(value)` — emitted for Jalvin's `!!` operator.
|
|
16
|
+
* Throws if value is null/undefined, otherwise returns the value.
|
|
17
|
+
*/
|
|
18
|
+
function notNull(value) {
|
|
19
|
+
if (value === null || value === undefined) {
|
|
20
|
+
throw new NullPointerException("!! operator invoked on null or undefined value");
|
|
21
|
+
}
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
class NullPointerException extends Error {
|
|
25
|
+
constructor(message = "Value was null") {
|
|
26
|
+
super(message);
|
|
27
|
+
this.name = "NullPointerException";
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.NullPointerException = NullPointerException;
|
|
31
|
+
/**
|
|
32
|
+
* `safeCast<T>(value, Type)` — emitted for Jalvin's `as?` operator.
|
|
33
|
+
* Returns the value if it's an instanceof Type, otherwise returns null.
|
|
34
|
+
*/
|
|
35
|
+
function safeCast(value,
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
|
+
Type) {
|
|
38
|
+
return value instanceof Type ? value : null;
|
|
39
|
+
}
|
|
40
|
+
function checkNotNull(value, message = "Value must not be null") {
|
|
41
|
+
return notNull(value) ?? (() => { throw new NullPointerException(message); })();
|
|
42
|
+
}
|
|
43
|
+
function requireNotNull(value, message = "Required value was null") {
|
|
44
|
+
return notNull(value);
|
|
45
|
+
}
|
|
46
|
+
function requireCondition(condition, message = "Requirement failed") {
|
|
47
|
+
if (!condition) {
|
|
48
|
+
throw new IllegalArgumentException(typeof message === "function" ? message() : message);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function check(condition, message = "Check failed") {
|
|
52
|
+
if (!condition) {
|
|
53
|
+
throw new IllegalStateException(typeof message === "function" ? message() : message);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function error(message) {
|
|
57
|
+
throw new IllegalStateException(message);
|
|
58
|
+
}
|
|
59
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
60
|
+
// Standard exception hierarchy
|
|
61
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
62
|
+
class IllegalArgumentException extends Error {
|
|
63
|
+
constructor(message) { super(message); this.name = "IllegalArgumentException"; }
|
|
64
|
+
}
|
|
65
|
+
exports.IllegalArgumentException = IllegalArgumentException;
|
|
66
|
+
class IllegalStateException extends Error {
|
|
67
|
+
constructor(message) { super(message); this.name = "IllegalStateException"; }
|
|
68
|
+
}
|
|
69
|
+
exports.IllegalStateException = IllegalStateException;
|
|
70
|
+
class UnsupportedOperationException extends Error {
|
|
71
|
+
constructor(message = "Operation is not supported") { super(message); this.name = "UnsupportedOperationException"; }
|
|
72
|
+
}
|
|
73
|
+
exports.UnsupportedOperationException = UnsupportedOperationException;
|
|
74
|
+
class IndexOutOfBoundsException extends Error {
|
|
75
|
+
constructor(message = "Index out of bounds") { super(message); this.name = "IndexOutOfBoundsException"; }
|
|
76
|
+
}
|
|
77
|
+
exports.IndexOutOfBoundsException = IndexOutOfBoundsException;
|
|
78
|
+
class NoSuchElementException extends Error {
|
|
79
|
+
constructor(message = "No such element") { super(message); this.name = "NoSuchElementException"; }
|
|
80
|
+
}
|
|
81
|
+
exports.NoSuchElementException = NoSuchElementException;
|
|
82
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/stdlib/types.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,sEAAsE;AACtE,gFAAgF;;;AAMhF,0BAKC;AAaD,4BAMC;AAED,oCAEC;AAED,wCAEC;AAED,4CAIC;AAED,sBAIC;AAED,sBAEC;AApDD;;;GAGG;AACH,SAAgB,OAAO,CAAI,KAA2B;IACpD,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QAC1C,MAAM,IAAI,oBAAoB,CAAC,gDAAgD,CAAC,CAAC;IACnF,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAa,oBAAqB,SAAQ,KAAK;IAC7C,YAAY,OAAO,GAAG,gBAAgB;QACpC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,sBAAsB,CA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