solve-engine 2.7.0 → 2.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/dist/{chunk-HF4H7LYA.js → chunk-2V44X7GH.js} +3 -3
- package/dist/{chunk-HF4H7LYA.js.map → chunk-2V44X7GH.js.map} +1 -1
- package/dist/{chunk-5FO4PDIG.js → chunk-3GAWAMT4.js} +2 -2
- package/dist/{chunk-5FO4PDIG.js.map → chunk-3GAWAMT4.js.map} +1 -1
- package/dist/{chunk-32GC2FHC.cjs → chunk-3HYO3QYW.cjs} +2 -2
- package/dist/{chunk-32GC2FHC.cjs.map → chunk-3HYO3QYW.cjs.map} +1 -1
- package/dist/{chunk-2JMFUQZH.js → chunk-44EOEWGP.js} +2 -2
- package/dist/chunk-44EOEWGP.js.map +1 -0
- package/dist/{chunk-CIQOK7Q4.cjs → chunk-6QRHN3I6.cjs} +2 -2
- package/dist/chunk-6QRHN3I6.cjs.map +1 -0
- package/dist/{chunk-IHZBKT7L.cjs → chunk-6TPXH6Y5.cjs} +3 -3
- package/dist/chunk-6TPXH6Y5.cjs.map +1 -0
- package/dist/chunk-BKSKZA4W.cjs +2 -0
- package/dist/chunk-BKSKZA4W.cjs.map +1 -0
- package/dist/{chunk-VAGS5JS7.cjs → chunk-C65UDMWH.cjs} +2 -2
- package/dist/{chunk-VAGS5JS7.cjs.map → chunk-C65UDMWH.cjs.map} +1 -1
- package/dist/{chunk-B7J24Q5T.cjs → chunk-CIENDLKV.cjs} +2 -2
- package/dist/{chunk-B7J24Q5T.cjs.map → chunk-CIENDLKV.cjs.map} +1 -1
- package/dist/chunk-DLAKPF5T.js +2 -0
- package/dist/chunk-DLAKPF5T.js.map +1 -0
- package/dist/chunk-EOMHELRL.js +2 -0
- package/dist/chunk-EOMHELRL.js.map +1 -0
- package/dist/{chunk-AQWNEO7M.cjs → chunk-EURCQMZK.cjs} +2 -2
- package/dist/{chunk-AQWNEO7M.cjs.map → chunk-EURCQMZK.cjs.map} +1 -1
- package/dist/{chunk-KXM7EY27.js → chunk-GAAXTO4K.js} +3 -3
- package/dist/{chunk-KXM7EY27.js.map → chunk-GAAXTO4K.js.map} +1 -1
- package/dist/{chunk-G7TBEQRQ.js → chunk-GMSBBLUQ.js} +2 -2
- package/dist/{chunk-G7TBEQRQ.js.map → chunk-GMSBBLUQ.js.map} +1 -1
- package/dist/chunk-HDVZZ7JN.js +3 -0
- package/dist/chunk-HDVZZ7JN.js.map +1 -0
- package/dist/{chunk-5AMJNF7J.js → chunk-LH7URJZT.js} +3 -3
- package/dist/chunk-LH7URJZT.js.map +1 -0
- package/dist/{chunk-ZRFUD2LX.cjs → chunk-OZ6SKIPD.cjs} +4 -4
- package/dist/{chunk-ZRFUD2LX.cjs.map → chunk-OZ6SKIPD.cjs.map} +1 -1
- package/dist/{chunk-YAHGSBMC.js → chunk-QYO7IEPR.js} +2 -2
- package/dist/{chunk-YAHGSBMC.js.map → chunk-QYO7IEPR.js.map} +1 -1
- package/dist/{chunk-2LFLR3VZ.cjs → chunk-SNVPM27Q.cjs} +2 -2
- package/dist/{chunk-2LFLR3VZ.cjs.map → chunk-SNVPM27Q.cjs.map} +1 -1
- package/dist/{chunk-AR7L5OJ2.js → chunk-T3FBAFRR.js} +2 -2
- package/dist/{chunk-AR7L5OJ2.js.map → chunk-T3FBAFRR.js.map} +1 -1
- package/dist/chunk-TUBLMUTZ.cjs +2 -0
- package/dist/chunk-TUBLMUTZ.cjs.map +1 -0
- package/dist/{chunk-GYX6S6OS.cjs → chunk-U47GA63S.cjs} +3 -3
- package/dist/chunk-U47GA63S.cjs.map +1 -0
- package/dist/{chunk-CVY2A3TP.js → chunk-UKDUFMT5.js} +2 -2
- package/dist/{chunk-CVY2A3TP.js.map → chunk-UKDUFMT5.js.map} +1 -1
- package/dist/chunk-UWAXJX5G.js +2 -0
- package/dist/chunk-UWAXJX5G.js.map +1 -0
- package/dist/chunk-WEAKI5V5.cjs +2 -0
- package/dist/chunk-WEAKI5V5.cjs.map +1 -0
- package/dist/{chunk-NXIMGB4S.cjs → chunk-WYIOXAFW.cjs} +2 -2
- package/dist/{chunk-NXIMGB4S.cjs.map → chunk-WYIOXAFW.cjs.map} +1 -1
- package/dist/{chunk-W7VOTR2J.cjs → chunk-YORX7723.cjs} +3 -3
- package/dist/{chunk-W7VOTR2J.cjs.map → chunk-YORX7723.cjs.map} +1 -1
- package/dist/{chunk-HTJPV42D.js → chunk-YTCTUBR2.js} +2 -2
- package/dist/{chunk-HTJPV42D.js.map → chunk-YTCTUBR2.js.map} +1 -1
- package/dist/constants.cjs +1 -1
- package/dist/constants.js +1 -1
- package/dist/engine.cjs +1 -1
- package/dist/engine.js +1 -1
- package/dist/format.cjs +1 -1
- package/dist/format.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/language.cjs +1 -1
- package/dist/language.js +1 -1
- package/dist/lexer.cjs +1 -1
- package/dist/lexer.js +1 -1
- package/dist/normalizer.cjs +1 -1
- package/dist/normalizer.js +1 -1
- package/dist/packages.cjs +1 -1
- package/dist/packages.d.cts +1 -1
- package/dist/packages.d.ts +1 -1
- package/dist/packages.js +1 -1
- package/dist/testing.cjs +2 -2
- package/dist/testing.js +1 -1
- package/dist/uom.cjs +1 -1
- package/dist/uom.js +1 -1
- package/dist/vm.cjs +1 -1
- package/dist/vm.js +1 -1
- package/dist/worker.cjs +2 -2
- package/dist/worker.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-2JMFUQZH.js.map +0 -1
- package/dist/chunk-5AMJNF7J.js.map +0 -1
- package/dist/chunk-CIQOK7Q4.cjs.map +0 -1
- package/dist/chunk-FWW3M36J.cjs +0 -2
- package/dist/chunk-FWW3M36J.cjs.map +0 -1
- package/dist/chunk-GYX6S6OS.cjs.map +0 -1
- package/dist/chunk-HAEOMJE3.cjs +0 -2
- package/dist/chunk-HAEOMJE3.cjs.map +0 -1
- package/dist/chunk-IANAMBJQ.cjs +0 -2
- package/dist/chunk-IANAMBJQ.cjs.map +0 -1
- package/dist/chunk-IHZBKT7L.cjs.map +0 -1
- package/dist/chunk-N4HJTHZR.js +0 -2
- package/dist/chunk-N4HJTHZR.js.map +0 -1
- package/dist/chunk-P5EMTVMJ.js +0 -3
- package/dist/chunk-P5EMTVMJ.js.map +0 -1
- package/dist/chunk-TRBXW6HW.js +0 -2
- package/dist/chunk-TRBXW6HW.js.map +0 -1
- package/dist/chunk-WGZ3FNHI.js +0 -2
- package/dist/chunk-WGZ3FNHI.js.map +0 -1
package/dist/chunk-TRBXW6HW.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import {a,f}from'./chunk-2JMFUQZH.js';var r=new Map([["in","the IN keyword owns this word (the conversion operator). ConvertParselet and friends special-case the IN token type directly and trust its text as a unit name, so inches still convert"],["dec","already a converter name, as in `255 as dec`"],["M","the millions magnitude suffix, as in `2.5M`. Nautical miles are still spelled `nmi` and `NM`"],["pm","the meridiem marker, as in `4pm`. Picometres lose, and `picometre` still works"],["are","the English verb, against a 100-square-metre unit almost nobody writes"],["ares","the English verb in plural, same reasoning as `are` above"],["turn","ordinary English, against a full-rotation angle unit also spelled in gradians"],["turns","ordinary English in plural, same reasoning as `turn` above"],["grade","ordinary English. The angle unit is also spelled `gon` and `grad`"],["grades","ordinary English in plural, same reasoning as `grade` above"],["point","ordinary English. The typographic point is also reachable as `pica`"],["points","ordinary English in plural, same reasoning as `point` above"],["moment","ordinary English, against an obscure medieval time unit of 90 seconds"],["moments","ordinary English in plural, same reasoning as `moment` above"],["shake","ordinary English, against an obscure physics unit of ten nanoseconds"],["shakes","ordinary English in plural, same reasoning as `shake` above"]]);function s(n){return /^[A-Za-z0-9_]+$/.test(n)}var i=new Set(["m","g","t","s","h","d","l","b","B","C","F","K","W"]);function o(n){return !s(n)||r.has(n)?false:n.length===1?i.has(n):true}var t=["USD","EUR","GBP","JPY","AUD","CAD","CHF","CNY","SEK","NOK","DKK","NZD","KRW","SGD","HKD","TWD","INR","BRL","ZAR","MXN","RUB","TRY","SAR","AED","ILS","PLN","CZK","HUF","THB","IDR","MYR","PHP","CLP","COP","ARS","NGN","EGP","PKR","BDT","VND","KES","XOF","XAF","MAD","QAR","KWD","OMR","BHD","JOD","LKR","MMK","UZS","KZT","RON","BGN","HRK","ISK","UAH","GEL","AZN","BTN","BND","BOB","BWP","BYN","BZD","CDF","CRC","CUP","DOP","DZD","ERN","ETB","FJD","FKP","GMD","GNF","GYD","HNL","HTG","JMD","KGZ","KHR","KMF","KYD","LAK","LBP","LRD","LSL","LYD","MDL","MGA","MKD","MNT","MOP","MRU","MUR","MVR","MWK","MZN","NAD","NIO","NPR","PGK","PYG","RSD","RWF","SBD","SCR","SDG","SHP","SLE","SOS","SRD","SSP","STN","SVC","SYP","SZL","TJS","TMT","TND","TOP","TTD","TZS","UGX","UYU","VEB","VUV","WST","XCD","XDR","XPF","YER","ZMW","ZWL","BTC","ETH","SOL","XRP","ADA","DOGE","DOT"],l=["dollar","dollars","euro","euros","yen","ruble","rubles","rouble","roubles","won","rupee","rupees","yuan","renminbi","franc","francs","rand","krona","kronor","krone","kroner","real","reais","peso","pesos","shekel","shekels","lira","hryvnia","hryvnias","zloty","zlotys","forint","koruna","dirham","dirhams","riyal","riyals","rial","rials","ringgit","rupiah","baht","dong","naira"],D=["workday","workdays"],d=new Set([...Object.keys(a).filter(o),...Object.keys(f),...D,...t,...l]);function g(n){return d.has(n)}export{d as a,g as b};//# sourceMappingURL=chunk-TRBXW6HW.js.map
|
|
2
|
-
//# sourceMappingURL=chunk-TRBXW6HW.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/lexer/units.ts"],"names":["EXCLUDED_UNIT_SPELLINGS","isTokenizableSpelling","spelling","GRANDFATHERED_SINGLE_CHARACTER_UNITS","isAdmissible","CURRENCY_CODES","CURRENCY_WORD_FORMS","WORKDAY_UNITS","knownUnits","UNIT_TABLE","EXTENDED_UNITS","isKnownUnit","text"],"mappings":"sCAm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,MAAO,KAAA,CAAO,KAAA,CAAO,MAAO,KAAA,CACjD,KAAA,CAAO,MAAO,KAAA,CAAO,KAAA,CACrB,MAAO,KAAA,CAAO,KAAA,CAAO,MAAO,KAAA,CAAO,MAAA,CAAQ,KAC7C,CAAA,CAWMC,EAAsB,CAC1B,QAAA,CAAU,UAAW,MAAA,CAAQ,OAAA,CAAS,MACtC,OAAA,CAAS,QAAA,CAAU,QAAA,CAAU,SAAA,CAAW,MACxC,OAAA,CAAS,QAAA,CAAU,OAAQ,UAAA,CAAY,OAAA,CAAS,SAAU,MAAA,CAC1D,OAAA,CAAS,QAAA,CAAU,OAAA,CAAS,SAAU,MAAA,CAAQ,OAAA,CAAS,OAAQ,OAAA,CAC/D,QAAA,CAAU,UAAW,MAAA,CAAQ,SAAA,CAAW,WAAY,OAAA,CAAS,QAAA,CAC7D,SAAU,QAAA,CAAU,QAAA,CAAU,UAAW,OAAA,CAAS,QAAA,CAAU,OAAQ,OAAA,CACpE,SAAA,CAAW,QAAA,CAAU,MAAA,CAAQ,OAAQ,OACvC,CAAA,CAeMC,EAAgB,CAAC,SAAA,CAAW,UAAU,CAAA,CAe/BC,CAAAA,CAAkC,IAAI,GAAA,CAAI,CACrD,GAAG,MAAA,CAAO,KAAKC,CAAU,CAAA,CAAE,OAAOL,CAAY,CAAA,CAC9C,GAAG,MAAA,CAAO,KAAKM,CAAc,CAAA,CAC7B,GAAGH,CAAAA,CACH,GAAGF,EACH,GAAGC,CACL,CAAC,EAMM,SAASK,EAAYC,CAAAA,CAAuB,CACjD,OAAOJ,CAAAA,CAAW,GAAA,CAAII,CAAI,CAC5B","file":"chunk-TRBXW6HW.js","sourcesContent":["/**\n * The set of unit identifiers the lexer will turn into a UNIT token.\n *\n * DERIVED, not hand-listed. This used to be a hand-maintained list of about a\n * hundred spellings, which existed only because the conversion tables lived\n * inside a third-party package and could not be enumerated. Every spelling had\n * to be transcribed by hand and kept in sync, and this file's own history\n * records the consequences: the IEC binary prefixes (`GiB`, `TiB`) were absent\n * for a long time, and the note explaining the fix said it was \"purely a lexer\n * allowlist gap, not a conversion-logic one\".\n *\n * The tables are now in-repo (see `uom/generated/UnitTable.generated.ts`), so\n * the allowlist is computed from them. Roughly 975 base spellings are\n * recognized instead of about 101, which is why `1 kilojoule to Wh`,\n * `5 arcminutes to deg` and `2 fortnights in days` work at all.\n *\n * Units are case-sensitive to eliminate ambiguity (`C` is Celsius and `c` is a\n * cup, `B` is bytes and `b` is bits). Nothing here normalizes or aliases.\n */\n\nimport { UNIT_TABLE } from \"@solve-js/uom/generated/UnitTable.generated\";\nimport { EXTENDED_UNITS } from \"@solve-js/uom/ExtendedUnits\";\n\n/**\n * Spellings the conversion tables accept but the lexer must not claim, each\n * with its reason. `UnitVocabulary.spec.ts` asserts every one of these still\n * fails to lex, so nobody can quietly delete an entry.\n *\n * Only three spellings in the whole table collide with an existing language\n * keyword (`in`, `min`, `dec`), and `min` is left alone because it has always\n * been a time unit here and works. The rest of this list is about ordinary\n * English: a unit spelling that is also a common word turns prose into\n * arithmetic. `shouldEvaluateLine`'s prose gate is a backstop, not a licence\n * to claim every word in the dictionary.\n */\nconst EXCLUDED_UNIT_SPELLINGS: ReadonlyMap<string, string> = new Map([\n [\"in\", \"the IN keyword owns this word (the conversion operator). ConvertParselet and friends special-case the IN token type directly and trust its text as a unit name, so inches still convert\"],\n [\"dec\", \"already a converter name, as in `255 as dec`\"],\n [\"M\", \"the millions magnitude suffix, as in `2.5M`. Nautical miles are still spelled `nmi` and `NM`\"],\n // Claimed by a normalizer rule rather than by the keyword table, which is why\n // scanning the locale keywords alone does not find it. Admitting `pm`\n // (picometre) broke every clock time in the suite: `4pm` lexed as 4\n // picometres. There is deliberately no entry for `am`: the table's SI\n // prefixes stop at femto, so attometres do not exist and an exclusion would\n // be dead weight. `UnitVocabularyCollisions.spec.ts` asserts that.\n [\"pm\", \"the meridiem marker, as in `4pm`. Picometres lose, and `picometre` still works\"],\n [\"are\", \"the English verb, against a 100-square-metre unit almost nobody writes\"],\n [\"ares\", \"the English verb in plural, same reasoning as `are` above\"],\n [\"turn\", \"ordinary English, against a full-rotation angle unit also spelled in gradians\"],\n [\"turns\", \"ordinary English in plural, same reasoning as `turn` above\"],\n [\"grade\", \"ordinary English. The angle unit is also spelled `gon` and `grad`\"],\n [\"grades\", \"ordinary English in plural, same reasoning as `grade` above\"],\n [\"point\", \"ordinary English. The typographic point is also reachable as `pica`\"],\n [\"points\", \"ordinary English in plural, same reasoning as `point` above\"],\n [\"moment\", \"ordinary English, against an obscure medieval time unit of 90 seconds\"],\n [\"moments\", \"ordinary English in plural, same reasoning as `moment` above\"],\n [\"shake\", \"ordinary English, against an obscure physics unit of ten nanoseconds\"],\n [\"shakes\", \"ordinary English in plural, same reasoning as `shake` above\"],\n]);\n\n/**\n * Whether a spelling can be a single UNIT token at all.\n *\n * The lexer reads a unit as one run of `[A-Za-z0-9_]`, so the 465 spellings\n * containing a space, a slash, a prime or a non-ASCII character cannot be\n * tokenized however well the converter understands them. `square metres`,\n * `cd/m2` and `µm²` all remain reachable through the conversion API (notably\n * the cooking package's free-text target unit), just not by typing them in an\n * expression.\n */\nfunction isTokenizableSpelling(spelling: string): boolean {\n return /^[A-Za-z0-9_]+$/.test(spelling);\n}\n\n/**\n * The single-character units that were already claimed before the vocabulary\n * was derived from the tables, and are therefore grandfathered in.\n *\n * No OTHER single character is admitted. A one-letter unit is indistinguishable\n * from the placeholder names people actually write (`x`, `y`, `n`), and the\n * table has ten more of them: `r a y c p S L N J R`. Admitting those turned\n * `x.y` into a unit expression and broke comparison-operator tests that had\n * deliberately picked letters which were not units. The upside was a handful of\n * spellings that all have an unambiguous longer form (`rad`, `year`, `cup`).\n */\nconst GRANDFATHERED_SINGLE_CHARACTER_UNITS = new Set([\n \"m\", \"g\", \"t\", \"s\", \"h\", \"d\", \"l\", \"b\", \"B\", \"C\", \"F\", \"K\", \"W\",\n]);\n\n/** Whether a base-table spelling should become a lexer token. */\nfunction isAdmissible(spelling: string): boolean {\n if (!isTokenizableSpelling(spelling)) return false;\n if (EXCLUDED_UNIT_SPELLINGS.has(spelling)) return false;\n if (spelling.length === 1) return GRANDFATHERED_SINGLE_CHARACTER_UNITS.has(spelling);\n return true;\n}\n\n/**\n * ISO 4217 codes and the crypto tickers handled alongside them.\n *\n * Hand-maintained on purpose: these are NOT units. They route through\n * CurrencyExchangeService, and `getMeasure()` deliberately returns undefined\n * for every one of them, which is how `VM.ts` tells a currency from a unit.\n * Must stay in sync with CurrencyExchangeService's `isCurrency()`: without a\n * lexer entry a code never becomes a UNIT token, so `1 BTC to USD` used to\n * fail at tokenization with \"Undefined variable: BTC\" before ever reaching\n * the currency service that could have handled it.\n */\nconst CURRENCY_CODES = [\n \"USD\", \"EUR\", \"GBP\", \"JPY\",\n \"AUD\", \"CAD\", \"CHF\", \"CNY\", \"SEK\", \"NOK\", \"DKK\", \"NZD\",\n \"KRW\", \"SGD\", \"HKD\", \"TWD\", \"INR\", \"BRL\", \"ZAR\", \"MXN\",\n \"RUB\", \"TRY\", \"SAR\", \"AED\", \"ILS\", \"PLN\", \"CZK\", \"HUF\",\n \"THB\", \"IDR\", \"MYR\", \"PHP\", \"CLP\", \"COP\", \"ARS\", \"NGN\",\n \"EGP\", \"PKR\", \"BDT\", \"VND\", \"KES\", \"XOF\", \"XAF\", \"MAD\",\n \"QAR\", \"KWD\", \"OMR\", \"BHD\", \"JOD\", \"LKR\", \"MMK\", \"UZS\",\n \"KZT\", \"RON\", \"BGN\", \"HRK\", \"ISK\", \"UAH\", \"GEL\", \"AZN\",\n \"BTN\", \"BND\", \"BOB\", \"BWP\", \"BYN\", \"BZD\", \"CDF\", \"CRC\",\n \"CUP\", \"DOP\", \"DZD\", \"ERN\", \"ETB\", \"FJD\", \"FKP\", \"GMD\",\n \"GNF\", \"GYD\", \"HNL\", \"HTG\", \"JMD\", \"KGZ\", \"KHR\", \"KMF\",\n \"KYD\", \"LAK\", \"LBP\", \"LRD\", \"LSL\", \"LYD\", \"MDL\", \"MGA\",\n \"MKD\", \"MNT\", \"MOP\", \"MRU\", \"MUR\", \"MVR\", \"MWK\", \"MZN\",\n \"NAD\", \"NIO\", \"NPR\", \"PGK\", \"PYG\", \"RSD\", \"RWF\", \"SBD\",\n \"SCR\", \"SDG\", \"SHP\", \"SLE\", \"SOS\", \"SRD\", \"SSP\", \"STN\",\n \"SVC\", \"SYP\", \"SZL\", \"TJS\", \"TMT\", \"TND\", \"TOP\", \"TTD\",\n \"TZS\", \"UGX\", \"UYU\", \"VEB\", \"VUV\", \"WST\", \"XCD\", \"XDR\",\n \"XPF\", \"YER\", \"ZMW\", \"ZWL\",\n \"BTC\", \"ETH\", \"SOL\", \"XRP\", \"ADA\", \"DOGE\", \"DOT\",\n];\n\n/**\n * Currency WORD forms, resolved to their canonical ISO code by\n * `UomLiteralParselet.ts` via `uom/CurrencyAliases.ts`.\n *\n * That table doc-comments every ambiguous choice (peso to MXN, franc to CHF,\n * krona to SEK) and explains why \"pound\"/\"pounds\" is deliberately absent: the\n * mass unit already claims it, and remapping would be exactly the kind of\n * guessing the case-sensitive, no-alias policy exists to prevent.\n */\nconst CURRENCY_WORD_FORMS = [\n \"dollar\", \"dollars\", \"euro\", \"euros\", \"yen\",\n \"ruble\", \"rubles\", \"rouble\", \"roubles\", \"won\",\n \"rupee\", \"rupees\", \"yuan\", \"renminbi\", \"franc\", \"francs\", \"rand\",\n \"krona\", \"kronor\", \"krone\", \"kroner\", \"real\", \"reais\", \"peso\", \"pesos\",\n \"shekel\", \"shekels\", \"lira\", \"hryvnia\", \"hryvnias\", \"zloty\", \"zlotys\",\n \"forint\", \"koruna\", \"dirham\", \"dirhams\", \"riyal\", \"riyals\", \"rial\", \"rials\",\n \"ringgit\", \"rupiah\", \"baht\", \"dong\", \"naira\",\n];\n\n/**\n * \"workday\" and \"workdays\", a business day (Mon-Fri).\n *\n * Backs the datetime package's `<date> + N workdays` arithmetic and\n * `$X/workday` Rate literals. Not a real unit (a business day has no fixed\n * physical duration, it depends on which dates are weekends), so it has no\n * entry in the conversion tables and is shimmed at a fixed 7/5 ratio for rate\n * math only. See `uom/UomConverter.ts`.\n *\n * Safe with respect to variable names: VariableParselet accepts UNIT-typed\n * tokens as names, so `:workday = 5` keeps working, exactly as `:b = 5`\n * already did for the bits unit.\n */\nconst WORKDAY_UNITS = [\"workday\", \"workdays\"];\n\n/**\n * Set of all known unit identifiers (case-sensitive).\n *\n * Base units come from the conversion table; the extended units (speed,\n * voltage, parts-per and the other categories the base table has no measure\n * for) come from ExtendedUnits.ts; currencies and workdays are listed above.\n *\n * Note ExtendedUnits deliberately omits bare `V` (collides with the stocks\n * package's Visa ticker), bare `var` (reads as a variable name) and `fps`\n * (the Time package needs it for frames per second, so speed uses `ft_s`).\n * Those exclusions live there rather than here because they are properties of\n * that table.\n */\nexport const knownUnits: ReadonlySet<string> = new Set([\n ...Object.keys(UNIT_TABLE).filter(isAdmissible),\n ...Object.keys(EXTENDED_UNITS),\n ...WORKDAY_UNITS,\n ...CURRENCY_CODES,\n ...CURRENCY_WORD_FORMS,\n]);\n\n/** The exclusion list, exported so the vocabulary spec can assert each entry. */\nexport const excludedUnitSpellings: ReadonlyMap<string, string> = EXCLUDED_UNIT_SPELLINGS;\n\n/** Units are case-sensitive to eliminate ambiguity (e.g. C=Celsius, c=cup). */\nexport function isKnownUnit(text: string): boolean {\n return knownUnits.has(text);\n}\n"]}
|
package/dist/chunk-WGZ3FNHI.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import {a as a$1,b as b$1,f,e,d,c}from'./chunk-2JMFUQZH.js';var p=new Map(Object.entries(a$1)),_=new Map(Object.entries(b$1));function a(n){return p.get(n)}function b(n,e,t){let r=p.get(e);if(r===void 0)throw new RangeError(`${e} is not a valid unit`);let i=p.get(t);if(i===void 0)throw new RangeError(`${t} is not a valid unit`);return x(n,e,t,r,i)}function x(n,e,t,r,i){let s=r,u=i;if(s[0]!==u[0])throw new RangeError(`Cannot convert between different measures: ${e} and ${t}`);let o=s[1],d=u[1],f=_.get(e),l=_.get(t);return f!==void 0?l!==void 0?(n+f)*(o/d)-l:(n+f)*(o/d):l!==void 0?n*(o/d)-l:n*(o/d)}function B(n,e){let t=p.get(e);if(t===void 0)throw new RangeError(`${e} is not a valid unit`);let r=c[t[0]],i=r[0][0],s=i,u=b(n,e,i),o=u<0?-u:u;for(let d=0;d<r.length;d++){let f=r[d];if(o>=f[1])s=f[0];else break}return {quantity:b(n,e,s),unit:s}}var v=new Set(["workday","workdays"]),F=7/5;function g(n){return typeof n=="string"&&v.has(n)}function k(n){return n}function m(n){if(g(n))return m("day");let e$1=f[n];if(e$1)return e$1.measure;let t=a(n);if(t!==void 0)return e[t[0]]}function K(n,e){if(n===e)return true;if(g(n)||g(e)){let u=m(n),o=m(e);return !!u&&u===o}let t=a(n),r=a(e);if(t!==void 0&&r!==void 0)return t[0]===r[0];let i=f[n],s=f[e];return i!==void 0&&s!==void 0?i.measure===s.measure:y(n,e)||y(e,n)}function y(n,e$1){let t=f[n];if(t===void 0)return false;let r=a(e$1);return r===void 0?false:e[r[0]]===t.measure}function R(n,e,t){if(e===t)return n;let r=a(e),i=a(t);if(r!==void 0&&i!==void 0)return x(n,e,t,r,i);if(g(e)&&g(t))return n;if(g(e)){let o=n*F;return t==="day"?o:R(o,"day",t)}if(g(t))return (e==="day"?n:R(n,e,"day"))/F;let s=f[e],u=f[t];return s!==void 0&&u!==void 0?n*(s.toBase/u.toBase):s!==void 0&&y(e,t)?b(n*s.toBase,N(t),t):u!==void 0&&y(t,e)?b(n,e,N(e))/u.toBase:b(n,e,t)}function N(n){let e=a(n);if(e===void 0)return n;for(let t of Object.keys(a$1)){let r=a$1[t];if(r[0]===e[0]&&r[1]===1)return t}return n}function L(n){let e=n,t=a(e);if(t===void 0)return [];let r=d[t[0]];return r?r.filter(i=>i!==e):[]}function $(n){return g(n)||f[n]?true:a(n)!==void 0}function Y(n,e){let t=e;try{let r=B(n,t);return {value:r.quantity,unit:r.unit}}catch{return {value:n,unit:t}}}function S(n,e){let t=e.indexOf("/");if(t>=0)return {value:n,numerator:e.slice(0,t),denominator:e.slice(t+1)};let r=f[e];return r!==void 0&&r.measure==="speed"?{value:n*r.toBase,numerator:"m",denominator:"s"}:null}function O(n,e){if(n===e)return 1;if(n===""||e==="")return null;let t=m(n),r=m(e);return t===void 0||r===void 0||t!==r?null:R(1,n,e)}function j(n,e,t){let r=S(n,e);if(r===null)return null;let i,s,u,o=t.indexOf("/");if(o>=0)i=t.slice(0,o),s=t.slice(o+1),u=1;else {let l=f[t];if(l===void 0||l.measure!=="speed")return null;i="m",s="s",u=l.toBase;}let d=O(r.numerator,i);if(d===null)return null;let f$1=O(r.denominator,s);return f$1===null?null:r.value*d/f$1/u}export{g as a,k as b,m as c,K as d,R as e,L as f,$ as g,Y as h,j as i};//# sourceMappingURL=chunk-WGZ3FNHI.js.map
|
|
2
|
-
//# sourceMappingURL=chunk-WGZ3FNHI.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/uom/UnitConversion.ts","../src/uom/UomConverter.ts"],"names":["UNIT_LOOKUP","UNIT_TABLE","DIFFERENCE_LOOKUP","UNIT_DIFFERENCES","lookupUnit","unit","convertRaw","quantity","from","to","parsedFrom","parsedTo","convertResolved","fromEntry","toEntry","fromRatio","toRatio","fromDifference","toDifference","convertToBestMetric","best","BEST_UNITS_METRIC","smallestUnit","bestUnit","baseQuantity","absQuantity","i","bestEntry","WORKDAY_UNIT_NAMES","WORKDAY_TO_DAY_FACTOR","isWorkdayUnit","resolveUnit","getMeasure","extended","EXTENDED_UNITS","entry","MEASURE_KIND_NAMES","canConvert","fromMeasure","toMeasure","fromExtended","toExtended","bridgesToBaseMeasure","extendedUnit","baseUnit","base","convertUnit","value","days","fExt","tExt","baseUnitFor","symbol","candidate","getConvertiblePossibilities","resolved","symbols","MEASURE_SYMBOLS","s","isConvertibleUnit","getBestUnit","u","result","expandUnitToRate","slash","ext","rateAxisFactor","convertRate","source","targetN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EAAezB,CAAE,CAAA,CAC7B,GAAIwD,CAAAA,GAAQ,MAAA,EAAaA,CAAAA,CAAI,UAAY,OAAA,CAAS,OAAO,IAAA,CACzDI,CAAAA,CAAkB,GAAA,CAClBC,CAAAA,CAAoB,IACpBC,CAAAA,CAAcN,CAAAA,CAAI,OACpB,CAEA,IAAMO,CAAAA,CAAkBN,EAAeE,CAAAA,CAAO,SAAA,CAAWC,CAAe,CAAA,CACxE,GAAIG,IAAoB,IAAA,CAAM,OAAO,IAAA,CACrC,IAAMC,GAAAA,CAAoBP,CAAAA,CAAeE,EAAO,WAAA,CAAaE,CAAiB,CAAA,CAC9E,OAAIG,GAAAA,GAAsB,IAAA,CAAa,KAE/BL,CAAAA,CAAO,KAAA,CAAQI,CAAAA,CAAmBC,GAAAA,CAAoBF,CAChE","file":"chunk-WGZ3FNHI.js","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, UNIT_TABLE } 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 in the base table and the other is extended. That used\n // to be refused outright, on the grounds that the two measure spaces are\n // disjoint. They are not, once an extended unit names a measure the base\n // table also has: `furlong` is a length and so is `m`, and the ratio between\n // them is exactly what both tables already record.\n return bridgesToBaseMeasure(from, to) || bridgesToBaseMeasure(to, from);\n}\n\n/**\n * Whether `extendedUnit` extends a measure the base table also knows, so a\n * value in it can reach `baseUnit`.\n *\n * The bridge works because both tables express a unit as a ratio to the same\n * physical base: the generated table's length ratios are metres and its mass\n * ratios are grams, and an extended unit declaring `measure: \"length\"` states\n * its `toBase` in the same metres. Composing the two ratios is then ordinary\n * arithmetic rather than a second conversion system.\n *\n * A measure the base table has no concept of, such as pace, still fails here,\n * which is the behaviour this replaced and the reason the check is by measure\n * name rather than by presence in the extended table.\n */\nfunction bridgesToBaseMeasure(extendedUnit: string, baseUnit: string): boolean {\n const extended = EXTENDED_UNITS[extendedUnit];\n if (extended === undefined) return false;\n\n const base = lookupUnit(resolveUnit(baseUnit));\n if (base === undefined) return false;\n\n return MEASURE_KIND_NAMES[base[0]] === extended.measure;\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 // One side extended, the other in the base table, sharing a measure. Convert\n // through the measure's base unit, which both tables state their ratios\n // against: an extended length declares its `toBase` in metres, and the\n // generated table's length ratios are metres too.\n if (fExt !== undefined && bridgesToBaseMeasure(from, to)) {\n return convertRaw(value * fExt.toBase, baseUnitFor(to), to);\n }\n if (tExt !== undefined && bridgesToBaseMeasure(to, from)) {\n return convertRaw(value, from, baseUnitFor(from)) / 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 * The unit a measure states its ratios against, found from any unit in it.\n *\n * Read out of the table rather than hard-coded, so it cannot drift from the\n * ratios it has to agree with: the base is whichever unit of that measure has\n * a ratio of exactly one.\n */\nfunction baseUnitFor(unit: string): string {\n const entry = lookupUnit(resolveUnit(unit));\n if (entry === undefined) return unit;\n\n for (const symbol of Object.keys(UNIT_TABLE)) {\n const candidate = UNIT_TABLE[symbol];\n if (candidate[0] === entry[0] && candidate[1] === 1) return symbol;\n }\n return unit;\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\n// ── Rate and derived-unit conversion ───────────────────────────────────────\n//\n// A rate value carries a compound unit spelled \"numerator/denominator\" (e.g.\n// \"km/h\", \"m/s\"), see vm/Value.ts's rateValue(). Plain convertUnit() cannot\n// touch one, because neither half is the whole unit and getMeasure(\"km/h\") is\n// undefined. This section converts a rate to another rate, and bridges a rate\n// to the single-token speed spellings (mph, kph, mps, ...) that ExtendedUnits.ts\n// already carries, so \"100 km/h in mph\" and \"60 mph in km/h\" resolve instead of\n// reporting incompatible units.\n\n/** A rate reduced to a numerator unit over a denominator unit. */\ninterface RateForm {\n /** Magnitude, scaled so `value numerator/denominator` is the physical quantity. */\n value: number;\n /** Numerator unit spelling, or `\"\"` for a countless rate such as `30/week`. */\n numerator: string;\n /** Denominator unit spelling. */\n denominator: string;\n}\n\n/**\n * Express `value unit` as a numerator/denominator rate, or `null` when `unit`\n * is neither a compound rate spelling nor a single-token speed alias.\n *\n * A speed alias (mph, kph, ...) is one unit standing for a length/time rate, so\n * it expands to the base pair `m`/`s` with its value scaled by the alias's\n * metres-per-second factor. That collapses both inputs to one shape, so a\n * single routine handles rate/rate and rate/alias without a second code path.\n */\nfunction expandUnitToRate(value: number, unit: string): RateForm | null {\n const slash = unit.indexOf(\"/\");\n if (slash >= 0) {\n return { value, numerator: unit.slice(0, slash), denominator: unit.slice(slash + 1) };\n }\n const ext = EXTENDED_UNITS[unit];\n if (ext !== undefined && ext.measure === \"speed\") {\n // 1 alias == ext.toBase m/s, so `value alias` is `value * toBase` m/s.\n return { value: value * ext.toBase, numerator: \"m\", denominator: \"s\" };\n }\n return null;\n}\n\n/**\n * The factor that turns one `from` into `to` along a single rate axis, or\n * `null` when the two cannot line up.\n *\n * Same spelling needs no conversion. A countless axis (`\"\"`) only lines up with\n * another countless one, never with a real unit. Otherwise both sides must name\n * the same measure, which is what keeps a length numerator from pairing with a\n * mass one.\n */\nfunction rateAxisFactor(from: string, to: string): number | null {\n if (from === to) return 1;\n if (from === \"\" || to === \"\") return null;\n const fromMeasure = getMeasure(from);\n const toMeasure = getMeasure(to);\n if (fromMeasure === undefined || toMeasure === undefined || fromMeasure !== toMeasure) {\n return null;\n }\n return convertUnit(1, from, to);\n}\n\n/**\n * Convert `value` from a rate/speed unit `from` to a rate/speed unit `to`,\n * returning the converted magnitude, or `null` when the pair is not\n * rate-convertible (so the caller falls back to its own incompatible-units\n * handling).\n *\n * Handles rate to rate (`10 m/s in km/h`), rate to speed alias\n * (`100 km/h in mph`) and speed alias to rate (`60 mph in km/h`). Plain\n * same-measure pairs (`kph in mph`, `km in miles`) never reach here, they are\n * resolved by {@link convertUnit} first.\n *\n * The rule is the ordinary one for a quotient of quantities: convert the\n * numerator and the denominator each on their own, so `A/B -> C/D` scales by\n * `(A->C) / (B->D)`.\n */\nexport function convertRate(value: number, from: string, to: string): number | null {\n const source = expandUnitToRate(value, from);\n if (source === null) return null;\n\n // The target is either a rate spelling or a single-token speed alias. An\n // alias expands to the base m/s pair, and `targetScale` is what the base-form\n // magnitude is divided by to read out in the alias itself.\n let targetNumerator: string;\n let targetDenominator: string;\n let targetScale: number;\n const slash = to.indexOf(\"/\");\n if (slash >= 0) {\n targetNumerator = to.slice(0, slash);\n targetDenominator = to.slice(slash + 1);\n targetScale = 1;\n } else {\n const ext = EXTENDED_UNITS[to];\n if (ext === undefined || ext.measure !== \"speed\") return null;\n targetNumerator = \"m\";\n targetDenominator = \"s\";\n targetScale = ext.toBase;\n }\n\n const numeratorFactor = rateAxisFactor(source.numerator, targetNumerator);\n if (numeratorFactor === null) return null;\n const denominatorFactor = rateAxisFactor(source.denominator, targetDenominator);\n if (denominatorFactor === null) return null;\n\n return (source.value * numeratorFactor) / denominatorFactor / targetScale;\n}\n"]}
|