@xylabs/decimal-precision 7.0.2 → 7.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -4
- package/dist/neutral/index.d.ts +1 -3
- package/dist/neutral/index.d.ts.map +1 -1
- package/dist/neutral/index.mjs +2 -38
- package/dist/neutral/index.mjs.map +3 -3
- package/package.json +19 -9
- package/dist/neutral/fromFixedPoint.d.ts +0 -8
- package/dist/neutral/fromFixedPoint.d.ts.map +0 -1
- package/dist/neutral/toDecimalPrecision.d.ts +0 -8
- package/dist/neutral/toDecimalPrecision.d.ts.map +0 -1
- package/dist/neutral/toFixedPoint.d.ts +0 -8
- package/dist/neutral/toFixedPoint.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
> **Deprecated.** Use [`@ariestools/sdk`](../../ariestools-sdk/README.md) instead. This package is a backward-compatibility re-export shim.
|
|
2
|
+
|
|
1
3
|
[![logo][]](https://xylabs.com)
|
|
2
4
|
|
|
3
5
|
# @xylabs/decimal-precision
|
|
@@ -12,25 +14,25 @@
|
|
|
12
14
|
Using npm:
|
|
13
15
|
|
|
14
16
|
```sh
|
|
15
|
-
npm install
|
|
17
|
+
npm install @xylabs/decimal-precision
|
|
16
18
|
```
|
|
17
19
|
|
|
18
20
|
Using yarn:
|
|
19
21
|
|
|
20
22
|
```sh
|
|
21
|
-
yarn add
|
|
23
|
+
yarn add @xylabs/decimal-precision
|
|
22
24
|
```
|
|
23
25
|
|
|
24
26
|
Using pnpm:
|
|
25
27
|
|
|
26
28
|
```sh
|
|
27
|
-
pnpm add
|
|
29
|
+
pnpm add @xylabs/decimal-precision
|
|
28
30
|
```
|
|
29
31
|
|
|
30
32
|
Using bun:
|
|
31
33
|
|
|
32
34
|
```sh
|
|
33
|
-
bun add
|
|
35
|
+
bun add @xylabs/decimal-precision
|
|
34
36
|
```
|
|
35
37
|
|
|
36
38
|
|
package/dist/neutral/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mCAAmC,CAAA"}
|
package/dist/neutral/index.mjs
CHANGED
|
@@ -1,39 +1,3 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
|
|
3
|
-
if (!Number.isSafeInteger(places)) throw new Error(`places (${places}) must be an Integer`);
|
|
4
|
-
return value / 10n ** BigInt(places);
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
// src/toDecimalPrecision.ts
|
|
8
|
-
var toDecimalPrecision = (value, digits) => {
|
|
9
|
-
let fixed = 0;
|
|
10
|
-
const result = Number(value.toPrecision(digits));
|
|
11
|
-
while (Number(result.toFixed(fixed)) !== result && fixed < 20) {
|
|
12
|
-
fixed++;
|
|
13
|
-
}
|
|
14
|
-
return result.toFixed(fixed);
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
// src/toFixedPoint.ts
|
|
18
|
-
var toFixedPoint = (value, places = 18) => {
|
|
19
|
-
if (!Number.isSafeInteger(places)) throw new Error(`places (${places}) must be an Integer`);
|
|
20
|
-
if (typeof value === "string") {
|
|
21
|
-
const parts = value.split(".");
|
|
22
|
-
if (parts.length > 2) {
|
|
23
|
-
throw new Error("Too many decimals in value");
|
|
24
|
-
}
|
|
25
|
-
if (parts.length === 1) {
|
|
26
|
-
return BigInt(value) * 10n ** BigInt(places);
|
|
27
|
-
}
|
|
28
|
-
const [whole, fraction] = parts;
|
|
29
|
-
const trimmed = fraction.slice(0, places);
|
|
30
|
-
return BigInt(whole + trimmed.padEnd(Number(places), "0"));
|
|
31
|
-
}
|
|
32
|
-
return value * 10n ** BigInt(places);
|
|
33
|
-
};
|
|
34
|
-
export {
|
|
35
|
-
fromFixedPoint,
|
|
36
|
-
toDecimalPrecision,
|
|
37
|
-
toFixedPoint
|
|
38
|
-
};
|
|
1
|
+
// src/index.ts
|
|
2
|
+
export * from "@ariestools/sdk/decimal-precision";
|
|
39
3
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": ";
|
|
3
|
+
"sources": ["../../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["export * from '@ariestools/sdk/decimal-precision'\n"],
|
|
5
|
+
"mappings": ";AAAA,cAAc;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/decimal-precision",
|
|
3
|
-
"version": "7.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "7.0.4",
|
|
4
|
+
"description": "DEPRECATED — use @ariestools/sdk/decimal-precision. Backward-compatibility re-export shim.",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"decimal",
|
|
7
|
-
"precision",
|
|
8
6
|
"xylabs",
|
|
9
7
|
"utility",
|
|
10
8
|
"typescript",
|
|
@@ -41,20 +39,32 @@
|
|
|
41
39
|
"!**/*.test.*",
|
|
42
40
|
"README.md"
|
|
43
41
|
],
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@ariestools/sdk": "~7.0.4"
|
|
44
|
+
},
|
|
44
45
|
"devDependencies": {
|
|
45
|
-
"@
|
|
46
|
-
"@
|
|
46
|
+
"@opentelemetry/api": "^1.9.1",
|
|
47
|
+
"@opentelemetry/sdk-trace-base": "^2.8.0",
|
|
48
|
+
"@xylabs/toolchain": "^8.5.11",
|
|
49
|
+
"@xylabs/tsconfig": "^8.5.11",
|
|
50
|
+
"async-mutex": "^0.5.0",
|
|
47
51
|
"browserslist": "4.28.4",
|
|
48
52
|
"eslint": "^10.6.0",
|
|
49
53
|
"eslint-import-resolver-typescript": "^4.4.5",
|
|
50
54
|
"typescript": "^6.0.3",
|
|
51
|
-
"
|
|
52
|
-
|
|
55
|
+
"zod": "^4.4.3"
|
|
56
|
+
},
|
|
57
|
+
"peerDependencies": {
|
|
58
|
+
"@opentelemetry/api": "^1.9",
|
|
59
|
+
"@opentelemetry/sdk-trace-base": "^2.7",
|
|
60
|
+
"async-mutex": "^0.5",
|
|
61
|
+
"zod": "^4.4"
|
|
53
62
|
},
|
|
54
63
|
"engines": {
|
|
55
64
|
"node": ">=18"
|
|
56
65
|
},
|
|
57
66
|
"publishConfig": {
|
|
58
67
|
"access": "public"
|
|
59
|
-
}
|
|
68
|
+
},
|
|
69
|
+
"deprecated": "Use @ariestools/sdk/decimal-precision instead. @xylabs/decimal-precision is a compatibility shim only and will not receive further updates."
|
|
60
70
|
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Converts a fixed-point bigint back to a whole-number bigint by dividing out the decimal places.
|
|
3
|
-
* @param value - The fixed-point bigint value to convert
|
|
4
|
-
* @param places - Number of decimal places (default 18)
|
|
5
|
-
* @returns The whole-number bigint result
|
|
6
|
-
*/
|
|
7
|
-
export declare const fromFixedPoint: (value: bigint, places?: number) => bigint;
|
|
8
|
-
//# sourceMappingURL=fromFixedPoint.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fromFixedPoint.d.ts","sourceRoot":"","sources":["../../src/fromFixedPoint.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,MAAM,EAAE,eAAW,KAAG,MAG3D,CAAA"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Formats a number to the specified number of significant digits, returning a string with minimal trailing zeros.
|
|
3
|
-
* @param value - The number to format
|
|
4
|
-
* @param digits - The number of significant digits
|
|
5
|
-
* @returns A string representation of the number with the specified precision
|
|
6
|
-
*/
|
|
7
|
-
export declare const toDecimalPrecision: (value: number, digits: number) => string;
|
|
8
|
-
//# sourceMappingURL=toDecimalPrecision.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"toDecimalPrecision.d.ts","sourceRoot":"","sources":["../../src/toDecimalPrecision.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAAI,OAAO,MAAM,EAAE,QAAQ,MAAM,WAO/D,CAAA"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Converts a bigint or decimal string to a fixed-point bigint representation.
|
|
3
|
-
* @param value - The value to convert (bigint or string with optional decimal point)
|
|
4
|
-
* @param places - Number of decimal places (default 18)
|
|
5
|
-
* @returns A bigint representing the value scaled by 10^places
|
|
6
|
-
*/
|
|
7
|
-
export declare const toFixedPoint: (value: bigint | string, places?: number) => bigint;
|
|
8
|
-
//# sourceMappingURL=toFixedPoint.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"toFixedPoint.d.ts","sourceRoot":"","sources":["../../src/toFixedPoint.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GAAI,OAAO,MAAM,GAAG,MAAM,EAAE,eAAW,KAAG,MAelE,CAAA"}
|