solve-engine 1.0.0-beta.0 → 1.0.0-beta.2
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/BytecodeBuilder-3egMyuDi.d.cts +274 -0
- package/dist/BytecodeBuilder-3egMyuDi.d.ts +274 -0
- package/dist/Configuration-fVpd-HC-.d.cts +228 -0
- package/dist/Configuration-fVpd-HC-.d.ts +228 -0
- package/dist/EngineError-DvPSnhZi.d.cts +304 -0
- package/dist/EngineError-DvPSnhZi.d.ts +304 -0
- package/dist/Lexer-BJdhlnej.d.cts +531 -0
- package/dist/Lexer-D9l4Yrk2.d.ts +531 -0
- package/dist/NormalizerRule-BrVoVjmP.d.cts +163 -0
- package/dist/NormalizerRule-CEjf1FyD.d.ts +163 -0
- package/dist/PackageRegistry-D-Tv_7ca.d.cts +2572 -0
- package/dist/PackageRegistry-DaH4aIKP.d.ts +2572 -0
- package/dist/Parselet-CK8cQu2a.d.cts +299 -0
- package/dist/Parselet-ConOIdRO.d.ts +299 -0
- package/dist/ScopeManager-B5k0nk05.d.ts +559 -0
- package/dist/ScopeManager-CKfQtl7l.d.cts +559 -0
- package/dist/Token-0jpvUdPY.d.cts +245 -0
- package/dist/Token-0jpvUdPY.d.ts +245 -0
- package/dist/VMCheckpoints-BmDwIXgK.d.ts +171 -0
- package/dist/VMCheckpoints-CqFuLwrT.d.cts +171 -0
- package/dist/Value-KtAQNHur.d.cts +295 -0
- package/dist/Value-KtAQNHur.d.ts +295 -0
- package/dist/chunk-2RWAXT6O.js +3 -0
- package/dist/chunk-2RWAXT6O.js.map +1 -0
- package/dist/chunk-34RRD7PC.js +1492 -0
- package/dist/chunk-34RRD7PC.js.map +1 -0
- package/dist/chunk-3PPFLFH4.js +5097 -0
- package/dist/chunk-3PPFLFH4.js.map +1 -0
- package/dist/chunk-3VGDNEE3.js +84 -0
- package/dist/chunk-3VGDNEE3.js.map +1 -0
- package/dist/chunk-3YNVWKR2.cjs +370 -0
- package/dist/chunk-3YNVWKR2.cjs.map +1 -0
- package/dist/chunk-47LRVGOT.cjs +316 -0
- package/dist/chunk-47LRVGOT.cjs.map +1 -0
- package/dist/chunk-4MG4XKO2.js +1644 -0
- package/dist/chunk-4MG4XKO2.js.map +1 -0
- package/dist/chunk-4QADQTWS.js +2392 -0
- package/dist/chunk-4QADQTWS.js.map +1 -0
- package/dist/chunk-53B6KDDJ.cjs +1651 -0
- package/dist/chunk-53B6KDDJ.cjs.map +1 -0
- package/dist/chunk-5X2PTP6F.cjs +104 -0
- package/dist/chunk-5X2PTP6F.cjs.map +1 -0
- package/dist/chunk-5YEMOYSE.js +264 -0
- package/dist/chunk-5YEMOYSE.js.map +1 -0
- package/dist/chunk-64W6GLLZ.js +481 -0
- package/dist/chunk-64W6GLLZ.js.map +1 -0
- package/dist/chunk-6BKTCEUP.cjs +233 -0
- package/dist/chunk-6BKTCEUP.cjs.map +1 -0
- package/dist/chunk-6NTVRDQV.cjs +1642 -0
- package/dist/chunk-6NTVRDQV.cjs.map +1 -0
- package/dist/chunk-6RDSQURE.js +290 -0
- package/dist/chunk-6RDSQURE.js.map +1 -0
- package/dist/chunk-75JP4BZX.js +93 -0
- package/dist/chunk-75JP4BZX.js.map +1 -0
- package/dist/chunk-B7LXJ6LC.cjs +36 -0
- package/dist/chunk-B7LXJ6LC.cjs.map +1 -0
- package/dist/chunk-BVAR5J2F.js +257 -0
- package/dist/chunk-BVAR5J2F.js.map +1 -0
- package/dist/chunk-C4XZV6E7.cjs +269 -0
- package/dist/chunk-C4XZV6E7.cjs.map +1 -0
- package/dist/chunk-CCJPSHGI.cjs +40 -0
- package/dist/chunk-CCJPSHGI.cjs.map +1 -0
- package/dist/chunk-CLL7RUQV.cjs +316 -0
- package/dist/chunk-CLL7RUQV.cjs.map +1 -0
- package/dist/chunk-DM3LMRBC.js +329 -0
- package/dist/chunk-DM3LMRBC.js.map +1 -0
- package/dist/chunk-DUEZFTK2.js +38 -0
- package/dist/chunk-DUEZFTK2.js.map +1 -0
- package/dist/chunk-EBSPLUW4.cjs +489 -0
- package/dist/chunk-EBSPLUW4.cjs.map +1 -0
- package/dist/chunk-EHAHVROS.cjs +261 -0
- package/dist/chunk-EHAHVROS.cjs.map +1 -0
- package/dist/chunk-EIGTWK5N.js +167 -0
- package/dist/chunk-EIGTWK5N.js.map +1 -0
- package/dist/chunk-EPOXXJBK.js +96 -0
- package/dist/chunk-EPOXXJBK.js.map +1 -0
- package/dist/chunk-FEAIOR7N.cjs +91 -0
- package/dist/chunk-FEAIOR7N.cjs.map +1 -0
- package/dist/chunk-G535KJEG.js +312 -0
- package/dist/chunk-G535KJEG.js.map +1 -0
- package/dist/chunk-GCM5JHMX.js +88 -0
- package/dist/chunk-GCM5JHMX.js.map +1 -0
- package/dist/chunk-GOLDJNMZ.js +368 -0
- package/dist/chunk-GOLDJNMZ.js.map +1 -0
- package/dist/chunk-GW32KPCU.cjs +360 -0
- package/dist/chunk-GW32KPCU.cjs.map +1 -0
- package/dist/chunk-HTXVVJRA.cjs +1549 -0
- package/dist/chunk-HTXVVJRA.cjs.map +1 -0
- package/dist/chunk-HWSZJQCI.js +311 -0
- package/dist/chunk-HWSZJQCI.js.map +1 -0
- package/dist/chunk-IF532O7C.js +101 -0
- package/dist/chunk-IF532O7C.js.map +1 -0
- package/dist/chunk-J73SJHR3.cjs +2415 -0
- package/dist/chunk-J73SJHR3.cjs.map +1 -0
- package/dist/chunk-JBSYC7BB.cjs +7473 -0
- package/dist/chunk-JBSYC7BB.cjs.map +1 -0
- package/dist/chunk-KVILKGMS.js +228 -0
- package/dist/chunk-KVILKGMS.js.map +1 -0
- package/dist/chunk-LIPPNDBE.js +258 -0
- package/dist/chunk-LIPPNDBE.js.map +1 -0
- package/dist/chunk-LR7YASZF.cjs +172 -0
- package/dist/chunk-LR7YASZF.cjs.map +1 -0
- package/dist/chunk-M4N5GA5Z.cjs +309 -0
- package/dist/chunk-M4N5GA5Z.cjs.map +1 -0
- package/dist/chunk-M5LX5AOO.js +7459 -0
- package/dist/chunk-M5LX5AOO.js.map +1 -0
- package/dist/chunk-MZOVP3WI.cjs +96 -0
- package/dist/chunk-MZOVP3WI.cjs.map +1 -0
- package/dist/chunk-N5YFR4UP.cjs +10 -0
- package/dist/chunk-N5YFR4UP.cjs.map +1 -0
- package/dist/chunk-NGBBNL4K.cjs +4 -0
- package/dist/chunk-NGBBNL4K.cjs.map +1 -0
- package/dist/chunk-NH2O2AUR.js +146 -0
- package/dist/chunk-NH2O2AUR.js.map +1 -0
- package/dist/chunk-NLNDMWZC.js +31 -0
- package/dist/chunk-NLNDMWZC.js.map +1 -0
- package/dist/chunk-NMCRQP3Z.cjs +778 -0
- package/dist/chunk-NMCRQP3Z.cjs.map +1 -0
- package/dist/chunk-NMD5VRN4.cjs +1327 -0
- package/dist/chunk-NMD5VRN4.cjs.map +1 -0
- package/dist/chunk-OC6LTXYS.cjs +286 -0
- package/dist/chunk-OC6LTXYS.cjs.map +1 -0
- package/dist/chunk-OT6OJY7C.cjs +114 -0
- package/dist/chunk-OT6OJY7C.cjs.map +1 -0
- package/dist/chunk-PFSDGGYL.js +8 -0
- package/dist/chunk-PFSDGGYL.js.map +1 -0
- package/dist/chunk-QNJ4ACRT.cjs +155 -0
- package/dist/chunk-QNJ4ACRT.cjs.map +1 -0
- package/dist/chunk-QWY3VEZN.js +1637 -0
- package/dist/chunk-QWY3VEZN.js.map +1 -0
- package/dist/chunk-RFYD5TJE.js +111 -0
- package/dist/chunk-RFYD5TJE.js.map +1 -0
- package/dist/chunk-RIN643A3.js +354 -0
- package/dist/chunk-RIN643A3.js.map +1 -0
- package/dist/chunk-RZCWSXTA.cjs +5122 -0
- package/dist/chunk-RZCWSXTA.cjs.map +1 -0
- package/dist/chunk-SDGRK7EP.js +774 -0
- package/dist/chunk-SDGRK7EP.js.map +1 -0
- package/dist/chunk-VEKIWQ3F.cjs +39 -0
- package/dist/chunk-VEKIWQ3F.cjs.map +1 -0
- package/dist/chunk-WQTTOGXC.cjs +99 -0
- package/dist/chunk-WQTTOGXC.cjs.map +1 -0
- package/dist/chunk-X6K3HUOY.cjs +86 -0
- package/dist/chunk-X6K3HUOY.cjs.map +1 -0
- package/dist/chunk-XJCMXB2E.cjs +333 -0
- package/dist/chunk-XJCMXB2E.cjs.map +1 -0
- package/dist/chunk-XVWCOTR6.js +1324 -0
- package/dist/chunk-XVWCOTR6.js.map +1 -0
- package/dist/chunk-YLJ4XMA6.js +33 -0
- package/dist/chunk-YLJ4XMA6.js.map +1 -0
- package/dist/chunk-Z2XP767T.cjs +35 -0
- package/dist/chunk-Z2XP767T.cjs.map +1 -0
- package/dist/chunk-Z4X2RWOF.js +37 -0
- package/dist/chunk-Z4X2RWOF.js.map +1 -0
- package/dist/constants.cjs +22 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/constants.d.cts +12 -0
- package/dist/constants.d.ts +12 -0
- package/dist/constants.js +5 -0
- package/dist/constants.js.map +1 -0
- package/dist/engine.cjs +79 -0
- package/dist/engine.cjs.map +1 -0
- package/dist/engine.d.cts +587 -0
- package/dist/engine.d.ts +587 -0
- package/dist/engine.js +34 -0
- package/dist/engine.js.map +1 -0
- package/dist/errors.cjs +81 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.cts +95 -0
- package/dist/errors.d.ts +95 -0
- package/dist/errors.js +4 -0
- package/dist/errors.js.map +1 -0
- package/dist/format.cjs +171 -0
- package/dist/format.cjs.map +1 -0
- package/dist/format.d.cts +51 -0
- package/dist/format.d.ts +51 -0
- package/dist/format.js +168 -0
- package/dist/format.js.map +1 -0
- package/dist/index.cjs +97 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +152 -0
- package/dist/index.d.ts +152 -0
- package/dist/index.js +75 -0
- package/dist/index.js.map +1 -0
- package/dist/language.cjs +308 -0
- package/dist/language.cjs.map +1 -0
- package/dist/language.d.cts +110 -0
- package/dist/language.d.ts +110 -0
- package/dist/language.js +287 -0
- package/dist/language.js.map +1 -0
- package/dist/lexer.cjs +64 -0
- package/dist/lexer.cjs.map +1 -0
- package/dist/lexer.d.cts +56 -0
- package/dist/lexer.d.ts +56 -0
- package/dist/lexer.js +11 -0
- package/dist/lexer.js.map +1 -0
- package/dist/normalizer.cjs +40 -0
- package/dist/normalizer.cjs.map +1 -0
- package/dist/normalizer.d.cts +364 -0
- package/dist/normalizer.d.ts +364 -0
- package/dist/normalizer.js +11 -0
- package/dist/normalizer.js.map +1 -0
- package/dist/packages.cjs +121 -0
- package/dist/packages.cjs.map +1 -0
- package/dist/packages.d.cts +691 -0
- package/dist/packages.d.ts +691 -0
- package/dist/packages.js +24 -0
- package/dist/packages.js.map +1 -0
- package/dist/parser.cjs +55 -0
- package/dist/parser.cjs.map +1 -0
- package/dist/parser.d.cts +46 -0
- package/dist/parser.d.ts +46 -0
- package/dist/parser.js +10 -0
- package/dist/parser.js.map +1 -0
- package/dist/pipeline-CrsRPmsv.d.ts +285 -0
- package/dist/pipeline-DPUQt7yL.d.cts +285 -0
- package/dist/resolvers.cjs +13 -0
- package/dist/resolvers.cjs.map +1 -0
- package/dist/resolvers.d.cts +111 -0
- package/dist/resolvers.d.ts +111 -0
- package/dist/resolvers.js +4 -0
- package/dist/resolvers.js.map +1 -0
- package/dist/services.cjs +21 -0
- package/dist/services.cjs.map +1 -0
- package/dist/services.d.cts +30 -0
- package/dist/services.d.ts +30 -0
- package/dist/services.js +4 -0
- package/dist/services.js.map +1 -0
- package/dist/uom.cjs +56 -0
- package/dist/uom.cjs.map +1 -0
- package/dist/uom.d.cts +224 -0
- package/dist/uom.d.ts +224 -0
- package/dist/uom.js +11 -0
- package/dist/uom.js.map +1 -0
- package/dist/utilities.cjs +32 -0
- package/dist/utilities.cjs.map +1 -0
- package/dist/utilities.d.cts +113 -0
- package/dist/utilities.d.ts +113 -0
- package/dist/utilities.js +7 -0
- package/dist/utilities.js.map +1 -0
- package/dist/variables.cjs +17 -0
- package/dist/variables.cjs.map +1 -0
- package/dist/variables.d.cts +87 -0
- package/dist/variables.d.ts +87 -0
- package/dist/variables.js +4 -0
- package/dist/variables.js.map +1 -0
- package/dist/vm.cjs +284 -0
- package/dist/vm.cjs.map +1 -0
- package/dist/vm.d.cts +68 -0
- package/dist/vm.d.ts +68 -0
- package/dist/vm.js +194 -0
- package/dist/vm.js.map +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/vm/Value.ts"],"names":["ValueType","v","ErrorFactory"],"mappings":";;;;;AA8CO,IAAK,SAAA,qBAAAA,UAAAA,KAAL;AAEN,EAAAA,UAAAA,CAAAA,UAAAA,CAAA,YAAS,CAAA,CAAA,GAAT,QAAA;AACA,EAAAA,UAAAA,CAAAA,UAAAA,CAAA,SAAM,CAAA,CAAA,GAAN,KAAA;AACA,EAAAA,UAAAA,CAAAA,UAAAA,CAAA,YAAS,CAAA,CAAA,GAAT,QAAA;AACA,EAAAA,UAAAA,CAAAA,UAAAA,CAAA,YAAS,CAAA,CAAA,GAAT,QAAA;AACA,EAAAA,UAAAA,CAAAA,UAAAA,CAAA,cAAW,CAAA,CAAA,GAAX,UAAA;AACA,EAAAA,UAAAA,CAAAA,UAAAA,CAAA,gBAAa,CAAA,CAAA,GAAb,YAAA;AACA,EAAAA,UAAAA,CAAAA,UAAAA,CAAA,SAAM,CAAA,CAAA,GAAN,KAAA;AAEA,EAAAA,UAAAA,CAAAA,UAAAA,CAAA,YAAS,CAAA,CAAA,GAAT,QAAA;AAEA,EAAAA,UAAAA,CAAAA,UAAAA,CAAA,WAAQ,CAAA,CAAA,GAAR,OAAA;AAEA,EAAAA,UAAAA,CAAAA,UAAAA,CAAA,cAAW,CAAA,CAAA,GAAX,UAAA;AAEA,EAAAA,UAAAA,CAAAA,UAAAA,CAAA,aAAU,EAAA,CAAA,GAAV,SAAA;AAEA,EAAAA,UAAAA,CAAAA,UAAAA,CAAA,UAAO,EAAA,CAAA,GAAP,MAAA;AAEA,EAAAA,UAAAA,CAAAA,UAAAA,C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,IAAI,KAAA,CAAM,EAAA,cAAiB,IAAA,EAAM,OAAO,CAAA;AAChD","file":"chunk-OC6LTXYS.cjs","sourcesContent":["import { ErrorFactory } from \"@solve-js/errors/UnifiedErrorFramework\";\nimport type { SymbolicNode } from \"@solve-js/symbolic\";\n\n/**\n * A single matrix cell. `boolean` covers element-wise comparison results\n * (`[1,6;3,8] < [5,2;7,4]` produces a Matrix of booleans, not numbers). A\n * `SymbolicNode` cell is a free-variable algebraic entry, e.g. `s =\n * [sx,0,0;0,sy,0;0,0,1]` where `sx`/`sy` are never assigned, so those\n * cells store a real `SymbolicNode` (a bare `var` node initially) rather\n * than degrading to `0`. See `MatrixOps.ts`'s `entryToSymbolic()`/\n * `symbolicToEntry()` for the two-way conversion every symbolic-aware\n * matrix op (multiply, inverse, determinant) uses.\n */\nexport type MatrixEntry = number | boolean | SymbolicNode;\n\n/**\n * A general rows×cols matrix, a vector is just a 1×N (row) or N×1 (column)\n * matrix. `data` is COLUMN-MAJOR (`data[row + col*rows]`), matching the\n * spec's own `a[index]` column-major indexing semantics directly (no\n * translation needed for single-index reads). `hasSymbolic` lets every\n * numeric matrix op fast-path the all-numeric case with one boolean check,\n * mirroring `binaryOp()`'s existing Number+Number fast path, computed by\n * `matrixValue()` itself (true the moment any cell is a `SymbolicNode`\n * object rather than a plain number/boolean), not something callers set\n * by hand.\n */\nexport interface MatrixData {\n\treadonly rows: number;\n\treadonly cols: number;\n\treadonly data: readonly MatrixEntry[];\n\treadonly hasSymbolic: boolean;\n}\n\n/** A first-class integer range `min:max`, both bounds inclusive. */\nexport interface RangeData {\n\treadonly min: number;\n\treadonly max: number;\n}\n\n/**\n * Discriminated union tag for {@link Value} objects.\n *\n * Determines the runtime type of a Value and how its `value` field should\n * be interpreted. Used by the VM for type-aware dispatch in arithmetic,\n * comparison, and conversion operations.\n */\nexport enum ValueType {\n\t/** Plain 64-bit floating point number (IEEE 754 double) */\n\tNumber = 0,\n\tHex = 1,\n\tBigInt = 2,\n\tString = 3,\n\tDatetime = 4,\n\tPercentage = 5,\n\tUom = 6,\n\t/** General rows×cols matrix (a vector is a 1×N or N×1 matrix). Value is {@link MatrixData}. */\n\tMatrix = 7,\n\t/** A first-class integer range `min:max`, both inclusive. Value is {@link RangeData}. */\n\tRange = 8,\n\t/** A symbolic/algebraic expression tree (free-variable formula, not a concrete number). Value is a `SymbolicNode` (`@solve-js/symbolic`). */\n\tSymbolic = 9,\n\t/** Boolean true/false. Value is `boolean`. */\n\tBoolean = 10,\n\t/** Unit of measurement token (lexer only, not a runtime value). */\n\tUnit = 11,\n\t/** Async result pending resolution. Value stores the queryKey string. */\n\tPending = 12,\n\t/** Plugin-raised error propagated through the DAG. Value stores error code, unit stores message. */\n\tError = 13,\n}\n\n// ── ValueArena ────────────────────────────────────────────────────────────\n// Phase 5.3: Bump-allocator arena for zero-allocation Value reuse during scroll.\n// Instead of allocating new Value objects per instruction, we pre-allocate a\n// block and bump an index. A single arena.reset() per scroll frame recycles all\n// Values, no per-value release overhead, no GC pressure during 60fps scrolling.\n\n/**\n * Bump-allocator arena for zero-allocation Value reuse during scroll.\n *\n * Instead of allocating new Value objects per instruction, pre-allocates a\n * block and bumps an index. `arena.reset()` per scroll frame recycles all\n * Values, no per-value release overhead, no GC pressure during 60fps scrolling.\n *\n * Only active during Tier 2 scroll execution (ThreeTierEvaluator).\n */\nexport class ValueArena {\n\tprivate arena: Value[] = [];\n\tprivate index: number = 0;\n\n\t/** Pre-allocate initial block. 512 Values covers ~30-line viewport comfortably. */\n\tconstructor(initialSize: number = 512) {\n\t\tfor (let i = 0; i < initialSize; i++) {\n\t\t\tthis.arena.push(new Value(ValueType.Number, 0));\n\t\t}\n\t}\n\n\t/** Bump-allocate a recycled Value. Falls back to allocation only for overflow. */\n\tacquire(type: ValueType, value: number | bigint | string | boolean | MatrixData | RangeData | SymbolicNode, unit?: string): Value {\n\t\tif (this.index < this.arena.length) {\n\t\t\tconst v = this.arena[this.index++];\n\t\t\tv.recycle(type, value, unit);\n\t\t\treturn v;\n\t\t}\n\t\t// Arena overflow, allocate fresh (rare, only for very complex expressions)\n\t\tconst v = new Value(type, value, unit);\n\t\tthis.arena.push(v);\n\t\tthis.index++;\n\t\treturn v;\n\t}\n\n\t/** Reset for next scroll frame. O(1), just resets the index. */\n\treset(): void {\n\t\tthis.index = 0;\n\t}\n\n\t/** Current arena utilization (for diagnostics). */\n\tget usage(): number { return this.index; }\n\tget capacity(): number { return this.arena.length; }\n}\n\n// Module-level arena toggle. Single-threaded JS, so global state is safe.\n// The arena is ONLY active during Tier 2 scroll execution, the ThreeTierEvaluator\n// enables it before evaluating visible lines and disables it after.\n//\n// The arena INSTANCE survives disable(): constructing a ValueArena allocates\n// its whole initial block (512 Values), so dropping it on every disable would\n// pay that allocation cost again on the next enable, more garbage than the\n// arena saves. Instead, an `_arenaActive` flag gates use of the long-lived\n// instance; enable() just resets the bump index.\nlet _arena: ValueArena | null = null;\nlet _arenaActive = false;\n\n/** Enable the Value arena for zero-allocation scroll execution. */\nexport function enableValueArena(size?: number): ValueArena {\n\tif (!_arena) _arena = new ValueArena(size);\n\t_arena.reset();\n\t_arenaActive = true;\n\treturn _arena;\n}\n\n/** Disable the arena (returns to normal GC-collected allocation). */\nexport function disableValueArena(): void {\n\t_arenaActive = false;\n}\n\n/** Check if arena is active (used by STORE_VAR / HALT to decide cloning). */\nexport function isArenaActive(): boolean {\n\treturn _arenaActive;\n}\n\n/**\n * Allocate a Value that persists beyond the current arena cycle.\n * Used for values stored in variables (STORE_VAR) and final expression results\n * (HALT return), these must survive arena.reset() in the next scroll frame.\n */\nexport function persistentValue(v: Value): Value {\n\treturn new Value(v.type, v.value, v.unit);\n}\n\n// ── Dev-mode immutability guard (Part II, L5, Value model hardening) ──\n//\n// Value is documented immutable by convention, not enforcement: the arena\n// mutates objects in place via recycle() (by design, for Tier-2 scroll\n// performance), so Value can never be unconditionally frozen. This guard\n// freezes a Value ONLY when it is safe to do so, i.e. NOT while the arena\n// is active, since an arena-active Value may still be recycled later in\n// the same scroll frame. It is a no-op outside development builds (matches\n// the existing `process.env.NODE_ENV === \"development\"` convention used by\n// the app-layer logger) so there is zero runtime cost in production.\nconst isDevelopmentBuild = process.env.NODE_ENV === \"development\";\n\n/**\n * Freeze a Value in development builds, catching accidental external\n * mutation of \"immutable\" results early. Safe to call unconditionally\n * it is a no-op in production and a no-op whenever the arena is active\n * (an arena-active Value may still be recycle()'d before this scroll\n * frame ends, and freezing it would make recycle() throw).\n *\n * Intended for values leaving a public evaluation boundary\n * (ExpressionEngine.evaluateLine* / evaluateExpression), not for values\n * still moving through internal VM/arena machinery.\n */\nexport function freezeIfDev<T extends Value>(value: T): T {\n\tif (isDevelopmentBuild && !isArenaActive()) {\n\t\t// toNumber() lazily memoizes _cachedNumber for bigint/string values\n\t\t// (Number/Hex are already eagerly cached by the constructor), warm\n\t\t// it now so a later toNumber() call on the frozen object doesn't\n\t\t// try to write to a frozen field.\n\t\tvalue.toNumber();\n\t\tObject.freeze(value);\n\t}\n\treturn value;\n}\n\n/**\n * Universal runtime value for the solve-js VM.\n *\n * Carries a {@link ValueType} discriminant, a polymorphic `value` payload,\n * and an optional `unit` string (for UoM values). Treated as immutable after\n * construction, the arena reuses objects internally via `recycle()`, but\n * external code should never mutate Value fields.\n *\n * A cached `_cachedNumber` avoids repeated `toNumber()` computation on\n * hot paths (ADD/SUB/MUL in the VM dispatch loop).\n */\nexport class Value {\n\t// Cached numeric representation, computed once on first toNumber() call.\n\t// Cleared on recycle() when the arena reuses this Value for a new value.\n\tprivate _cachedNumber: number | undefined;\n\n\t// Fields are NOT readonly, the arena reuses Value objects by calling\n\t// recycle() which overwrites all fields. External code should treat Values\n\t// as immutable after construction (arena handles mutation internally).\n\tpublic type: ValueType;\n\tpublic value: number | bigint | string | boolean | MatrixData | RangeData | SymbolicNode;\n\tpublic unit?: string;\n\t/** Set by async resolvers when a fetch timed out, the result is a fallback (typically 0). */\n\tpublic timedOut?: boolean;\n\n\tconstructor(\n\t\ttype: ValueType,\n\t\tvalue: number | bigint | string | boolean | MatrixData | RangeData | SymbolicNode,\n\t\tunit?: string\n\t) {\n\t\tthis.type = type;\n\t\tthis.value = value;\n\t\tthis.unit = unit;\n\t\t// Eagerly cache for Number and Hex types (the most common case).\n\t\t// This avoids a method call + type-check on first toNumber().\n\t\tif (typeof value === 'number') {\n\t\t\tthis._cachedNumber = value;\n\t\t}\n\t}\n\n\t/**\n\t * Phase 5.3: Reset all fields for arena reuse.\n\t * Called by ValueArena.acquire(), zero allocation, just field assignment.\n\t */\n\trecycle(type: ValueType, value: number | bigint | string | boolean | MatrixData | RangeData | SymbolicNode, unit?: string): void {\n\t\tthis.type = type;\n\t\tthis.value = value;\n\t\tthis.unit = unit;\n\t\t// Clear cache, value changed, cached number is stale.\n\t\t// Re-eager-cache for Number type (most common).\n\t\tthis._cachedNumber = typeof value === 'number' ? value : undefined;\n\t\t// Clear timeout flag, recycled Values shouldn't inherit stale metadata.\n\t\tthis.timedOut = undefined;\n\t}\n\n\tisNumber(): this is Value & { value: number } {\n\t\treturn this.type === ValueType.Number;\n\t}\n\n\tisHex(): this is Value & { value: number } {\n\t\treturn this.type === ValueType.Hex;\n\t}\n\n\tisBigInt(): this is Value & { value: bigint } {\n\t\treturn this.type === ValueType.BigInt;\n\t}\n\n\tisString(): this is Value & { value: string } {\n\t\treturn this.type === ValueType.String;\n\t}\n\n\tisMatrix(): this is Value & { value: MatrixData } {\n\t\treturn this.type === ValueType.Matrix;\n\t}\n\n\t/** A Matrix shaped like a vector, 1×N (row) or N×1 (column). */\n\tisVectorShape(): boolean {\n\t\tif (this.type !== ValueType.Matrix) return false;\n\t\tconst m = this.value as MatrixData;\n\t\treturn m.rows === 1 || m.cols === 1;\n\t}\n\n\tisRange(): this is Value & { value: RangeData } {\n\t\treturn this.type === ValueType.Range;\n\t}\n\n\tisSymbolic(): this is Value & { value: SymbolicNode } {\n\t\treturn this.type === ValueType.Symbolic;\n\t}\n\n\ttoNumber(): number {\n\t\t// Pending/Error have no numeric representation at all, 0 (established\n\t\t// convention). A genuinely multi-cell Matrix has no single numeric\n\t\t// representation either (real callers branch on `.isMatrix()` BEFORE\n\t\t// reaching this fallback. See e.g. VM.ts's MUL/comparison dispatch)\n\t\t// but a 1x1 Matrix, the shape `float(x)`'s legacy sugar produces, see\n\t\t// packages/vector/parselets/FloatParselet.ts, IS a scalar in every\n\t\t// meaningful sense, so it degrades to that single cell's numeric value\n\t\t// rather than 0 (this exact case used to work \"by accident\" pre-Matrix,\n\t\t// since `parseFloat([2].toString())` happened to yield `2`).\n\t\tif (this.type === ValueType.Pending) return 0;\n\t\tif (this.type === ValueType.Error) return 0;\n\t\tif (this.type === ValueType.Matrix) {\n\t\t\tconst m = this.value as MatrixData;\n\t\t\tif (m.rows === 1 && m.cols === 1 && typeof m.data[0] === \"number\") return m.data[0];\n\t\t\treturn 0;\n\t\t}\n\t\tif (this.type === ValueType.Range) return 0;\n\t\t// A symbolic expression has no single concrete numeric value by\n\t\t// definition (it's a free-variable formula), 0, matching the\n\t\t// Pending/Error/Range convention. Real callers branch on\n\t\t// `.isSymbolic()` BEFORE reaching this fallback (see\n\t\t// `VMConversion.ts`'s `binaryOp()`).\n\t\tif (this.type === ValueType.Symbolic) return 0;\n\n\t\tif (this._cachedNumber !== undefined) return this._cachedNumber;\n\n\t\tif (typeof this.value === 'bigint') {\n\t\t\tthis._cachedNumber = Number(this.value);\n\t\t\treturn this._cachedNumber;\n\t\t}\n\t\t// Prevent silent NaN propagation from non-numeric strings\n\t\tconst result = parseFloat(this.value as string);\n\t\tthis._cachedNumber = isNaN(result) ? 0 : result;\n\t\treturn this._cachedNumber;\n\t}\n\n\tisNaN(): boolean {\n\t\tif (this.type === ValueType.Pending) return false;\n\t\tif (this.type === ValueType.Error) return false;\n\t\tif (this.type === ValueType.Matrix) {\n\t\t\tconst m = this.value as MatrixData;\n\t\t\tif (m.rows === 1 && m.cols === 1 && typeof m.data[0] === \"number\") return isNaN(m.data[0]);\n\t\t\treturn false;\n\t\t}\n\t\tif (this.type === ValueType.Range) return false;\n\t\tif (this.type === ValueType.Symbolic) return false;\n\t\tif (typeof this.value === 'number') return isNaN(this.value);\n\t\tif (typeof this.value === 'bigint') return false;\n\t\treturn isNaN(parseFloat(this.value as string));\n\t}\n}\n\n/**\n * Create a Number-typed Value. Uses the arena when active for zero-allocation.\n * This is the most common factory, over 90% of all Value creations.\n */\nexport function numberValue(n: number): Value {\n\tif (_arenaActive && _arena) return _arena.acquire(ValueType.Number, n);\n\treturn new Value(ValueType.Number, n);\n}\n\n/** Which base a {@link ValueType.Hex} value is displayed in. */\nexport type DisplayBase = \"hex\" | \"bin\" | \"oct\";\n\n/**\n * Create a Hex-typed Value: a **number** that displays in another base.\n *\n * The type is numeric on purpose, and that is the whole point of it. A base is\n * a way of writing a quantity, not a different kind of quantity, so `0xFF + 1`\n * has to be 256. Returning a string instead makes it 1, because a string reads\n * as zero in arithmetic, and nothing about that failure is visible at the point\n * of use.\n *\n * @param n - The number itself, in full precision.\n * @param base - How to display it, defaulting to hexadecimal. Carried in the\n * `unit` slot, which is free for this type.\n */\nexport function hexValue(n: number, base: DisplayBase = \"hex\"): Value {\n\tconst tag = base === \"hex\" ? undefined : base;\n\tif (_arenaActive && _arena) return _arena.acquire(ValueType.Hex, n, tag);\n\treturn new Value(ValueType.Hex, n, tag);\n}\n\n/** Create a BigInt-typed Value (arbitrary-precision integer). */\nexport function bigIntValue(n: bigint): Value {\n\tif (_arenaActive && _arena) return _arena.acquire(ValueType.BigInt, n);\n\treturn new Value(ValueType.BigInt, n);\n}\n\n/** Create a String-typed Value. */\nexport function stringValue(s: string): Value {\n\tif (_arenaActive && _arena) return _arena.acquire(ValueType.String, s);\n\treturn new Value(ValueType.String, s);\n}\n\n/** Create a Unit-of-Measurement Value (typed number with unit annotation). */\nexport function uomValue(n: number, unit: string): Value {\n\tif (_arenaActive && _arena) return _arena.acquire(ValueType.Uom, n, unit);\n\treturn new Value(ValueType.Uom, n, unit);\n}\n\n// ── Rate, \"quantity per unit of something\" (SoulverCore: `$99/week`\n// `3 hours/day`, `30 fps`). Represented as a `ValueType.Uom` (no new\n// ValueType, a rate IS a unit-of-measurement, just a compound one) whose\n// `unit` string is `\"<numerator>/<denominator>\"`. The numerator is an\n// opaque label (may be a real convertible unit like \"USD\"/\"km\", or a bare\n// tag like \"frames\" that the `convert` package doesn't know about, rate\n// arithmetic never needs to convert the numerator, only compare it for\n// equality when combining two rates). The denominator MUST be a unit\n// `convertUnit()`/`getMeasure()` (uom/UomConverter.ts) recognizes, since\n// that's the part rate arithmetic actually rescales. See `vm/VM.ts`'s\n// `RATE_CONVERT`/`RATE_MUL`/`RATE_DIV` opcodes for the operations built on\n// this representation.\n\n/** Create a Rate value: `magnitude` of `numeratorUnit` per one `denominatorUnit`. */\nexport function rateValue(magnitude: number, numeratorUnit: string, denominatorUnit: string): Value {\n\treturn uomValue(magnitude, `${numeratorUnit}/${denominatorUnit}`);\n}\n\n/** Whether `unit` is a compound rate unit (`\"X/Y\"`) rather than a plain unit. */\nexport function isRateUnit(unit: string | undefined): unit is string {\n\treturn typeof unit === \"string\" && unit.includes(\"/\");\n}\n\n/**\n * Split a rate unit string into its numerator/denominator halves.\n * @throws if `unit` isn't a rate unit, check with {@link isRateUnit} first.\n */\nexport function splitRateUnit(unit: string): { numerator: string; denominator: string } {\n\tconst idx = unit.indexOf(\"/\");\n\tif (idx < 0) {\n\t\tthrow ErrorFactory.internal(\n\t\t\t\"INVALID_RATE_UNIT\",\n\t\t\t`splitRateUnit: \"${unit}\" is not a rate unit (expected \"numerator/denominator\")`,\n\t\t\t{ unit },\n\t\t);\n\t}\n\treturn { numerator: unit.slice(0, idx), denominator: unit.slice(idx + 1) };\n}\n\n/** Join a numerator/denominator pair back into a rate unit string. */\nexport function joinRateUnit(numeratorUnit: string, denominatorUnit: string): string {\n\treturn `${numeratorUnit}/${denominatorUnit}`;\n}\n\n// ── Video timecode, \"HH:MM:SS:FF at a given fps\" (SoulverCore: video\n// editing timecode literals, e.g. `01:02:03:04 at 30fps`). Represented the\n// same way Rate is above: NOT a new ValueType, just a `ValueType.Uom` whose\n// `unit` string is `\"timecode@<fps>\"` and whose numeric `value` is the\n// TOTAL FRAME COUNT since 00:00:00:00 at that fps, e.g. \"00:00:01:00 at\n// 30fps\" is `Uom(30, \"timecode@30\")`.\n//\n// Storing the total frame count (rather than four separate H/M/S/F fields)\n// means ordinary integer addition/subtraction on the numeric value is\n// ALREADY correct carry/borrow-aware arithmetic with zero extra logic\n// e.g. \"frame 29 + 2 frames\" at 30fps is just `29 + 2 = 31`, and 31 total\n// frames at 30fps IS frame 1 of the next second, with no explicit carry\n// step required. Carry/borrow only needs to be reconstructed when\n// converting a total frame count back into HH:MM:SS:FF display notation\n// see `packages/time/timecode/TimecodeMath.ts`'s `framesToTimecodeString()`.\n// See `vm/VM.ts`'s ADD/SUB dispatch for the arithmetic built on this\n// representation (timecode + frames, + duration, + timecode, - timecode).\n\nconst TIMECODE_UNIT_PREFIX = \"timecode@\";\n\n/** Build a timecode Uom unit string embedding its frame rate, e.g. `timecodeUnit(30)` -> `\"timecode@30\"`. */\nexport function timecodeUnit(fps: number): string {\n\treturn `${TIMECODE_UNIT_PREFIX}${fps}`;\n}\n\n/** Whether `unit` is a compound video-timecode unit (`\"timecode@<fps>\"`). */\nexport function isTimecodeUnit(unit: string | undefined): unit is string {\n\treturn typeof unit === \"string\" && unit.startsWith(TIMECODE_UNIT_PREFIX);\n}\n\n/**\n * Extract the fps from a timecode unit string.\n * @throws if `unit` isn't a timecode unit, check with {@link isTimecodeUnit} first.\n */\nexport function timecodeFps(unit: string): number {\n\tif (!isTimecodeUnit(unit)) {\n\t\tthrow ErrorFactory.internal(\n\t\t\t\"INVALID_TIMECODE_UNIT\",\n\t\t\t`timecodeFps: \"${unit}\" is not a timecode unit (expected \"timecode@<fps>\")`,\n\t\t\t{ unit },\n\t\t);\n\t}\n\treturn parseFloat(unit.slice(TIMECODE_UNIT_PREFIX.length));\n}\n\n/**\n * Create a Matrix value from an explicit shape + column-major data array.\n * `data.length` must equal `rows*cols`, callers building a matrix from\n * row-major source syntax (e.g. the `[1,2;3,4]` literal) must transpose\n * into column-major order before calling this; see `MatrixOps.ts`'s\n * `rowMajorToColumnMajor()`.\n */\nexport function matrixValue(rows: number, cols: number, data: readonly MatrixEntry[]): Value {\n\t// A SymbolicNode cell is the only object-typed MatrixEntry variant\n\t// (number/boolean are primitives), a cheap, always-correct way to\n\t// derive hasSymbolic without asking every caller to track it by hand.\n\t// The `\"kind\" in cell` half is a tripwire, not redundancy. MatrixEntry is\n\t// `number | boolean | SymbolicNode`, so an object cell should always be a\n\t// node; requiring the discriminant means a Rational that escaped\n\t// MatrixOps.ts's symbolicToEntry() shows up as a wrong result rather than as\n\t// a matrix that silently believes it is symbolic.\n\tconst hasSymbolic = data.some(cell => typeof cell === \"object\" && cell !== null && \"kind\" in cell);\n\tconst m: MatrixData = { rows, cols, data, hasSymbolic };\n\tif (_arenaActive && _arena) return _arena.acquire(ValueType.Matrix, m);\n\treturn new Value(ValueType.Matrix, m);\n}\n\n/** A 1×N row-vector Matrix, row-major and column-major storage are identical for a single row. */\nexport function rowVectorValue(data: readonly number[]): Value {\n\treturn matrixValue(1, data.length, data);\n}\n\n/** An N×1 column-vector Matrix, row-major and column-major storage are identical for a single column. */\nexport function colVectorValue(data: readonly number[]): Value {\n\treturn matrixValue(data.length, 1, data);\n}\n\n/** Create a Range value, a first-class integer range `min:max`, both bounds inclusive. */\nexport function rangeValue(min: number, max: number): Value {\n\tconst r: RangeData = { min, max };\n\tif (_arenaActive && _arena) return _arena.acquire(ValueType.Range, r);\n\treturn new Value(ValueType.Range, r);\n}\n\n/** Create a Symbolic value, a free-variable algebraic expression tree (`symbolic/SymbolicNode.ts`'s `SymbolicNode`), not a concrete number. */\nexport function symbolicValue(node: SymbolicNode): Value {\n\tif (_arenaActive && _arena) return _arena.acquire(ValueType.Symbolic, node);\n\treturn new Value(ValueType.Symbolic, node);\n}\n\n\n\n/** Create a Boolean-typed Value. */\nexport function boolValue(b: boolean): Value {\n\tif (_arenaActive && _arena) return _arena.acquire(ValueType.Boolean, b);\n\treturn new Value(ValueType.Boolean, b);\n}\n\n/** Create a Datetime-typed Value (Unix timestamp in milliseconds). */\nexport function datetimeValue(n: number): Value {\n\tif (_arenaActive && _arena) return _arena.acquire(ValueType.Datetime, n);\n\treturn new Value(ValueType.Datetime, n);\n}\n\n/** Create a Percentage-typed Value (stored as fraction, e.g. 0.5 for 50%). */\nexport function percentageValue(n: number): Value {\n\tif (_arenaActive && _arena) return _arena.acquire(ValueType.Percentage, n);\n\treturn new Value(ValueType.Percentage, n);\n}\n\n/**\n * Create a Pending value, signals that an async result is not yet resolved.\n * The value field stores the queryKey string for deduplication and diagnostics.\n * Pending values should NEVER be stored in the arena (they persist across\n * scroll frames until resolution completes).\n */\nexport function pendingValue(queryKey: string): Value {\n\treturn new Value(ValueType.Pending, queryKey);\n}\n\n/**\n * Create an Error value, propagated through the DAG when a plugin raises an error.\n * The value field stores the EngineError code, unit stores the message.\n * Downstream consumers (lines that depend on errored data) bubble this up.\n * Should NEVER be stored in the arena.\n */\nexport function errorValue(code: string, message: string): Value {\n\treturn new Value(ValueType.Error, code, message);\n}\n"]}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/uom/CurrencyAliases.ts
|
|
4
|
+
var CURRENCY_SYMBOL_ALIASES = {
|
|
5
|
+
"$": "USD",
|
|
6
|
+
"\xA3": "GBP",
|
|
7
|
+
"\u20AC": "EUR",
|
|
8
|
+
// ¥ is genuinely ambiguous between JPY and CNY in real-world usage, JPY
|
|
9
|
+
// is the conventional default (matches Numi/most calculator apps' own
|
|
10
|
+
// choice); a user wanting CNY specifically can still type "CNY" directly.
|
|
11
|
+
"\xA5": "JPY",
|
|
12
|
+
"\u20BD": "RUB",
|
|
13
|
+
"\u20A9": "KRW",
|
|
14
|
+
"\u20B9": "INR",
|
|
15
|
+
"\u20BA": "TRY",
|
|
16
|
+
"\u20B4": "UAH",
|
|
17
|
+
"\u20AA": "ILS",
|
|
18
|
+
"\u20AB": "VND",
|
|
19
|
+
"\u20A6": "NGN",
|
|
20
|
+
"\u20B1": "PHP"
|
|
21
|
+
};
|
|
22
|
+
var CURRENCY_WORD_ALIASES = {
|
|
23
|
+
dollar: "USD",
|
|
24
|
+
dollars: "USD",
|
|
25
|
+
euro: "EUR",
|
|
26
|
+
euros: "EUR",
|
|
27
|
+
yen: "JPY",
|
|
28
|
+
ruble: "RUB",
|
|
29
|
+
rubles: "RUB",
|
|
30
|
+
rouble: "RUB",
|
|
31
|
+
roubles: "RUB",
|
|
32
|
+
won: "KRW",
|
|
33
|
+
rupee: "INR",
|
|
34
|
+
rupees: "INR",
|
|
35
|
+
yuan: "CNY",
|
|
36
|
+
renminbi: "CNY",
|
|
37
|
+
franc: "CHF",
|
|
38
|
+
francs: "CHF",
|
|
39
|
+
rand: "ZAR",
|
|
40
|
+
krona: "SEK",
|
|
41
|
+
kronor: "SEK",
|
|
42
|
+
krone: "NOK",
|
|
43
|
+
kroner: "NOK",
|
|
44
|
+
real: "BRL",
|
|
45
|
+
reais: "BRL",
|
|
46
|
+
peso: "MXN",
|
|
47
|
+
pesos: "MXN",
|
|
48
|
+
shekel: "ILS",
|
|
49
|
+
shekels: "ILS",
|
|
50
|
+
lira: "TRY",
|
|
51
|
+
hryvnia: "UAH",
|
|
52
|
+
hryvnias: "UAH",
|
|
53
|
+
zloty: "PLN",
|
|
54
|
+
zlotys: "PLN",
|
|
55
|
+
forint: "HUF",
|
|
56
|
+
koruna: "CZK",
|
|
57
|
+
dirham: "AED",
|
|
58
|
+
dirhams: "AED",
|
|
59
|
+
riyal: "SAR",
|
|
60
|
+
riyals: "SAR",
|
|
61
|
+
rial: "SAR",
|
|
62
|
+
rials: "SAR",
|
|
63
|
+
ringgit: "MYR",
|
|
64
|
+
rupiah: "IDR",
|
|
65
|
+
baht: "THB",
|
|
66
|
+
dong: "VND",
|
|
67
|
+
naira: "NGN"
|
|
68
|
+
};
|
|
69
|
+
function resolveCurrencyAlias(text) {
|
|
70
|
+
return CURRENCY_SYMBOL_ALIASES[text] ?? CURRENCY_WORD_ALIASES[text.toLowerCase()];
|
|
71
|
+
}
|
|
72
|
+
var CURRENCY_DISPLAY = {
|
|
73
|
+
USD: { symbol: "$", position: "prefix", spaced: false },
|
|
74
|
+
AUD: { symbol: "$", position: "prefix", spaced: false },
|
|
75
|
+
CAD: { symbol: "$", position: "prefix", spaced: false },
|
|
76
|
+
NZD: { symbol: "$", position: "prefix", spaced: false },
|
|
77
|
+
HKD: { symbol: "$", position: "prefix", spaced: false },
|
|
78
|
+
SGD: { symbol: "$", position: "prefix", spaced: false },
|
|
79
|
+
MXN: { symbol: "$", position: "prefix", spaced: false },
|
|
80
|
+
GBP: { symbol: "\xA3", position: "prefix", spaced: false },
|
|
81
|
+
// English-language convention (€100.00), many EU locales instead suffix
|
|
82
|
+
// with a space ("100,00 €"); this engine's default locale is "en", so
|
|
83
|
+
// the English convention was chosen. A locale-aware override would be a
|
|
84
|
+
// reasonable future extension, not attempted here.
|
|
85
|
+
EUR: { symbol: "\u20AC", position: "prefix", spaced: false },
|
|
86
|
+
JPY: { symbol: "\xA5", position: "prefix", spaced: false },
|
|
87
|
+
CNY: { symbol: "\xA5", position: "prefix", spaced: false },
|
|
88
|
+
KRW: { symbol: "\u20A9", position: "prefix", spaced: false },
|
|
89
|
+
INR: { symbol: "\u20B9", position: "prefix", spaced: false },
|
|
90
|
+
// Russian convention places the ruble sign AFTER the amount, with a space.
|
|
91
|
+
RUB: { symbol: "\u20BD", position: "suffix", spaced: true },
|
|
92
|
+
TRY: { symbol: "\u20BA", position: "prefix", spaced: false },
|
|
93
|
+
UAH: { symbol: "\u20B4", position: "suffix", spaced: true },
|
|
94
|
+
ILS: { symbol: "\u20AA", position: "prefix", spaced: false },
|
|
95
|
+
// Vietnamese convention: no space, symbol after the amount.
|
|
96
|
+
VND: { symbol: "\u20AB", position: "suffix", spaced: false },
|
|
97
|
+
NGN: { symbol: "\u20A6", position: "prefix", spaced: false },
|
|
98
|
+
PHP: { symbol: "\u20B1", position: "prefix", spaced: false },
|
|
99
|
+
BRL: { symbol: "R$", position: "prefix", spaced: false },
|
|
100
|
+
ZAR: { symbol: "R", position: "prefix", spaced: false },
|
|
101
|
+
// Scandinavian convention: amount then "kr", space-separated.
|
|
102
|
+
SEK: { symbol: "kr", position: "suffix", spaced: true },
|
|
103
|
+
NOK: { symbol: "kr", position: "suffix", spaced: true },
|
|
104
|
+
DKK: { symbol: "kr", position: "suffix", spaced: true },
|
|
105
|
+
PLN: { symbol: "z\u0142", position: "suffix", spaced: true },
|
|
106
|
+
CHF: { symbol: "Fr", position: "suffix", spaced: true },
|
|
107
|
+
HUF: { symbol: "Ft", position: "suffix", spaced: true },
|
|
108
|
+
CZK: { symbol: "K\u010D", position: "suffix", spaced: true }
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
exports.CURRENCY_DISPLAY = CURRENCY_DISPLAY;
|
|
112
|
+
exports.resolveCurrencyAlias = resolveCurrencyAlias;
|
|
113
|
+
//# sourceMappingURL=chunk-OT6OJY7C.cjs.map
|
|
114
|
+
//# sourceMappingURL=chunk-OT6OJY7C.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/uom/CurrencyAliases.ts"],"names":[],"mappings":";;;AAwBO,IAAM,uBAAA,GAAkD;AAAA,EAC7D,GAAA,EAAK,KAAA;AAAA,EACL,MAAA,EAAK,KAAA;AAAA,EACL,QAAA,EAAK,KAAA;AAAA;AAAA;AAAA;AAAA,EAIL,MAAA,EAAK,KAAA;AAAA,EACL,QAAA,EAAK,KAAA;AAAA,EACL,QAAA,EAAK,KAAA;AAAA,EACL,QAAA,EAAK,KAAA;AAAA,EACL,QAAA,EAAK,KAAA;AAAA,EACL,QAAA,EAAK,KAAA;AAAA,EACL,QAAA,EAAK,KAAA;AAAA,EACL,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Q,MAAM,QAAA,EAAU,QAAA,EAAU,QAAQ,IAAA,EAAK;AAAA,EACtD,KAAK,EAAE,MAAA,EAAQ,MAAM,QAAA,EAAU,QAAA,EAAU,QAAQ,IAAA,EAAK;AAAA,EACtD,KAAK,EAAE,MAAA,EAAQ,WAAM,QAAA,EAAU,QAAA,EAAU,QAAQ,IAAA,EAAK;AAAA,EACtD,KAAK,EAAE,MAAA,EAAQ,MAAM,QAAA,EAAU,QAAA,EAAU,QAAQ,IAAA,EAAK;AAAA,EACtD,KAAK,EAAE,MAAA,EAAQ,MAAM,QAAA,EAAU,QAAA,EAAU,QAAQ,IAAA,EAAK;AAAA,EACtD,KAAK,EAAE,MAAA,EAAQ,WAAM,QAAA,EAAU,QAAA,EAAU,QAAQ,IAAA;AACnD","file":"chunk-OT6OJY7C.cjs","sourcesContent":["/**\n * Currency symbol/word → ISO 4217 code aliases, and the reverse table used\n * for display formatting (see `format/FormatEngine.ts`'s `formatUom()`).\n *\n * Single source of truth for BOTH directions so the same ambiguity\n * decisions (documented inline below) aren't made twice, inconsistently,\n * in two different files.\n */\n\n/**\n * Currency SYMBOLS (non-alphanumeric characters), safe to recognize as\n * bare lexer tokens with zero risk of colliding with a variable name,\n * since `:name = expr` variable names can never be symbol characters.\n * `CurrencySymbolParselet.ts` consumes these directly.\n *\n * `¥`/`₱`/`peso` ambiguity note: the PESO SIGN (₱) is, per Unicode, the\n * Philippine peso specifically, but the WORD \"peso\" (see\n * `CURRENCY_WORD_ALIASES` below) defaults to the Mexican peso, the most\n * globally recognized \"peso\" in English financial writing. This is a\n * deliberate inconsistency between the symbol and the word for the same\n * general concept, same reasoning as `¥` (JPY) vs \"yuan\" (CNY) below\n * document rather than silently guess, and a user wanting the other one\n * can always type the ISO code directly (\"PHP\"/\"CNY\").\n */\nexport const CURRENCY_SYMBOL_ALIASES: Record<string, string> = {\n \"$\": \"USD\",\n \"£\": \"GBP\",\n \"€\": \"EUR\",\n // ¥ is genuinely ambiguous between JPY and CNY in real-world usage, JPY\n // is the conventional default (matches Numi/most calculator apps' own\n // choice); a user wanting CNY specifically can still type \"CNY\" directly.\n \"¥\": \"JPY\",\n \"₽\": \"RUB\",\n \"₩\": \"KRW\",\n \"₹\": \"INR\",\n \"₺\": \"TRY\",\n \"₴\": \"UAH\",\n \"₪\": \"ILS\",\n \"₫\": \"VND\",\n \"₦\": \"NGN\",\n \"₱\": \"PHP\",\n};\n\n/**\n * Currency WORD forms (singular/plural, all lowercase. This codebase's\n * unit table is strictly case-sensitive with no aliasing, so \"Euro\"/\"EURO\"\n * are deliberately NOT recognized, matching every other word-unit here).\n * Registered as `UNIT` tokens (see `lexer/units.ts`) rather than bare\n * keywords: a bare keyword can never be a `:variableName` (this codebase's\n * tested, intentional policy. See `VariableParselet.ts`'s doc comment)\n * but `:dollar = 5` etc. must keep working, and UNIT-typed tokens ARE\n * accepted as variable names (e.g. \":b = 5\" already works for the \"b\" bits\n * unit), so these ride the same safe mechanism `workday`/`workdays` used.\n *\n * Deliberately NOT included: \"pound\"/\"pounds\", already a MASS unit in\n * `lexer/units.ts` (450g, matching \"lb\"). Remapping it to GBP would be a\n * real, silent regression for anyone using \"5 pounds\" to mean weight; GBP\n * stays reachable via the £ symbol or the \"GBP\" code, same as before.\n *\n * Deliberately NOT included: \"dinar\", used by ~10 countries (Kuwaiti\n * Bahraini, Jordanian, Iraqi, Algerian, ... dinars) with wildly different\n * values (a Kuwaiti dinar is worth roughly 1000x an Algerian one), no\n * single default is defensible the way ¥→JPY or peso→MXN are. Type the\n * ISO code directly (KWD/BHD/JOD/...).\n *\n * Ambiguous-but-resolved cases, and why:\n * - \"peso\"/\"pesos\" → MXN (Mexican peso is the most globally recognized\n * \"peso\" in English financial writing). See the ₱ symbol note above\n * for why this deliberately differs from the ₱ SYMBOL's PHP mapping.\n * - \"franc\"/\"francs\" → CHF (Swiss franc; also used by several African\n * currencies, CHF is the overwhelmingly dominant \"franc\" in English use).\n * - \"krona\"/\"kronor\" → SEK (Swedish); \"krone\"/\"kroner\" → NOK (Norwegian)\n * Danish also uses \"krone\" (DKK) with the identical spelling as\n * Norwegian; NOK was picked arbitrarily as the more commonly-referenced\n * of the two in English text. Type \"DKK\" directly for Danish krone.\n * - \"riyal\"/\"riyals\"/\"rial\"/\"rials\" → SAR (Saudi riyal), both spellings\n * also refer to Qatari/Omani riyals and the Iranian rial; SAR is the\n * most commonly referenced in English. Type \"QAR\"/\"OMR\"/\"IRR\" directly\n * for the others.\n */\nexport const CURRENCY_WORD_ALIASES: Record<string, string> = {\n dollar: \"USD\", dollars: \"USD\",\n euro: \"EUR\", euros: \"EUR\",\n yen: \"JPY\",\n ruble: \"RUB\", rubles: \"RUB\", rouble: \"RUB\", roubles: \"RUB\",\n won: \"KRW\",\n rupee: \"INR\", rupees: \"INR\",\n yuan: \"CNY\", renminbi: \"CNY\",\n franc: \"CHF\", francs: \"CHF\",\n rand: \"ZAR\",\n krona: \"SEK\", kronor: \"SEK\",\n krone: \"NOK\", kroner: \"NOK\",\n real: \"BRL\", reais: \"BRL\",\n peso: \"MXN\", pesos: \"MXN\",\n shekel: \"ILS\", shekels: \"ILS\",\n lira: \"TRY\",\n hryvnia: \"UAH\", hryvnias: \"UAH\",\n zloty: \"PLN\", zlotys: \"PLN\",\n forint: \"HUF\",\n koruna: \"CZK\",\n dirham: \"AED\", dirhams: \"AED\",\n riyal: \"SAR\", riyals: \"SAR\", rial: \"SAR\", rials: \"SAR\",\n ringgit: \"MYR\",\n rupiah: \"IDR\",\n baht: \"THB\",\n dong: \"VND\",\n naira: \"NGN\",\n};\n\n/**\n * Resolve a raw lexed unit/symbol string to its canonical ISO 4217 code\n * e.g. `\"euro\"` -> `\"EUR\"`, `\"$\"` -> `\"USD\"`, `\"USD\"` -> `\"USD\"` (already\n * canonical, returned unchanged). Returns `undefined` if `text` isn't a\n * recognized currency alias at all (distinct from \"already canonical\"\n * callers should fall back to the original text in that case).\n */\nexport function resolveCurrencyAlias(text: string): string | undefined {\n return CURRENCY_SYMBOL_ALIASES[text] ?? CURRENCY_WORD_ALIASES[text.toLowerCase()];\n}\n\n/** How a currency's amount and symbol are conventionally arranged for display. */\nexport interface CurrencyDisplayInfo {\n /** The symbol/abbreviation to render, e.g. \"$\", \"kr\", \"R$\". */\n readonly symbol: string;\n /** Whether the symbol comes before or after the formatted amount. */\n readonly position: \"prefix\" | \"suffix\";\n /** Whether a space separates the symbol from the amount. */\n readonly spaced: boolean;\n}\n\n/**\n * Display convention per ISO code, for currencies with a widely-recognized\n * symbol/abbreviation and an unambiguous placement convention. NOT\n * exhaustive, any code absent here (most of the ~150 codes\n * `CurrencyExchange.isCurrency()` recognizes) falls back to the existing\n * \"amount CODE\" format (e.g. \"100.00 AED\") in `FormatEngine.formatUom()`,\n * exactly as before this table existed. Extend as needed, same pattern as\n * this session's other \"not exhaustive, additive\" tables (city timezones,\n * ingredient densities).\n *\n * Several currencies share the same symbol (USD/AUD/CAD/NZD/HKD/SGD/MXN\n * all conventionally use \"$\" locally). This is safe here because OUTPUT\n * formatting always starts from an already-resolved, unambiguous ISO code\n * (`value.unit`), unlike INPUT parsing where a bare \"$\" genuinely is\n * ambiguous (see `CURRENCY_SYMBOL_ALIASES`'s USD default above).\n */\nexport const CURRENCY_DISPLAY: Record<string, CurrencyDisplayInfo> = {\n USD: { symbol: \"$\", position: \"prefix\", spaced: false },\n AUD: { symbol: \"$\", position: \"prefix\", spaced: false },\n CAD: { symbol: \"$\", position: \"prefix\", spaced: false },\n NZD: { symbol: \"$\", position: \"prefix\", spaced: false },\n HKD: { symbol: \"$\", position: \"prefix\", spaced: false },\n SGD: { symbol: \"$\", position: \"prefix\", spaced: false },\n MXN: { symbol: \"$\", position: \"prefix\", spaced: false },\n GBP: { symbol: \"£\", position: \"prefix\", spaced: false },\n // English-language convention (€100.00), many EU locales instead suffix\n // with a space (\"100,00 €\"); this engine's default locale is \"en\", so\n // the English convention was chosen. A locale-aware override would be a\n // reasonable future extension, not attempted here.\n EUR: { symbol: \"€\", position: \"prefix\", spaced: false },\n JPY: { symbol: \"¥\", position: \"prefix\", spaced: false },\n CNY: { symbol: \"¥\", position: \"prefix\", spaced: false },\n KRW: { symbol: \"₩\", position: \"prefix\", spaced: false },\n INR: { symbol: \"₹\", position: \"prefix\", spaced: false },\n // Russian convention places the ruble sign AFTER the amount, with a space.\n RUB: { symbol: \"₽\", position: \"suffix\", spaced: true },\n TRY: { symbol: \"₺\", position: \"prefix\", spaced: false },\n UAH: { symbol: \"₴\", position: \"suffix\", spaced: true },\n ILS: { symbol: \"₪\", position: \"prefix\", spaced: false },\n // Vietnamese convention: no space, symbol after the amount.\n VND: { symbol: \"₫\", position: \"suffix\", spaced: false },\n NGN: { symbol: \"₦\", position: \"prefix\", spaced: false },\n PHP: { symbol: \"₱\", position: \"prefix\", spaced: false },\n BRL: { symbol: \"R$\", position: \"prefix\", spaced: false },\n ZAR: { symbol: \"R\", position: \"prefix\", spaced: false },\n // Scandinavian convention: amount then \"kr\", space-separated.\n SEK: { symbol: \"kr\", position: \"suffix\", spaced: true },\n NOK: { symbol: \"kr\", position: \"suffix\", spaced: true },\n DKK: { symbol: \"kr\", position: \"suffix\", spaced: true },\n PLN: { symbol: \"zł\", position: \"suffix\", spaced: true },\n CHF: { symbol: \"Fr\", position: \"suffix\", spaced: true },\n HUF: { symbol: \"Ft\", position: \"suffix\", spaced: true },\n CZK: { symbol: \"Kč\", position: \"suffix\", spaced: true },\n};\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// src/utilities/Strings.ts
|
|
2
|
+
function stripQuotes(value) {
|
|
3
|
+
return value.startsWith('"') && value.endsWith('"') && value.length >= 2 ? value.slice(1, -1) : value;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export { stripQuotes };
|
|
7
|
+
//# sourceMappingURL=chunk-PFSDGGYL.js.map
|
|
8
|
+
//# sourceMappingURL=chunk-PFSDGGYL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utilities/Strings.ts"],"names":[],"mappings":";AAOO,SAAS,YAAY,KAAA,EAAuB;AAClD,EAAA,OAAO,KAAA,CAAM,UAAA,CAAW,GAAG,CAAA,IAAK,MAAM,QAAA,CAAS,GAAG,CAAA,IAAK,KAAA,CAAM,UAAU,CAAA,GACpE,KAAA,CAAM,KAAA,CAAM,CAAA,EAAG,EAAE,CAAA,GACjB,KAAA;AACJ","file":"chunk-PFSDGGYL.js","sourcesContent":["/**\n * Strips a single layer of matching double quotes from a string, if present.\n * Returns the input unchanged if it isn't fully wrapped in quotes.\n *\n * Used for STRING token values, which the lexer emits with their surrounding\n * `\"...\"` quotes still attached.\n */\nexport function stripQuotes(value: string): string {\n\treturn value.startsWith('\"') && value.endsWith('\"') && value.length >= 2\n\t\t? value.slice(1, -1)\n\t\t: value;\n}\n"]}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk53B6KDDJ_cjs = require('./chunk-53B6KDDJ.cjs');
|
|
4
|
+
|
|
5
|
+
// src/uom/UnitConversion.ts
|
|
6
|
+
var UNIT_LOOKUP = new Map(Object.entries(chunk53B6KDDJ_cjs.UNIT_TABLE));
|
|
7
|
+
var DIFFERENCE_LOOKUP = new Map(Object.entries(chunk53B6KDDJ_cjs.UNIT_DIFFERENCES));
|
|
8
|
+
function lookupUnit(unit) {
|
|
9
|
+
return UNIT_LOOKUP.get(unit);
|
|
10
|
+
}
|
|
11
|
+
function convertRaw(quantity, from, to) {
|
|
12
|
+
const parsedFrom = UNIT_LOOKUP.get(from);
|
|
13
|
+
if (parsedFrom === void 0) {
|
|
14
|
+
throw new RangeError(`${from} is not a valid unit`);
|
|
15
|
+
}
|
|
16
|
+
const parsedTo = UNIT_LOOKUP.get(to);
|
|
17
|
+
if (parsedTo === void 0) {
|
|
18
|
+
throw new RangeError(`${to} is not a valid unit`);
|
|
19
|
+
}
|
|
20
|
+
return convertResolved(quantity, from, to, parsedFrom, parsedTo);
|
|
21
|
+
}
|
|
22
|
+
function convertResolved(quantity, from, to, fromEntry, toEntry) {
|
|
23
|
+
const parsedFrom = fromEntry;
|
|
24
|
+
const parsedTo = toEntry;
|
|
25
|
+
if (parsedFrom[0] !== parsedTo[0]) {
|
|
26
|
+
throw new RangeError(`Cannot convert between different measures: ${from} and ${to}`);
|
|
27
|
+
}
|
|
28
|
+
const fromRatio = parsedFrom[1];
|
|
29
|
+
const toRatio = parsedTo[1];
|
|
30
|
+
const fromDifference = DIFFERENCE_LOOKUP.get(from);
|
|
31
|
+
const toDifference = DIFFERENCE_LOOKUP.get(to);
|
|
32
|
+
if (fromDifference !== void 0) {
|
|
33
|
+
if (toDifference !== void 0) {
|
|
34
|
+
return (quantity + fromDifference) * (fromRatio / toRatio) - toDifference;
|
|
35
|
+
}
|
|
36
|
+
return (quantity + fromDifference) * (fromRatio / toRatio);
|
|
37
|
+
}
|
|
38
|
+
if (toDifference !== void 0) {
|
|
39
|
+
return quantity * (fromRatio / toRatio) - toDifference;
|
|
40
|
+
}
|
|
41
|
+
return quantity * (fromRatio / toRatio);
|
|
42
|
+
}
|
|
43
|
+
function convertToBestMetric(quantity, from) {
|
|
44
|
+
const parsedFrom = UNIT_LOOKUP.get(from);
|
|
45
|
+
if (parsedFrom === void 0) {
|
|
46
|
+
throw new RangeError(`${from} is not a valid unit`);
|
|
47
|
+
}
|
|
48
|
+
const best = chunk53B6KDDJ_cjs.BEST_UNITS_METRIC[parsedFrom[0]];
|
|
49
|
+
const smallestUnit = best[0][0];
|
|
50
|
+
let bestUnit = smallestUnit;
|
|
51
|
+
const baseQuantity = convertRaw(quantity, from, smallestUnit);
|
|
52
|
+
const absQuantity = baseQuantity < 0 ? -baseQuantity : baseQuantity;
|
|
53
|
+
for (let i = 0; i < best.length; i++) {
|
|
54
|
+
const bestEntry = best[i];
|
|
55
|
+
if (absQuantity >= bestEntry[1]) {
|
|
56
|
+
bestUnit = bestEntry[0];
|
|
57
|
+
} else {
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return { quantity: convertRaw(quantity, from, bestUnit), unit: bestUnit };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// src/uom/UomConverter.ts
|
|
65
|
+
var WORKDAY_UNIT_NAMES = /* @__PURE__ */ new Set(["workday", "workdays"]);
|
|
66
|
+
var WORKDAY_TO_DAY_FACTOR = 7 / 5;
|
|
67
|
+
function isWorkdayUnit(unit) {
|
|
68
|
+
return typeof unit === "string" && WORKDAY_UNIT_NAMES.has(unit);
|
|
69
|
+
}
|
|
70
|
+
function resolveUnit(unit) {
|
|
71
|
+
return unit;
|
|
72
|
+
}
|
|
73
|
+
function getMeasure(unit) {
|
|
74
|
+
if (isWorkdayUnit(unit)) return getMeasure("day");
|
|
75
|
+
const extended = chunk53B6KDDJ_cjs.EXTENDED_UNITS[unit];
|
|
76
|
+
if (extended) return extended.measure;
|
|
77
|
+
const entry = lookupUnit(unit);
|
|
78
|
+
if (entry === void 0) return void 0;
|
|
79
|
+
return chunk53B6KDDJ_cjs.MEASURE_KIND_NAMES[entry[0]];
|
|
80
|
+
}
|
|
81
|
+
function canConvert(from, to) {
|
|
82
|
+
if (from === to) return true;
|
|
83
|
+
if (isWorkdayUnit(from) || isWorkdayUnit(to)) {
|
|
84
|
+
const fromMeasure = getMeasure(from);
|
|
85
|
+
const toMeasure = getMeasure(to);
|
|
86
|
+
return !!fromMeasure && fromMeasure === toMeasure;
|
|
87
|
+
}
|
|
88
|
+
const fromEntry = lookupUnit(from);
|
|
89
|
+
const toEntry = lookupUnit(to);
|
|
90
|
+
if (fromEntry !== void 0 && toEntry !== void 0) {
|
|
91
|
+
return fromEntry[0] === toEntry[0];
|
|
92
|
+
}
|
|
93
|
+
const fromExtended = chunk53B6KDDJ_cjs.EXTENDED_UNITS[from];
|
|
94
|
+
const toExtended = chunk53B6KDDJ_cjs.EXTENDED_UNITS[to];
|
|
95
|
+
if (fromExtended !== void 0 && toExtended !== void 0) {
|
|
96
|
+
return fromExtended.measure === toExtended.measure;
|
|
97
|
+
}
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
function convertUnit(value, from, to) {
|
|
101
|
+
if (from === to) return value;
|
|
102
|
+
const fromEntry = lookupUnit(from);
|
|
103
|
+
const toEntry = lookupUnit(to);
|
|
104
|
+
if (fromEntry !== void 0 && toEntry !== void 0) {
|
|
105
|
+
return convertResolved(value, from, to, fromEntry, toEntry);
|
|
106
|
+
}
|
|
107
|
+
if (isWorkdayUnit(from) && isWorkdayUnit(to)) return value;
|
|
108
|
+
if (isWorkdayUnit(from)) {
|
|
109
|
+
const days = value * WORKDAY_TO_DAY_FACTOR;
|
|
110
|
+
return to === "day" ? days : convertUnit(days, "day", to);
|
|
111
|
+
}
|
|
112
|
+
if (isWorkdayUnit(to)) {
|
|
113
|
+
const days = from === "day" ? value : convertUnit(value, from, "day");
|
|
114
|
+
return days / WORKDAY_TO_DAY_FACTOR;
|
|
115
|
+
}
|
|
116
|
+
const fExt = chunk53B6KDDJ_cjs.EXTENDED_UNITS[from];
|
|
117
|
+
const tExt = chunk53B6KDDJ_cjs.EXTENDED_UNITS[to];
|
|
118
|
+
if (fExt !== void 0 && tExt !== void 0) {
|
|
119
|
+
return value * (fExt.toBase / tExt.toBase);
|
|
120
|
+
}
|
|
121
|
+
return convertRaw(value, from, to);
|
|
122
|
+
}
|
|
123
|
+
function getConvertiblePossibilities(unit) {
|
|
124
|
+
const resolved = resolveUnit(unit);
|
|
125
|
+
const entry = lookupUnit(resolved);
|
|
126
|
+
if (entry === void 0) return [];
|
|
127
|
+
const symbols = chunk53B6KDDJ_cjs.MEASURE_SYMBOLS[entry[0]];
|
|
128
|
+
if (!symbols) return [];
|
|
129
|
+
return symbols.filter((s) => s !== resolved);
|
|
130
|
+
}
|
|
131
|
+
function isConvertibleUnit(unit) {
|
|
132
|
+
if (isWorkdayUnit(unit)) return true;
|
|
133
|
+
if (chunk53B6KDDJ_cjs.EXTENDED_UNITS[unit]) return true;
|
|
134
|
+
return lookupUnit(resolveUnit(unit)) !== void 0;
|
|
135
|
+
}
|
|
136
|
+
function getBestUnit(value, unit) {
|
|
137
|
+
const u = resolveUnit(unit);
|
|
138
|
+
try {
|
|
139
|
+
const result = convertToBestMetric(value, u);
|
|
140
|
+
return { value: result.quantity, unit: result.unit };
|
|
141
|
+
} catch {
|
|
142
|
+
return { value, unit: u };
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
exports.canConvert = canConvert;
|
|
147
|
+
exports.convertUnit = convertUnit;
|
|
148
|
+
exports.getBestUnit = getBestUnit;
|
|
149
|
+
exports.getConvertiblePossibilities = getConvertiblePossibilities;
|
|
150
|
+
exports.getMeasure = getMeasure;
|
|
151
|
+
exports.isConvertibleUnit = isConvertibleUnit;
|
|
152
|
+
exports.isWorkdayUnit = isWorkdayUnit;
|
|
153
|
+
exports.resolveUnit = resolveUnit;
|
|
154
|
+
//# sourceMappingURL=chunk-QNJ4ACRT.cjs.map
|
|
155
|
+
//# sourceMappingURL=chunk-QNJ4ACRT.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/uom/UnitConversion.ts","../src/uom/UomConverter.ts"],"names":["UNIT_TABLE","UNIT_DIFFERENCES","BEST_UNITS_METRIC","EXTENDED_UNITS","MEASURE_KIND_NAMES","MEASURE_SYMBOLS"],"mappings":";;;;;AAmCA,IAAM,cAA8C,IAAI,GAAA,CAAI,MAAA,CAAO,OAAA,CAAQA,4BAAU,CAAC,CAAA;AAStF,IAAM,oBAAiD,IAAI,GAAA,CAAI,MAAA,CAAO,OAAA,CAAQC,kCAAgB,CAAC,CAAA;AAgBxF,SAAS,WAAW,IAAA,EAAqC;AAC9D,EAAA,OAAO,WAAA,CAAY,IAAI,IAAI,CAAA;AAC7B;AAWO,SAAS,UAAA,CAAW,QAAA,EAAkB,IAAA,EAAc,EAAA,EAAoB;AAC7E,EAAA,MAAM,UAAA,GAAa,WAAA,CAAY,G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ACF","file":"chunk-QNJ4ACRT.cjs","sourcesContent":["/**\n * The unit conversion algorithm, ported from the `convert` npm package v7.0.2\n * alongside its tables (see `generated/UnitTable.generated.ts` and\n * THIRD-PARTY-NOTICES.md).\n *\n * Transliterated expression for expression rather than rewritten. Floating\n * point is not associative, so `(q + d) * (a / b) - d2` and any algebraically\n * equal rearrangement disagree in the last bits. Those bits are observable:\n * `0.5 l` best-converts to `500.00000000000006 mL` today, and the test suite\n * pins several conversions to ten decimal places.\n *\n * This module is deliberately unaware of the engine's own additions. Workdays,\n * extended units, currency and the caches all live in `UomConverter.ts`, which\n * layers them on top of these three functions.\n */\n\nimport {\n UNIT_TABLE,\n UNIT_DIFFERENCES,\n BEST_UNITS_METRIC,\n type UnitEntry,\n} from \"./generated/UnitTable.generated\";\n\n/**\n * The generated tables re-keyed into Maps once at module load.\n *\n * Not a micro-optimization. A 1456-key object literal lands in V8's dictionary\n * mode, and guarding a read on it against inherited names (`constructor`,\n * `toString`) costs about 123ns per call with either `hasOwnProperty.call` or\n * `Object.hasOwn`, measured. `Map.get` is about 6ns and needs no guard at all,\n * because a Map has no prototype chain to fall through to. That is a 20x\n * difference on the single hottest operation in the unit system: `convertRaw`\n * performs two of these per call, and `LanguageService` sweeps all 1456 keys\n * to build completions.\n */\nconst UNIT_LOOKUP: ReadonlyMap<string, UnitEntry> = new Map(Object.entries(UNIT_TABLE));\n\n/**\n * Temperature offsets, as a Map for the same reason.\n *\n * Also removes a latent hazard: the upstream code tests membership with `in`,\n * and `\"toString\" in UNIT_DIFFERENCES` is true, so an inherited name reaching\n * that branch would add a function to a number.\n */\nconst DIFFERENCE_LOOKUP: ReadonlyMap<string, number> = new Map(Object.entries(UNIT_DIFFERENCES));\n\n/**\n * Looks up a unit spelling.\n *\n * @returns its `[kind, ratio]` entry, or `undefined` if the spelling is not a\n * unit. Case-sensitive: no normalization or aliasing happens anywhere in this\n * module.\n *\n * The one deliberate deviation from upstream. `convert` tests membership with\n * `in` and reads the property directly, so inherited names like \"constructor\"\n * and \"toString\" reach its measure comparison and fail there with \"Cannot\n * convert between different measures\" instead of \"is not a valid unit\". Both\n * throw a RangeError and both report no measure, so nothing downstream can\n * tell the difference, and naming the real problem is the better message.\n */\nexport function lookupUnit(unit: string): UnitEntry | undefined {\n return UNIT_LOOKUP.get(unit);\n}\n\n/**\n * Converts `quantity` from one unit to another.\n *\n * THROWS a `RangeError` for an unknown unit or a pair in different measures.\n * Callers depend on that: `VM.ts`'s `extractDurationMs()` calls this with an\n * arbitrary unit inside a bare try/catch and treats the throw as \"not a\n * duration, contribute zero\". Returning NaN or the input unchanged instead\n * would turn `<date> + 5 kg` into an Invalid Date rather than a no-op.\n */\nexport function convertRaw(quantity: number, from: string, to: string): number {\n const parsedFrom = UNIT_LOOKUP.get(from);\n if (parsedFrom === undefined) {\n throw new RangeError(`${from} is not a valid unit`);\n }\n\n const parsedTo = UNIT_LOOKUP.get(to);\n if (parsedTo === undefined) {\n throw new RangeError(`${to} is not a valid unit`);\n }\n\n return convertResolved(quantity, from, to, parsedFrom, parsedTo);\n}\n\n/**\n * The conversion arithmetic, for callers that have already looked both units\n * up and want to skip doing it twice.\n *\n * Split out for `UomConverter.convertUnit()`, which has to check whether\n * either side is a workday or an extended unit before it can dispatch, and\n * would otherwise resolve each unit once to decide and again to convert. The\n * entries MUST be the ones this module returned for these exact spellings.\n */\nexport function convertResolved(\n quantity: number,\n from: string,\n to: string,\n fromEntry: UnitEntry,\n toEntry: UnitEntry\n): number {\n const parsedFrom = fromEntry;\n const parsedTo = toEntry;\n\n if (parsedFrom[0] !== parsedTo[0]) {\n // DELIBERATE DEVIATION from the ported original, which silently reinterpreted\n // \"m\" as minutes whenever the other side was a time unit. That is a guess,\n // and this project's stated position is that refusing to guess is the safer\n // default for a tool doing arithmetic on someone's real numbers (see\n // docs/architecture/design-decisions.md). The guess was not harmless: it\n // reached `<date> + <duration>` through VM.ts's extractDurationMs(), where\n // `today + 5 m` silently added five MINUTES for someone who wrote metres.\n //\n // Minutes are spelled \"min\", \"minute\" or \"minutes\", all of which the table\n // has always accepted.\n throw new RangeError(`Cannot convert between different measures: ${from} and ${to}`);\n }\n\n const fromRatio = parsedFrom[1];\n const toRatio = parsedTo[1];\n\n // Only six units in the whole table carry an offset, so the common path is\n // both misses. Reading the Map once per side and reusing the value beats\n // testing membership and then reading it again.\n const fromDifference = DIFFERENCE_LOOKUP.get(from);\n const toDifference = DIFFERENCE_LOOKUP.get(to);\n\n // Scales that do not share an origin (temperature) need the offset applied\n // around the ratio. Do not refactor the four branches into one expression:\n // the grouping is what makes the result bit-identical to the original.\n if (fromDifference !== undefined) {\n if (toDifference !== undefined) {\n return (quantity + fromDifference) * (fromRatio / toRatio) - toDifference;\n }\n return (quantity + fromDifference) * (fromRatio / toRatio);\n }\n\n if (toDifference !== undefined) {\n return quantity * (fromRatio / toRatio) - toDifference;\n }\n\n return quantity * (fromRatio / toRatio);\n}\n\n/**\n * Picks the most readable metric unit for a magnitude and converts to it.\n *\n * Only the metric lists are ported; nothing has ever requested the imperial\n * ones. Note the final conversion goes from the ORIGINAL unit to the chosen\n * one directly rather than via the smallest unit, which is what keeps the\n * result exact.\n */\nexport function convertToBestMetric(\n quantity: number,\n from: string\n): { quantity: number; unit: string } {\n const parsedFrom = UNIT_LOOKUP.get(from);\n if (parsedFrom === undefined) {\n throw new RangeError(`${from} is not a valid unit`);\n }\n\n const best = BEST_UNITS_METRIC[parsedFrom[0]];\n const smallestUnit = best[0][0];\n let bestUnit = smallestUnit;\n\n const baseQuantity = convertRaw(quantity, from, smallestUnit);\n const absQuantity = baseQuantity < 0 ? -baseQuantity : baseQuantity;\n\n // Thresholds are expressed in the smallest unit and ascend, so the last one\n // the magnitude reaches wins. Breaking early rather than scanning the whole\n // list matters for zero and for negatives, which stay on the smallest unit.\n for (let i = 0; i < best.length; i++) {\n const bestEntry = best[i];\n if (absQuantity >= bestEntry[1]) {\n bestUnit = bestEntry[0];\n } else {\n break;\n }\n }\n\n return { quantity: convertRaw(quantity, from, bestUnit), unit: bestUnit };\n}\n","/**\n * UoM Converter, built on the in-house unit tables in `UnitConversion.ts` and\n * `generated/UnitTable.generated.ts` (ported from the `convert` npm package\n * v7.0.2 so the engine ships with no runtime dependencies).\n *\n * Units are strictly case-sensitive and are looked up without aliasing. No unit\n * remapping, what you type is what you get.\n * e.g. 'C' = Celsius, 'c' = cup; 'MB' = megabytes, 'mb' = millibits.\n *\n * This file owns everything the base tables do not: the workday shim, the\n * extended (custom-measure) units, and the two caches.\n */\n\nimport { lookupUnit, convertRaw, convertResolved, convertToBestMetric } from \"@solve-js/uom/UnitConversion\";\nimport { MEASURE_KIND_NAMES, MEASURE_SYMBOLS } from \"@solve-js/uom/generated/UnitTable.generated\";\nimport { EXTENDED_UNITS } from \"@solve-js/uom/ExtendedUnits\";\n\n// ── \"workday\", a synthetic unit with no entry in the base table ───────────\n//\n// A business day (Mon-Fri) backing the datetime package's `<date> + N\n// workdays` arithmetic and `$X/workday` Rate literals\n// (packages/datetime/). NOT a real physical unit, a business day has no\n// fixed duration, since it depends on which calendar dates are weekends\n// so the ported base table has no concept of it and can't be\n// taught one without monkey-patching its internal unit table.\n//\n// For RATE-MATH purposes only (e.g. \"$500/workday x 4 weeks\" needs a\n// workday count to multiply by), a workday is treated as a FIXED 7/5 of a\n// calendar day: 5 workdays span exactly 7 calendar days in a whole week,\n// so this ratio is exact for whole-week spans and a reasonable linear\n// approximation otherwise. This is deliberately NOT the same\n// calendar-aware, weekend-skipping logic real \"<date> + N workdays\" date\n// arithmetic needs (see vm/VM.ts's addBusinessDays()), that can't be\n// reduced to a fixed ratio, since the exact skip pattern depends on which\n// day of the week the calculation actually starts from.\n//\n// Handled here as a thin pre/post layer in front of the normal\n// base-table path (rather than inside the tables themselves) so every\n// caller of getMeasure()/convertUnit()/canConvert() automatically gets\n// workday support for free.\nconst WORKDAY_UNIT_NAMES = new Set([\"workday\", \"workdays\"]);\nconst WORKDAY_TO_DAY_FACTOR = 7 / 5; // 1 workday == 1.4 calendar days\n\n/** Whether `unit` is the synthetic \"workday\" unit (see module note above). */\nexport function isWorkdayUnit(unit: string | undefined): unit is string {\n return typeof unit === \"string\" && WORKDAY_UNIT_NAMES.has(unit);\n}\n\n/**\n * Validate `unit` against the known unit table.\n *\n * @returns `unit` unchanged in all cases. This does NOT normalize casing\n * or aliasing (units are strictly case-sensitive, see the module note\n * above). A unit the table doesn't recognize is still\n * returned as-is (not thrown), so callers must not assume a returned\n * string is actually convertible, check with {@link isConvertibleUnit}\n * or {@link canConvert} first if that matters.\n *\n * Kept as an identity function purely for API compatibility. It used to guard\n * a validity cache, which existed because validating a unit meant a\n * throw/catch round trip through the old dependency. Validation is now a Map\n * lookup, so the cache cost more than it saved: worse, it was capped at 1000\n * entries against a 1456-unit table, so any sweep over the full vocabulary\n * (which is exactly what LanguageService does to build completions) evicted\n * on almost every call. That one change took the full-table sweep from 7.7ms\n * to under 20us.\n */\nexport function resolveUnit(unit: string): string {\n return unit;\n}\n\n// MEASURE_KIND_NAMES now comes from the generated table (it is derived data,\n// so the generator emits it rather than it being retyped here). The reason it\n// is a module-level constant has not changed: getMeasure() runs at least twice\n// per conversion, and this used to be reallocated on every call.\n\n/**\n * Get the measure/dimension kind for `unit` (e.g. `\"length\"`, `\"mass\"`,\n * `\"temperature\"`), used to check whether two units are even in the same\n * dimension before attempting a conversion.\n *\n * @returns `undefined` if `unit` isn't recognized, rather than throwing.\n */\nexport function getMeasure(unit: string): string | undefined {\n // Workday is a Time-measure unit by convention (see isWorkdayUnit's doc\n // comment) and is not in the base table, so resolve its measure via \"day\"\n // instead of attempting the real lookup below.\n if (isWorkdayUnit(unit)) return getMeasure(\"day\");\n\n // Extended (custom) categories the base table has no measure kind for,\n // see ExtendedUnits.ts.\n const extended = EXTENDED_UNITS[unit];\n if (extended) return extended.measure;\n\n const entry = lookupUnit(unit);\n if (entry === undefined) return undefined;\n\n return MEASURE_KIND_NAMES[entry[0]];\n}\n\n/**\n * Check whether `from` can be converted to `to`. Same unit, or same\n * measure kind (length, mass, ...) and the underlying tables accept the pair.\n * Never throws; returns `false` on any failure.\n */\nexport function canConvert(from: string, to: string): boolean {\n if (from === to) return true;\n if (isWorkdayUnit(from) || isWorkdayUnit(to)) {\n const fromMeasure = getMeasure(from);\n const toMeasure = getMeasure(to);\n return !!fromMeasure && fromMeasure === toMeasure;\n }\n // One table read per side, comparing numeric kind ids. The old shape called\n // getMeasure() on each side (two more reads) purely to compare the resulting\n // STRINGS, then did a throwaway conversion to confirm what the kind check had\n // already established.\n const fromEntry = lookupUnit(from);\n const toEntry = lookupUnit(to);\n if (fromEntry !== undefined && toEntry !== undefined) {\n return fromEntry[0] === toEntry[0];\n }\n\n // Extended (custom) categories aren't in the base table at all, so they are\n // compared on their own measure names instead.\n const fromExtended = EXTENDED_UNITS[from];\n const toExtended = EXTENDED_UNITS[to];\n if (fromExtended !== undefined && toExtended !== undefined) {\n return fromExtended.measure === toExtended.measure;\n }\n\n // Mixed: one side is a base unit and the other is extended or unknown. The\n // measure spaces are disjoint by construction, so this can never convert.\n return false;\n}\n\n/**\n * Convert `value` from unit `from` to unit `to`.\n *\n * Does not validate that the conversion is possible, callers should check\n * with {@link canConvert} first if `from`/`to` aren't already known-good.\n *\n * THROWS a RangeError for an unknown unit or a cross-measure pair. `VM.ts`'s\n * `extractDurationMs()` depends on that, see {@link convertRaw}.\n *\n * This used to memoize a per-pair conversion factor in an LFU cache. The cache\n * is gone: computing the factor is now two Map reads, while the cache cost a\n * template-string key allocation on every call plus the LFU's own frequency\n * bookkeeping, so it was slower than the work it avoided. Removing it is\n * bit-exact, not merely close: the cache stored `convertRaw(1, f, t)`, which is\n * exactly `fromRatio / toRatio`, and then multiplied, which is the identical\n * expression `convertRaw(value, f, t)` evaluates. It also deleted the special\n * case that existed only to keep offset-based temperature pairs out of a\n * factor cache.\n */\nexport function convertUnit(value: number, from: string, to: string): number {\n if (from === to) return value;\n\n // Fast path first: two ordinary units, which is nearly every call. Resolving\n // both here and handing the entries to convertResolved() avoids looking them\n // up again inside convertRaw(). Neither workdays nor extended units appear in\n // the base table, so they always fall through to the branches below and this\n // ordering cannot steal a case from them. UnitVocabulary.spec.ts pins that\n // the two vocabularies stay disjoint.\n const fromEntry = lookupUnit(from);\n const toEntry = lookupUnit(to);\n if (fromEntry !== undefined && toEntry !== undefined) {\n return convertResolved(value, from, to, fromEntry, toEntry);\n }\n\n // Workday <-> any other Time-measure unit: pivot through \"day\" using the\n // fixed 7/5 ratio (see isWorkdayUnit's doc comment above).\n if (isWorkdayUnit(from) && isWorkdayUnit(to)) return value; // \"workday\" <-> \"workdays\" alias\n if (isWorkdayUnit(from)) {\n const days = value * WORKDAY_TO_DAY_FACTOR;\n return to === \"day\" ? days : convertUnit(days, \"day\", to);\n }\n if (isWorkdayUnit(to)) {\n const days = from === \"day\" ? value : convertUnit(value, from, \"day\");\n return days / WORKDAY_TO_DAY_FACTOR;\n }\n\n // Extended (custom) categories the base table has no measure kind for\n // (see ExtendedUnits.ts), compute the ratio directly from each unit's\n // factor-to-base value instead of calling convertRaw(), which would throw\n // on an unrecognized unit string. Every extended category is a pure linear\n // ratio scale (no Temperature-style offset), so this is always safe.\n const fExt = EXTENDED_UNITS[from];\n const tExt = EXTENDED_UNITS[to];\n if (fExt !== undefined && tExt !== undefined) {\n return value * (fExt.toBase / tExt.toBase);\n }\n\n // Offsets, cross-measure rejection and the unknown-unit throw all live in\n // convertRaw. Nothing is layered on top here any more.\n return convertRaw(value, from, to);\n}\n\n/**\n * List every unit symbol in the same measure/dimension as `unit` (wiki:\n * Units-Of-Measurement, \"Conversion Possibilities\", `sourceUnit to ?`\n * e.g. `cm to ?\"` → every Length unit). Excludes `unit` itself.\n *\n * Reads MEASURE_SYMBOLS, which is a curated symbols-only vocabulary and\n * deliberately NOT the keys of the unit table filtered by kind. The two\n * differ: Volume's symbols include `c` and `pt` but not `cup`/`cups`, and\n * Time's include `wk` and `mo` but not `week`/`month`. Deriving this list\n * from the unit table instead would roughly quadruple every answer.\n *\n * @returns `[]` if `unit` isn't recognized, rather than throwing.\n */\nexport function getConvertiblePossibilities(unit: string): string[] {\n const resolved = resolveUnit(unit);\n const entry = lookupUnit(resolved);\n if (entry === undefined) return [];\n const symbols = MEASURE_SYMBOLS[entry[0]];\n if (!symbols) return [];\n return symbols.filter((s) => s !== resolved);\n}\n\n/** Check whether `unit` is a unit the conversion tables recognize. Never throws. */\nexport function isConvertibleUnit(unit: string): boolean {\n if (isWorkdayUnit(unit)) return true;\n if (EXTENDED_UNITS[unit]) return true;\n return lookupUnit(resolveUnit(unit)) !== undefined;\n}\n\n/**\n * Convert `value` (in `unit`) to whichever unit of the same measure gives\n * the most human-readable magnitude, e.g. 1500 metres becomes 1.5 km. Falls\n * back to returning `value`/`unit` unchanged if `unit` isn't recognized,\n * which is what every extended unit and workday does.\n *\n * Note the chosen unit is drawn from the best-unit lists, which are not\n * restricted to spellings the lexer accepts: 0.5 l reports \"mL\".\n */\nexport function getBestUnit(value: number, unit: string): { value: number; unit: string } {\n const u = resolveUnit(unit);\n try {\n const result = convertToBestMetric(value, u);\n return { value: result.quantity, unit: result.unit };\n } catch {\n return { value, unit: u };\n }\n}\n"]}
|