cbor-bigdecimal
Advanced tools
Comparing version 9.0.0 to 10.0.2
@@ -1,18 +0,18 @@ | ||
'use strict' | ||
'use strict'; | ||
const {BigNumber} = require('bignumber.js') | ||
let cbor = null | ||
const {BigNumber} = require('bignumber.js'); | ||
let cbor = null; | ||
const MAXINT = new BigNumber('0x20000000000000') | ||
const TWO = new BigNumber(2) | ||
const MAXINT = new BigNumber('0x20000000000000'); | ||
const TWO = new BigNumber(2); | ||
function pushBigNumber(gen, obj) { | ||
if (obj.isNaN()) { | ||
return gen._pushNaN() | ||
return gen._pushNaN(); | ||
} | ||
if (!obj.isFinite()) { | ||
return gen._pushInfinity(obj.isNegative() ? -Infinity : Infinity) | ||
return gen._pushInfinity(obj.isNegative() ? -Infinity : Infinity); | ||
} | ||
if (obj.isInteger()) { | ||
return gen._pushJSBigint(BigInt(obj.toFixed())) | ||
return gen._pushJSBigint(BigInt(obj.toFixed())); | ||
} | ||
@@ -23,14 +23,14 @@ | ||
gen._pushInt(2, 4))) { // Array | ||
return false | ||
return false; | ||
} | ||
const dec = obj.decimalPlaces() | ||
const slide = obj.shiftedBy(dec) | ||
const dec = obj.decimalPlaces(); | ||
const slide = obj.shiftedBy(dec); | ||
if (!gen._pushIntNum(-dec)) { | ||
return false | ||
return false; | ||
} | ||
if (slide.abs().isLessThan(MAXINT)) { | ||
return gen._pushIntNum(slide.toNumber()) | ||
return gen._pushIntNum(slide.toNumber()); | ||
} | ||
return gen._pushJSBigint(BigInt(slide.toFixed())) | ||
return gen._pushJSBigint(BigInt(slide.toFixed())); | ||
} | ||
@@ -40,3 +40,3 @@ | ||
function tag_4(v) { | ||
return new BigNumber(v[1]).shiftedBy(v[0]) | ||
return new BigNumber(v[1]).shiftedBy(v[0]); | ||
} | ||
@@ -46,14 +46,14 @@ | ||
function tag_5(v) { | ||
return TWO.pow(v[0]).times(v[1]) | ||
return TWO.pow(v[0]).times(v[1]); | ||
} | ||
function addBigDecimal(inCBOR) { | ||
cbor = inCBOR | ||
cbor.Encoder.SEMANTIC_TYPES[BigNumber.name] = pushBigNumber | ||
cbor.Tagged.TAGS[4] = tag_4 | ||
cbor.Tagged.TAGS[5] = tag_5 | ||
return cbor | ||
cbor = inCBOR; | ||
cbor.Encoder.SEMANTIC_TYPES[BigNumber.name] = pushBigNumber; | ||
cbor.Tagged.TAGS[4] = tag_4; | ||
cbor.Tagged.TAGS[5] = tag_5; | ||
return cbor; | ||
} | ||
addBigDecimal.BigNumber = BigNumber | ||
module.exports = addBigDecimal | ||
addBigDecimal.BigNumber = BigNumber; | ||
module.exports = addBigDecimal; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("bignumber.js")):"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.cborBigDecimal=t(require("bignumber.js")):e.cborBigDecimal=t(e.BigNumber)}(this,(e=>(()=>{"use strict";var t={143:(e,t,i)=>{const{BigNumber:n}=i(733);let r=null;const u=new n("0x20000000000000"),s=new n(2);function o(e,t){if(t.isNaN())return e._pushNaN();if(!t.isFinite())return e._pushInfinity(t.isNegative()?-1/0:1/0);if(t.isInteger())return e._pushJSBigint(BigInt(t.toFixed()));if(!e._pushTag(4)||!e._pushInt(2,4))return!1;const i=t.decimalPlaces(),n=t.shiftedBy(i);return!!e._pushIntNum(-i)&&(n.abs().isLessThan(u)?e._pushIntNum(n.toNumber()):e._pushJSBigint(BigInt(n.toFixed())))}function p(e){return new n(e[1]).shiftedBy(e[0])}function f(e){return s.pow(e[0]).times(e[1])}function c(e){return r=e,r.Encoder.SEMANTIC_TYPES[n.name]=o,r.Tagged.TAGS[4]=p,r.Tagged.TAGS[5]=f,r}c.BigNumber=n,e.exports=c},733:t=>{t.exports=e}},i={};return function e(n){var r=i[n];if(void 0!==r)return r.exports;var u=i[n]={exports:{}};return t[n](u,u.exports,e),u.exports}(143)})())); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("bignumber.js")):"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.cborBigDecimal=t(require("bignumber.js")):e.cborBigDecimal=t(e.BigNumber)}(this,(e=>(()=>{"use strict";var t={68:(e,t,i)=>{const{BigNumber:n}=i(905);let r=null;const u=new n("0x20000000000000"),s=new n(2);function o(e,t){if(t.isNaN())return e._pushNaN();if(!t.isFinite())return e._pushInfinity(t.isNegative()?-1/0:1/0);if(t.isInteger())return e._pushJSBigint(BigInt(t.toFixed()));if(!e._pushTag(4)||!e._pushInt(2,4))return!1;const i=t.decimalPlaces(),n=t.shiftedBy(i);return!!e._pushIntNum(-i)&&(n.abs().isLessThan(u)?e._pushIntNum(n.toNumber()):e._pushJSBigint(BigInt(n.toFixed())))}function p(e){return new n(e[1]).shiftedBy(e[0])}function f(e){return s.pow(e[0]).times(e[1])}function c(e){return r=e,r.Encoder.SEMANTIC_TYPES[n.name]=o,r.Tagged.TAGS[4]=p,r.Tagged.TAGS[5]=f,r}c.BigNumber=n,e.exports=c},905:t=>{t.exports=e}},i={};return function e(n){var r=i[n];if(void 0!==r)return r.exports;var u=i[n]={exports:{}};return t[n](u,u.exports,e),u.exports}(68)})())); |
{ | ||
"name": "cbor-bigdecimal", | ||
"version": "9.0.0", | ||
"version": "10.0.2", | ||
"description": "Plugin for node-cbor to add BigDecimal and BigFloat support. Requires bignumber.js", | ||
"browser": "dist/cbor-bigdecimal.js", | ||
"main": "./bigdecimal.js", | ||
"scripts": { | ||
"build": "webpack", | ||
"clean": "rimraf dist", | ||
"coverage": "nyc -r lcov npm test", | ||
"test": "ava test/*.ava.js", | ||
"dev": "light-server -q -s. -w 'lib/*.js,test/*.js # npm run coverage' -o /coverage/lcov-report/index.html" | ||
}, | ||
"keywords": [ | ||
@@ -25,3 +18,3 @@ "CBOR", | ||
"type": "git", | ||
"url": "http://github.com/hildjj/node-cbor.git", | ||
"url": "git+ssh://git@github.com/hildjj/node-cbor.git", | ||
"directory": "packages/cbor-bigdecimal" | ||
@@ -32,10 +25,5 @@ }, | ||
}, | ||
"devDependencies": { | ||
"bignumber.js": "^9.1.1", | ||
"webpack": "^5.82.1", | ||
"webpack-cli": "^5.1.1" | ||
}, | ||
"engines": { | ||
"node": ">=16" | ||
"node": ">=18" | ||
} | ||
} |
@@ -17,5 +17,5 @@ # cbor-bignumber | ||
```js | ||
const cbor = require('cbor') | ||
const bdec = require('cbor-bigdecimal') | ||
bdec(cbor) | ||
const cbor = require('cbor'); | ||
const bdec = require('cbor-bigdecimal'); | ||
bdec(cbor); | ||
``` | ||
@@ -26,3 +26,3 @@ | ||
```js | ||
cbor.reset() | ||
cbor.reset(); | ||
``` | ||
@@ -29,0 +29,0 @@ |
0
4981