Skip to content

Commit

Permalink
Merge pull request #15 from yukinotech/dev
Browse files Browse the repository at this point in the history
v0.0.8 feat(jsbd): support Deciaml params for BigDeciaml
  • Loading branch information
yukinotech authored Feb 14, 2022
2 parents 62f3c3d + aeac6b8 commit 7a6ce72
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jsbd",
"version": "0.0.7",
"version": "0.0.8",
"main": "dist/index.js",
"module": "dist/index.modern.mjs",
"unpkg": "dist/index.umd.js",
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { JSBD } from './jsbd'

export { Decimal } from './decimal'

export default JSBD
3 changes: 3 additions & 0 deletions src/jsbd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ export class JSBD {
* @param intVal default value to init a BigDecimal object
*/
static BigDecimal(intVal: DecimalIntVal) {
if (intVal instanceof Decimal) {
return snDecimal(intVal.mantissa, intVal.exponent)
}
return new Decimal(intVal)
}
// add => a + b
Expand Down
4 changes: 3 additions & 1 deletion src/type.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export type DecimalIntVal = string | number | bigint
import { Decimal } from './decimal'

export type DecimalIntVal = string | number | bigint | Decimal

export type DecimalSign = -1 | 1

Expand Down
7 changes: 7 additions & 0 deletions test/jsbd/bigDecimal.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { JSBD } from '../../src/jsbd'

test('copy Decimal a', () => {
let a = JSBD.BigDecimal('100')
let b = JSBD.BigDecimal(a)
expect(JSBD.equal(a, b)).toBe(true)
})

0 comments on commit 7a6ce72

Please sign in to comment.