@xylabs/decimal-precision 5.1.1 → 5.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/neutral/index.mjs
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/fromFixedPoint.ts", "../../src/toDecimalPrecision.ts", "../../src/toFixedPoint.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Converts a fixed-point bigint back to a whole-number bigint by dividing out the decimal places.\n * @param value - The fixed-point bigint value to convert\n * @param places - Number of decimal places (default 18)\n * @returns The whole-number bigint result\n */\nexport const fromFixedPoint = (value: bigint, places = 18): bigint => {\n if (!Number.isInteger(places)) throw new Error(`places (${places}) must be an Integer`)\n return value / (10n ** BigInt(places))\n}\n", "/**\n * Formats a number to the specified number of significant digits, returning a string with minimal trailing zeros.\n * @param value - The number to format\n * @param digits - The number of significant digits\n * @returns A string representation of the number with the specified precision\n */\nexport const toDecimalPrecision = (value: number, digits: number) => {\n let fixed = 0\n const result = Number.parseFloat(value.toPrecision(digits))\n while (Number.parseFloat(result.toFixed(fixed)) !== result && fixed < 20) {\n fixed++\n }\n return result.toFixed(fixed)\n}\n", "/**\n * Converts a bigint or decimal string to a fixed-point bigint representation.\n * @param value - The value to convert (bigint or string with optional decimal point)\n * @param places - Number of decimal places (default 18)\n * @returns A bigint representing the value scaled by 10^places\n */\nexport const toFixedPoint = (value: bigint | string, places = 18): bigint => {\n if (!Number.isInteger(places)) throw new Error(`places (${places}) must be an Integer`)\n if (typeof value === 'string') {\n const parts = value.split('.')\n if (parts.length > 2) {\n throw new Error('Too many decimals in value')\n }\n if (parts.length === 1) {\n return BigInt(value) * (10n ** BigInt(places))\n }\n const [whole, fraction] = parts\n const trimmed = fraction.slice(0, places)\n return BigInt(whole + trimmed.padEnd(Number(places), '0'))\n }\n return value * (10n ** BigInt(places))\n}\n"],
|
|
5
|
+
"mappings": ";AAMO,IAAM,iBAAiB,CAAC,OAAe,SAAS,OAAe;AACpE,MAAI,CAAC,OAAO,UAAU,MAAM,EAAG,OAAM,IAAI,MAAM,WAAW,MAAM,sBAAsB;AACtF,SAAO,QAAS,OAAO,OAAO,MAAM;AACtC;;;ACHO,IAAM,qBAAqB,CAAC,OAAe,WAAmB;AACnE,MAAI,QAAQ;AACZ,QAAM,SAAS,OAAO,WAAW,MAAM,YAAY,MAAM,CAAC;AAC1D,SAAO,OAAO,WAAW,OAAO,QAAQ,KAAK,CAAC,MAAM,UAAU,QAAQ,IAAI;AACxE;AAAA,EACF;AACA,SAAO,OAAO,QAAQ,KAAK;AAC7B;;;ACPO,IAAM,eAAe,CAAC,OAAwB,SAAS,OAAe;AAC3E,MAAI,CAAC,OAAO,UAAU,MAAM,EAAG,OAAM,IAAI,MAAM,WAAW,MAAM,sBAAsB;AACtF,MAAI,OAAO,UAAU,UAAU;AAC7B,UAAM,QAAQ,MAAM,MAAM,GAAG;AAC7B,QAAI,MAAM,SAAS,GAAG;AACpB,YAAM,IAAI,MAAM,4BAA4B;AAAA,IAC9C;AACA,QAAI,MAAM,WAAW,GAAG;AACtB,aAAO,OAAO,KAAK,IAAK,OAAO,OAAO,MAAM;AAAA,IAC9C;AACA,UAAM,CAAC,OAAO,QAAQ,IAAI;AAC1B,UAAM,UAAU,SAAS,MAAM,GAAG,MAAM;AACxC,WAAO,OAAO,QAAQ,QAAQ,OAAO,OAAO,MAAM,GAAG,GAAG,CAAC;AAAA,EAC3D;AACA,SAAO,QAAS,OAAO,OAAO,MAAM;AACtC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/decimal-precision",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.3",
|
|
4
4
|
"description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"decimal",
|
|
@@ -42,12 +42,12 @@
|
|
|
42
42
|
"README.md"
|
|
43
43
|
],
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@xylabs/toolchain": "~
|
|
46
|
-
"@xylabs/tsconfig": "~
|
|
45
|
+
"@xylabs/toolchain": "~8.0.4",
|
|
46
|
+
"@xylabs/tsconfig": "~8.0.4",
|
|
47
47
|
"eslint": "^10.3.0",
|
|
48
|
-
"typescript": "^
|
|
49
|
-
"vite": "^8.0.
|
|
50
|
-
"vitest": "^4.1.
|
|
48
|
+
"typescript": "^6.0.3",
|
|
49
|
+
"vite": "^8.0.13",
|
|
50
|
+
"vitest": "^4.1.6"
|
|
51
51
|
},
|
|
52
52
|
"engines": {
|
|
53
53
|
"node": ">=18"
|