trilean 1.7.12 → 1.8.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/README.md +33 -13
- package/dist/builtin-functions.cjs +129 -0
- package/dist/builtin-functions.d.cts +13 -0
- package/dist/builtin-functions.d.ts +13 -0
- package/dist/builtin-functions.js +128 -0
- package/dist/complex-division.cjs +48 -0
- package/dist/complex-division.d.cts +25 -0
- package/dist/complex-division.d.ts +25 -0
- package/dist/complex-division.js +47 -0
- package/dist/duration-order.cjs +84 -0
- package/dist/duration-order.d.cts +22 -0
- package/dist/duration-order.d.ts +22 -0
- package/dist/duration-order.js +82 -0
- package/dist/evaluate-document.cjs +87 -0
- package/dist/evaluate-document.d.cts +40 -0
- package/dist/evaluate-document.d.ts +40 -0
- package/dist/evaluate-document.js +86 -0
- package/dist/evaluator-collection.d.cts +1 -1
- package/dist/evaluator-collection.d.ts +1 -1
- package/dist/evaluator-factory.d.cts +1 -1
- package/dist/evaluator-factory.d.ts +1 -1
- package/dist/evaluator-indeterminacy-helpers.d.cts +1 -1
- package/dist/evaluator-indeterminacy-helpers.d.ts +1 -1
- package/dist/evaluator-operations.cjs +75 -24
- package/dist/evaluator-operations.d.cts +3 -3
- package/dist/evaluator-operations.d.ts +3 -3
- package/dist/evaluator-operations.js +74 -23
- package/dist/evaluator.d.cts +1 -1
- package/dist/evaluator.d.ts +1 -1
- package/dist/functions.d.cts +8 -4
- package/dist/functions.d.ts +8 -4
- package/dist/index.cjs +8 -1
- package/dist/index.d.cts +5 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.js +5 -2
- package/dist/input-resolvers.cjs +63 -0
- package/dist/input-resolvers.d.cts +19 -0
- package/dist/input-resolvers.d.ts +19 -0
- package/dist/input-resolvers.js +61 -0
- package/dist/integer-power.cjs +20 -0
- package/dist/integer-power.d.cts +13 -0
- package/dist/integer-power.d.ts +13 -0
- package/dist/integer-power.js +19 -0
- package/dist/plain-record.cjs +8 -0
- package/dist/plain-record.d.cts +4 -0
- package/dist/plain-record.d.ts +4 -0
- package/dist/plain-record.js +7 -0
- package/dist-cli/trilean.mjs +1745 -0
- package/package.json +5 -1
- package/schemas/trilean.schema.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { complexFromPolar, complexLiteralFromPolar, complexMagnitude, complexPhase } from "./complex.js";
|
|
2
1
|
import { ComputedValueSchema, DurationUnitSchema, UnitSchema, combineUnitsForDivide, combineUnitsForMultiply, unitsEqual } from "./computed-value.js";
|
|
2
|
+
import { builtinFunctions } from "./builtin-functions.js";
|
|
3
|
+
import { complexFromPolar, complexLiteralFromPolar, complexMagnitude, complexPhase } from "./complex.js";
|
|
3
4
|
import { average, count, presenceOf, sum } from "./derived-aggregates.js";
|
|
4
5
|
import { and, iff, implies, nand, none, nor, not, or, xor } from "./derived-connectives.js";
|
|
5
6
|
import { hierarchicalGlobPattern, prefixPattern, wildcardPattern } from "./derived-patterns.js";
|
|
@@ -9,4 +10,6 @@ import { JsonValueSchema } from "./json-value.js";
|
|
|
9
10
|
import { AccumulatorNodeSchema, AllOfNodeSchema, AndNodeSchema, AnyOfNodeSchema, ArithmeticNodeSchema, ArithmeticOperatorSchema, BooleanLiteralNodeSchema, CallNodeSchema, CompareNodeSchema, ComparisonOperatorSchema, ComplexLiteralNodeSchema, ComplexPolarLiteralNodeSchema, ComplexRectangularLiteralNodeSchema, ConditionalCaseSchema, ConditionalNodeSchema, DelegateNodeSchema, DurationLiteralNodeSchema, EveryNodeSchema, ExistsNodeSchema, ExpressionNodeSchema, FoldCombinerSchema, FoldNodeSchema, HitPolicySchema, InstantLiteralNodeSchema, LookupNodeSchema, MemberOfNodeSchema, MembershipOperatorSchema, NegateNodeSchema, NotNodeSchema, NumberLiteralNodeSchema, OrNodeSchema, PredicateNodeSchema, ReferenceNodeSchema, SomeNodeSchema, TextCompareNodeSchema, TextComparisonOperatorSchema, TextLiteralNodeSchema, TreeReferenceNodeSchema } from "./tree.js";
|
|
10
11
|
import { emptyFunctionRegistry } from "./functions.js";
|
|
11
12
|
import { createEvaluator, createSyncEvaluator, evaluatePredicate, evaluateValue } from "./evaluator-factory.js";
|
|
12
|
-
|
|
13
|
+
import { createInputResolvers, parseInputs } from "./input-resolvers.js";
|
|
14
|
+
import { evaluateDocument } from "./evaluate-document.js";
|
|
15
|
+
export { AccumulatorNodeSchema, AllOfNodeSchema, AndNodeSchema, AnyOfNodeSchema, ArithmeticNodeSchema, ArithmeticOperatorSchema, BooleanLiteralNodeSchema, CallNodeSchema, CompareNodeSchema, ComparisonOperatorSchema, ComplexLiteralNodeSchema, ComplexPolarLiteralNodeSchema, ComplexRectangularLiteralNodeSchema, ComputedValueSchema, ConditionalCaseSchema, ConditionalNodeSchema, DelegateNodeSchema, DurationLiteralNodeSchema, DurationUnitSchema, EveryNodeSchema, ExistsNodeSchema, ExpressionNodeSchema, FoldCombinerSchema, FoldNodeSchema, HitPolicySchema, IndeterminateReasonSchema, InstantLiteralNodeSchema, JsonValueSchema, LookupNodeSchema, MemberOfNodeSchema, MembershipOperatorSchema, NegateNodeSchema, NotNodeSchema, NumberLiteralNodeSchema, OrNodeSchema, PredicateNodeSchema, ReferenceNodeSchema, SomeNodeSchema, TextCompareNodeSchema, TextComparisonOperatorSchema, TextLiteralNodeSchema, TreeReferenceNodeSchema, UnitSchema, and, average, builtinFunctions, coalesce, combineUnitsForDivide, combineUnitsForMultiply, complexFromPolar, complexLiteralFromPolar, complexMagnitude, complexPhase, count, createEvaluator, createInputResolvers, createSyncEvaluator, definite, emptyFunctionRegistry, evaluateDocument, evaluatePredicate, evaluateValue, firstIndeterminate, hierarchicalGlobPattern, iff, implies, indeterminate, nand, none, nor, not, or, parseInputs, prefixPattern, presenceOf, sum, unitsEqual, wildcardPattern, xor };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_computed_value = require("./computed-value.cjs");
|
|
3
|
+
const require_plain_record = require("./plain-record.cjs");
|
|
4
|
+
//#region src/input-resolvers.ts
|
|
5
|
+
/** A plain JSON number, string or boolean is the unit-less value of that kind; anything else must already be a complete `ComputedValue` (the only way to supply units, durations, instants or complex values). Both routes end in `ComputedValueSchema`, so a number that is not finite (`1e999` parses to `Infinity`) is refused whichever way it was written, and a field the schema does not define is dropped rather than carried along. */
|
|
6
|
+
function toComputedValue(raw) {
|
|
7
|
+
const candidate = typeof raw === "number" ? {
|
|
8
|
+
kind: "number",
|
|
9
|
+
value: raw
|
|
10
|
+
} : typeof raw === "string" ? {
|
|
11
|
+
kind: "text",
|
|
12
|
+
value: raw
|
|
13
|
+
} : typeof raw === "boolean" ? {
|
|
14
|
+
kind: "boolean",
|
|
15
|
+
value: raw
|
|
16
|
+
} : raw;
|
|
17
|
+
const parsed = require_computed_value.ComputedValueSchema.safeParse(candidate);
|
|
18
|
+
return parsed.success ? parsed.data : void 0;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Validates a plain object of named inputs, one `ComputedValue` per name (see `toComputedValue` for the accepted shapes). Every entry is checked up front, so a malformed input is reported as one by name rather than surfacing later as a `not-found` reference.
|
|
22
|
+
*/
|
|
23
|
+
function parseInputs(raw) {
|
|
24
|
+
if (!require_plain_record.isPlainRecord(raw)) return {
|
|
25
|
+
ok: false,
|
|
26
|
+
issues: ["inputs must be a JSON object of named values"]
|
|
27
|
+
};
|
|
28
|
+
const inputs = /* @__PURE__ */ new Map();
|
|
29
|
+
const issues = [];
|
|
30
|
+
for (const [name, value] of Object.entries(raw)) {
|
|
31
|
+
const computed = toComputedValue(value);
|
|
32
|
+
if (computed === void 0) issues.push(`inputs.${name}: expected a finite number, text, boolean or a complete computed value`);
|
|
33
|
+
else inputs.set(name, computed);
|
|
34
|
+
}
|
|
35
|
+
return issues.length === 0 ? {
|
|
36
|
+
ok: true,
|
|
37
|
+
inputs
|
|
38
|
+
} : {
|
|
39
|
+
ok: false,
|
|
40
|
+
issues
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Synchronous resolvers over a fixed set of named inputs: a `reference` whose key is a string naming an input resolves to it, and every other key, and every `lookup`, is `not-found`. `resolveCollection` throws, because a fixed map of scalars has no collection to hand back and an empty list would silently change what a `fold`, `some` or `every` means; `delegate` and `treeReference` nodes are left unresolved, so they are `wrong-type` like any node whose optional resolver is absent.
|
|
45
|
+
*/
|
|
46
|
+
function createInputResolvers(inputs) {
|
|
47
|
+
return {
|
|
48
|
+
resolveValue: (key) => {
|
|
49
|
+
const value = typeof key === "string" ? inputs.get(key) : void 0;
|
|
50
|
+
return value === void 0 ? { found: false } : {
|
|
51
|
+
found: true,
|
|
52
|
+
value
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
resolveLookup: () => ({ found: false }),
|
|
56
|
+
resolveCollection: (collection) => {
|
|
57
|
+
throw new Error(`collection ${JSON.stringify(collection)} cannot be resolved: named inputs hold scalar values only`);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
exports.createInputResolvers = createInputResolvers;
|
|
63
|
+
exports.parseInputs = parseInputs;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { t as ComputedValue } from "./computed-value-CbRF0Izc.cjs";
|
|
2
|
+
import { SyncResolvers } from "./resolvers.cjs";
|
|
3
|
+
//#region src/input-resolvers.d.ts
|
|
4
|
+
export type InputsParseResult = {
|
|
5
|
+
ok: true;
|
|
6
|
+
inputs: ReadonlyMap<string, ComputedValue>;
|
|
7
|
+
} | {
|
|
8
|
+
ok: false;
|
|
9
|
+
issues: readonly string[];
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Validates a plain object of named inputs, one `ComputedValue` per name (see `toComputedValue` for the accepted shapes). Every entry is checked up front, so a malformed input is reported as one by name rather than surfacing later as a `not-found` reference.
|
|
13
|
+
*/
|
|
14
|
+
export declare function parseInputs(raw: unknown): InputsParseResult;
|
|
15
|
+
/**
|
|
16
|
+
* Synchronous resolvers over a fixed set of named inputs: a `reference` whose key is a string naming an input resolves to it, and every other key, and every `lookup`, is `not-found`. `resolveCollection` throws, because a fixed map of scalars has no collection to hand back and an empty list would silently change what a `fold`, `some` or `every` means; `delegate` and `treeReference` nodes are left unresolved, so they are `wrong-type` like any node whose optional resolver is absent.
|
|
17
|
+
*/
|
|
18
|
+
export declare function createInputResolvers(inputs: ReadonlyMap<string, ComputedValue>): SyncResolvers;
|
|
19
|
+
//#endregion
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { t as ComputedValue } from "./computed-value-CbRF0Izc.js";
|
|
2
|
+
import { SyncResolvers } from "./resolvers.js";
|
|
3
|
+
//#region src/input-resolvers.d.ts
|
|
4
|
+
export type InputsParseResult = {
|
|
5
|
+
ok: true;
|
|
6
|
+
inputs: ReadonlyMap<string, ComputedValue>;
|
|
7
|
+
} | {
|
|
8
|
+
ok: false;
|
|
9
|
+
issues: readonly string[];
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Validates a plain object of named inputs, one `ComputedValue` per name (see `toComputedValue` for the accepted shapes). Every entry is checked up front, so a malformed input is reported as one by name rather than surfacing later as a `not-found` reference.
|
|
13
|
+
*/
|
|
14
|
+
export declare function parseInputs(raw: unknown): InputsParseResult;
|
|
15
|
+
/**
|
|
16
|
+
* Synchronous resolvers over a fixed set of named inputs: a `reference` whose key is a string naming an input resolves to it, and every other key, and every `lookup`, is `not-found`. `resolveCollection` throws, because a fixed map of scalars has no collection to hand back and an empty list would silently change what a `fold`, `some` or `every` means; `delegate` and `treeReference` nodes are left unresolved, so they are `wrong-type` like any node whose optional resolver is absent.
|
|
17
|
+
*/
|
|
18
|
+
export declare function createInputResolvers(inputs: ReadonlyMap<string, ComputedValue>): SyncResolvers;
|
|
19
|
+
//#endregion
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { ComputedValueSchema } from "./computed-value.js";
|
|
2
|
+
import { isPlainRecord } from "./plain-record.js";
|
|
3
|
+
//#region src/input-resolvers.ts
|
|
4
|
+
/** A plain JSON number, string or boolean is the unit-less value of that kind; anything else must already be a complete `ComputedValue` (the only way to supply units, durations, instants or complex values). Both routes end in `ComputedValueSchema`, so a number that is not finite (`1e999` parses to `Infinity`) is refused whichever way it was written, and a field the schema does not define is dropped rather than carried along. */
|
|
5
|
+
function toComputedValue(raw) {
|
|
6
|
+
const candidate = typeof raw === "number" ? {
|
|
7
|
+
kind: "number",
|
|
8
|
+
value: raw
|
|
9
|
+
} : typeof raw === "string" ? {
|
|
10
|
+
kind: "text",
|
|
11
|
+
value: raw
|
|
12
|
+
} : typeof raw === "boolean" ? {
|
|
13
|
+
kind: "boolean",
|
|
14
|
+
value: raw
|
|
15
|
+
} : raw;
|
|
16
|
+
const parsed = ComputedValueSchema.safeParse(candidate);
|
|
17
|
+
return parsed.success ? parsed.data : void 0;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Validates a plain object of named inputs, one `ComputedValue` per name (see `toComputedValue` for the accepted shapes). Every entry is checked up front, so a malformed input is reported as one by name rather than surfacing later as a `not-found` reference.
|
|
21
|
+
*/
|
|
22
|
+
function parseInputs(raw) {
|
|
23
|
+
if (!isPlainRecord(raw)) return {
|
|
24
|
+
ok: false,
|
|
25
|
+
issues: ["inputs must be a JSON object of named values"]
|
|
26
|
+
};
|
|
27
|
+
const inputs = /* @__PURE__ */ new Map();
|
|
28
|
+
const issues = [];
|
|
29
|
+
for (const [name, value] of Object.entries(raw)) {
|
|
30
|
+
const computed = toComputedValue(value);
|
|
31
|
+
if (computed === void 0) issues.push(`inputs.${name}: expected a finite number, text, boolean or a complete computed value`);
|
|
32
|
+
else inputs.set(name, computed);
|
|
33
|
+
}
|
|
34
|
+
return issues.length === 0 ? {
|
|
35
|
+
ok: true,
|
|
36
|
+
inputs
|
|
37
|
+
} : {
|
|
38
|
+
ok: false,
|
|
39
|
+
issues
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Synchronous resolvers over a fixed set of named inputs: a `reference` whose key is a string naming an input resolves to it, and every other key, and every `lookup`, is `not-found`. `resolveCollection` throws, because a fixed map of scalars has no collection to hand back and an empty list would silently change what a `fold`, `some` or `every` means; `delegate` and `treeReference` nodes are left unresolved, so they are `wrong-type` like any node whose optional resolver is absent.
|
|
44
|
+
*/
|
|
45
|
+
function createInputResolvers(inputs) {
|
|
46
|
+
return {
|
|
47
|
+
resolveValue: (key) => {
|
|
48
|
+
const value = typeof key === "string" ? inputs.get(key) : void 0;
|
|
49
|
+
return value === void 0 ? { found: false } : {
|
|
50
|
+
found: true,
|
|
51
|
+
value
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
resolveLookup: () => ({ found: false }),
|
|
55
|
+
resolveCollection: (collection) => {
|
|
56
|
+
throw new Error(`collection ${JSON.stringify(collection)} cannot be resolved: named inputs hold scalar values only`);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
61
|
+
export { createInputResolvers, parseInputs };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/integer-power.ts
|
|
3
|
+
/**
|
|
4
|
+
* `base` raised to a non-negative integer `exponent` by exponentiation by squaring: one squaring and at most one product per bit of the exponent, so the number of `multiply` calls grows with the logarithm of the exponent where repeated multiplication grows with the exponent itself (an exponent of 1e9 is a few dozen products rather than a billion). `identity` is the value of exponent zero and the start of the product; `multiply` must be associative, which squaring relies on. With a rounding `multiply` the grouping matters: squaring compounds a rounding error through each successive square, so its error grows in proportion to the exponent, and for large exponents the result is many times less accurate than a plain loop's, in exchange for work that does not grow with the exponent.
|
|
5
|
+
*
|
|
6
|
+
* The exponent is halved with `Math.floor(remaining / 2)` and tested for oddness with `% 2`, both exact for any finite double, including those past the largest safe integer, whose low bits are all zero. The last squaring is skipped, so no unused product is formed and a base too large to square is not squared once more than the result needs.
|
|
7
|
+
*/
|
|
8
|
+
function powerByRepeatedSquaring({ base, exponent, identity, multiply }) {
|
|
9
|
+
let result = identity;
|
|
10
|
+
let factor = base;
|
|
11
|
+
let remaining = exponent;
|
|
12
|
+
while (remaining > 0) {
|
|
13
|
+
if (remaining % 2 === 1) result = multiply(result, factor);
|
|
14
|
+
remaining = Math.floor(remaining / 2);
|
|
15
|
+
if (remaining > 0) factor = multiply(factor, factor);
|
|
16
|
+
}
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
exports.powerByRepeatedSquaring = powerByRepeatedSquaring;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/integer-power.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* `base` raised to a non-negative integer `exponent` by exponentiation by squaring: one squaring and at most one product per bit of the exponent, so the number of `multiply` calls grows with the logarithm of the exponent where repeated multiplication grows with the exponent itself (an exponent of 1e9 is a few dozen products rather than a billion). `identity` is the value of exponent zero and the start of the product; `multiply` must be associative, which squaring relies on. With a rounding `multiply` the grouping matters: squaring compounds a rounding error through each successive square, so its error grows in proportion to the exponent, and for large exponents the result is many times less accurate than a plain loop's, in exchange for work that does not grow with the exponent.
|
|
4
|
+
*
|
|
5
|
+
* The exponent is halved with `Math.floor(remaining / 2)` and tested for oddness with `% 2`, both exact for any finite double, including those past the largest safe integer, whose low bits are all zero. The last squaring is skipped, so no unused product is formed and a base too large to square is not squared once more than the result needs.
|
|
6
|
+
*/
|
|
7
|
+
export declare function powerByRepeatedSquaring<T>({ base, exponent, identity, multiply }: {
|
|
8
|
+
base: T;
|
|
9
|
+
exponent: number;
|
|
10
|
+
identity: T;
|
|
11
|
+
multiply: (left: T, right: T) => T;
|
|
12
|
+
}): T;
|
|
13
|
+
//#endregion
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/integer-power.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* `base` raised to a non-negative integer `exponent` by exponentiation by squaring: one squaring and at most one product per bit of the exponent, so the number of `multiply` calls grows with the logarithm of the exponent where repeated multiplication grows with the exponent itself (an exponent of 1e9 is a few dozen products rather than a billion). `identity` is the value of exponent zero and the start of the product; `multiply` must be associative, which squaring relies on. With a rounding `multiply` the grouping matters: squaring compounds a rounding error through each successive square, so its error grows in proportion to the exponent, and for large exponents the result is many times less accurate than a plain loop's, in exchange for work that does not grow with the exponent.
|
|
4
|
+
*
|
|
5
|
+
* The exponent is halved with `Math.floor(remaining / 2)` and tested for oddness with `% 2`, both exact for any finite double, including those past the largest safe integer, whose low bits are all zero. The last squaring is skipped, so no unused product is formed and a base too large to square is not squared once more than the result needs.
|
|
6
|
+
*/
|
|
7
|
+
export declare function powerByRepeatedSquaring<T>({ base, exponent, identity, multiply }: {
|
|
8
|
+
base: T;
|
|
9
|
+
exponent: number;
|
|
10
|
+
identity: T;
|
|
11
|
+
multiply: (left: T, right: T) => T;
|
|
12
|
+
}): T;
|
|
13
|
+
//#endregion
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//#region src/integer-power.ts
|
|
2
|
+
/**
|
|
3
|
+
* `base` raised to a non-negative integer `exponent` by exponentiation by squaring: one squaring and at most one product per bit of the exponent, so the number of `multiply` calls grows with the logarithm of the exponent where repeated multiplication grows with the exponent itself (an exponent of 1e9 is a few dozen products rather than a billion). `identity` is the value of exponent zero and the start of the product; `multiply` must be associative, which squaring relies on. With a rounding `multiply` the grouping matters: squaring compounds a rounding error through each successive square, so its error grows in proportion to the exponent, and for large exponents the result is many times less accurate than a plain loop's, in exchange for work that does not grow with the exponent.
|
|
4
|
+
*
|
|
5
|
+
* The exponent is halved with `Math.floor(remaining / 2)` and tested for oddness with `% 2`, both exact for any finite double, including those past the largest safe integer, whose low bits are all zero. The last squaring is skipped, so no unused product is formed and a base too large to square is not squared once more than the result needs.
|
|
6
|
+
*/
|
|
7
|
+
function powerByRepeatedSquaring({ base, exponent, identity, multiply }) {
|
|
8
|
+
let result = identity;
|
|
9
|
+
let factor = base;
|
|
10
|
+
let remaining = exponent;
|
|
11
|
+
while (remaining > 0) {
|
|
12
|
+
if (remaining % 2 === 1) result = multiply(result, factor);
|
|
13
|
+
remaining = Math.floor(remaining / 2);
|
|
14
|
+
if (remaining > 0) factor = multiply(factor, factor);
|
|
15
|
+
}
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { powerByRepeatedSquaring };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/plain-record.ts
|
|
3
|
+
/** Narrows `unknown` to a plain JSON-style object: not `null`, not an array. The guard parsed JSON is checked with before its fields are read, in place of an `as Record<string, unknown>` assertion. */
|
|
4
|
+
function isPlainRecord(value) {
|
|
5
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
6
|
+
}
|
|
7
|
+
//#endregion
|
|
8
|
+
exports.isPlainRecord = isPlainRecord;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
//#region src/plain-record.d.ts
|
|
2
|
+
/** Narrows `unknown` to a plain JSON-style object: not `null`, not an array. The guard parsed JSON is checked with before its fields are read, in place of an `as Record<string, unknown>` assertion. */
|
|
3
|
+
export declare function isPlainRecord(value: unknown): value is Record<string, unknown>;
|
|
4
|
+
//#endregion
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
//#region src/plain-record.d.ts
|
|
2
|
+
/** Narrows `unknown` to a plain JSON-style object: not `null`, not an array. The guard parsed JSON is checked with before its fields are read, in place of an `as Record<string, unknown>` assertion. */
|
|
3
|
+
export declare function isPlainRecord(value: unknown): value is Record<string, unknown>;
|
|
4
|
+
//#endregion
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
//#region src/plain-record.ts
|
|
2
|
+
/** Narrows `unknown` to a plain JSON-style object: not `null`, not an array. The guard parsed JSON is checked with before its fields are read, in place of an `as Record<string, unknown>` assertion. */
|
|
3
|
+
function isPlainRecord(value) {
|
|
4
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
5
|
+
}
|
|
6
|
+
//#endregion
|
|
7
|
+
export { isPlainRecord };
|