@xylabs/decimal-precision 5.0.83 → 5.0.84

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
@@ -39,20 +39,28 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
39
39
  function fromFixedPoint(value, places?): bigint;
40
40
  ```
41
41
 
42
+ Converts a fixed-point bigint back to a whole-number bigint by dividing out the decimal places.
43
+
42
44
  ## Parameters
43
45
 
44
46
  ### value
45
47
 
46
48
  `bigint`
47
49
 
50
+ The fixed-point bigint value to convert
51
+
48
52
  ### places?
49
53
 
50
54
  `number` = `18`
51
55
 
56
+ Number of decimal places (default 18)
57
+
52
58
  ## Returns
53
59
 
54
60
  `bigint`
55
61
 
62
+ The whole-number bigint result
63
+
56
64
  ### <a id="toDecimalPrecision"></a>toDecimalPrecision
57
65
 
58
66
  [**@xylabs/decimal-precision**](#../README)
@@ -63,20 +71,28 @@ function fromFixedPoint(value, places?): bigint;
63
71
  function toDecimalPrecision(value, digits): string;
64
72
  ```
65
73
 
74
+ Formats a number to the specified number of significant digits, returning a string with minimal trailing zeros.
75
+
66
76
  ## Parameters
67
77
 
68
78
  ### value
69
79
 
70
80
  `number`
71
81
 
82
+ The number to format
83
+
72
84
  ### digits
73
85
 
74
86
  `number`
75
87
 
88
+ The number of significant digits
89
+
76
90
  ## Returns
77
91
 
78
92
  `string`
79
93
 
94
+ A string representation of the number with the specified precision
95
+
80
96
  ### <a id="toFixedPoint"></a>toFixedPoint
81
97
 
82
98
  [**@xylabs/decimal-precision**](#../README)
@@ -87,20 +103,28 @@ function toDecimalPrecision(value, digits): string;
87
103
  function toFixedPoint(value, places?): bigint;
88
104
  ```
89
105
 
106
+ Converts a bigint or decimal string to a fixed-point bigint representation.
107
+
90
108
  ## Parameters
91
109
 
92
110
  ### value
93
111
 
112
+ The value to convert (bigint or string with optional decimal point)
113
+
94
114
  `string` | `bigint`
95
115
 
96
116
  ### places?
97
117
 
98
118
  `number` = `18`
99
119
 
120
+ Number of decimal places (default 18)
121
+
100
122
  ## Returns
101
123
 
102
124
  `bigint`
103
125
 
126
+ A bigint representing the value scaled by 10^places
127
+
104
128
 
105
129
  Part of [sdk-js](https://www.npmjs.com/package/@xyo-network/sdk-js)
106
130
 
@@ -1,2 +1,8 @@
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
+ */
1
7
  export declare const fromFixedPoint: (value: bigint, places?: number) => bigint;
2
8
  //# sourceMappingURL=fromFixedPoint.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fromFixedPoint.d.ts","sourceRoot":"","sources":["../../src/fromFixedPoint.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,GAAI,OAAO,MAAM,EAAE,eAAW,KAAG,MAG3D,CAAA"}
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 +1 @@
1
- {"version":3,"sources":["../../src/fromFixedPoint.ts","../../src/toDecimalPrecision.ts","../../src/toFixedPoint.ts"],"sourcesContent":["export 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","export 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","export 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"],"mappings":";AAAO,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;","names":[]}
1
+ {"version":3,"sources":["../../src/fromFixedPoint.ts","../../src/toDecimalPrecision.ts","../../src/toFixedPoint.ts"],"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"],"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;","names":[]}
@@ -1,2 +1,8 @@
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
+ */
1
7
  export declare const toDecimalPrecision: (value: number, digits: number) => string;
2
8
  //# sourceMappingURL=toDecimalPrecision.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"toDecimalPrecision.d.ts","sourceRoot":"","sources":["../../src/toDecimalPrecision.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,GAAI,OAAO,MAAM,EAAE,QAAQ,MAAM,WAO/D,CAAA"}
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,2 +1,8 @@
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
+ */
1
7
  export declare const toFixedPoint: (value: bigint | string, places?: number) => bigint;
2
8
  //# sourceMappingURL=toFixedPoint.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"toFixedPoint.d.ts","sourceRoot":"","sources":["../../src/toFixedPoint.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY,GAAI,OAAO,MAAM,GAAG,MAAM,EAAE,eAAW,KAAG,MAelE,CAAA"}
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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xylabs/decimal-precision",
3
- "version": "5.0.83",
3
+ "version": "5.0.84",
4
4
  "description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
5
5
  "keywords": [
6
6
  "decimal",
@@ -43,8 +43,8 @@
43
43
  "!**/*.test.*"
44
44
  ],
45
45
  "devDependencies": {
46
- "@xylabs/ts-scripts-yarn3": "~7.4.11",
47
- "@xylabs/tsconfig": "~7.4.11",
46
+ "@xylabs/ts-scripts-yarn3": "~7.4.13",
47
+ "@xylabs/tsconfig": "~7.4.13",
48
48
  "typescript": "~5.9.3",
49
49
  "vitest": "~4.0.18"
50
50
  },