@xylabs/decimal-precision 5.0.80 → 5.0.82

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 CHANGED
@@ -36,7 +36,7 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
36
36
  ***
37
37
 
38
38
  ```ts
39
- function fromFixedPoint(value, places): bigint;
39
+ function fromFixedPoint(value, places?): bigint;
40
40
  ```
41
41
 
42
42
  ## Parameters
@@ -45,7 +45,7 @@ function fromFixedPoint(value, places): bigint;
45
45
 
46
46
  `bigint`
47
47
 
48
- ### places
48
+ ### places?
49
49
 
50
50
  `number` = `18`
51
51
 
@@ -84,7 +84,7 @@ function toDecimalPrecision(value, digits): string;
84
84
  ***
85
85
 
86
86
  ```ts
87
- function toFixedPoint(value, places): bigint;
87
+ function toFixedPoint(value, places?): bigint;
88
88
  ```
89
89
 
90
90
  ## Parameters
@@ -93,7 +93,7 @@ function toFixedPoint(value, places): bigint;
93
93
 
94
94
  `string` | `bigint`
95
95
 
96
- ### places
96
+ ### places?
97
97
 
98
98
  `number` = `18`
99
99
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xylabs/decimal-precision",
3
- "version": "5.0.80",
3
+ "version": "5.0.82",
4
4
  "description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
5
5
  "keywords": [
6
6
  "decimal",
@@ -30,24 +30,21 @@
30
30
  "exports": {
31
31
  ".": {
32
32
  "types": "./dist/neutral/index.d.ts",
33
- "source": "./src/index.ts",
34
33
  "default": "./dist/neutral/index.mjs"
35
34
  },
36
35
  "./package.json": "./package.json"
37
36
  },
38
37
  "module": "./dist/neutral/index.mjs",
39
- "source": "./src/index.ts",
40
38
  "types": "./dist/neutral/index.d.ts",
41
39
  "files": [
42
40
  "dist",
43
- "src",
44
41
  "!**/*.bench.*",
45
42
  "!**/*.spec.*",
46
43
  "!**/*.test.*"
47
44
  ],
48
45
  "devDependencies": {
49
- "@xylabs/ts-scripts-yarn3": "~7.3.2",
50
- "@xylabs/tsconfig": "~7.3.2",
46
+ "@xylabs/ts-scripts-yarn3": "~7.4.11",
47
+ "@xylabs/tsconfig": "~7.4.11",
51
48
  "typescript": "~5.9.3",
52
49
  "vitest": "~4.0.18"
53
50
  },
@@ -1,4 +0,0 @@
1
- export const fromFixedPoint = (value: bigint, places = 18): bigint => {
2
- if (!Number.isInteger(places)) throw new Error(`places (${places}) must be an Integer`)
3
- return value / (10n ** BigInt(places))
4
- }
package/src/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from './fromFixedPoint.ts'
2
- export * from './toDecimalPrecision.ts'
3
- export * from './toFixedPoint.ts'
@@ -1,8 +0,0 @@
1
- export const toDecimalPrecision = (value: number, digits: number) => {
2
- let fixed = 0
3
- const result = Number.parseFloat(value.toPrecision(digits))
4
- while (Number.parseFloat(result.toFixed(fixed)) !== result && fixed < 20) {
5
- fixed++
6
- }
7
- return result.toFixed(fixed)
8
- }
@@ -1,16 +0,0 @@
1
- export const toFixedPoint = (value: bigint | string, places = 18): bigint => {
2
- if (!Number.isInteger(places)) throw new Error(`places (${places}) must be an Integer`)
3
- if (typeof value === 'string') {
4
- const parts = value.split('.')
5
- if (parts.length > 2) {
6
- throw new Error('Too many decimals in value')
7
- }
8
- if (parts.length === 1) {
9
- return BigInt(value) * (10n ** BigInt(places))
10
- }
11
- const [whole, fraction] = parts
12
- const trimmed = fraction.slice(0, places)
13
- return BigInt(whole + trimmed.padEnd(Number(places), '0'))
14
- }
15
- return value * (10n ** BigInt(places))
16
- }