Skip to content

Commit 7a6ce72

Browse files
authored
Merge pull request #15 from yukinotech/dev
v0.0.8 feat(jsbd): support Deciaml params for BigDeciaml
2 parents 62f3c3d + aeac6b8 commit 7a6ce72

File tree

5 files changed

+16
-2
lines changed

5 files changed

+16
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jsbd",
3-
"version": "0.0.7",
3+
"version": "0.0.8",
44
"main": "dist/index.js",
55
"module": "dist/index.modern.mjs",
66
"unpkg": "dist/index.umd.js",

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
import { JSBD } from './jsbd'
22

3+
export { Decimal } from './decimal'
4+
35
export default JSBD

src/jsbd.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ export class JSBD {
88
* @param intVal default value to init a BigDecimal object
99
*/
1010
static BigDecimal(intVal: DecimalIntVal) {
11+
if (intVal instanceof Decimal) {
12+
return snDecimal(intVal.mantissa, intVal.exponent)
13+
}
1114
return new Decimal(intVal)
1215
}
1316
// add => a + b

src/type.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
export type DecimalIntVal = string | number | bigint
1+
import { Decimal } from './decimal'
2+
3+
export type DecimalIntVal = string | number | bigint | Decimal
24

35
export type DecimalSign = -1 | 1
46

test/jsbd/bigDecimal.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { JSBD } from '../../src/jsbd'
2+
3+
test('copy Decimal a', () => {
4+
let a = JSBD.BigDecimal('100')
5+
let b = JSBD.BigDecimal(a)
6+
expect(JSBD.equal(a, b)).toBe(true)
7+
})

0 commit comments

Comments
 (0)