From 562d2ab1f9e04979d3de944d1e69734982600f98 Mon Sep 17 00:00:00 2001 From: Kris Zyp Date: Wed, 3 Feb 2021 11:50:50 -0700 Subject: [PATCH] More exports of FLOAT32_OPTIONS, #13 --- browser.js | 1 + index.js | 7 ++----- index.mjs | 1 + pack.js | 6 +----- pack.mjs | 2 +- tests/test.js | 6 ++---- unpack.js | 6 ++++++ unpack.mjs | 2 +- 8 files changed, 15 insertions(+), 16 deletions(-) diff --git a/browser.js b/browser.js index 6a83936..c7d3dca 100644 --- a/browser.js +++ b/browser.js @@ -8,6 +8,7 @@ exports.unpack = packr.unpack exports.pack = packr.pack exports.decode = packr.unpack exports.encode = packr.pack +exports.FLOAT32_OPTIONS = require('./unpack').FLOAT32_OPTIONS Object.assign(exports, { ALWAYS:1, DECIMAL_ROUND: 3, diff --git a/index.js b/index.js index e8da5a4..dda8b8e 100644 --- a/index.js +++ b/index.js @@ -20,11 +20,8 @@ exports.decode = unpackModule.unpack exports.encode = packModule.pack exports.useRecords = false exports.mapsAsObjects = true -Object.assign(exports, { - ALWAYS: 1, - DECIMAL_ROUND: 3, - DECIMAL_FIT: 4 -}) +exports.FLOAT32_OPTIONS = unpackModule.FLOAT32_OPTIONS +Object.assign(exports, unpackModule.FLOAT32_OPTIONS) function tryRequire(moduleId) { try { diff --git a/index.mjs b/index.mjs index 0717f8d..2d3cfd7 100644 --- a/index.mjs +++ b/index.mjs @@ -23,6 +23,7 @@ export const decode = packr.unpack export const encode = packr.pack export const useRecords = false export const mapsAsObjects = true +export const FLOAT32_OPTIONS = unpackModule.FLOAT32_OPTIONS export const ALWAYS = 1 export const DECIMAL_ROUND = 3 export const DECIMAL_FIT = 4 diff --git a/pack.js b/pack.js index 4ac7860..e46cf98 100644 --- a/pack.js +++ b/pack.js @@ -759,8 +759,4 @@ exports.addExtension = function(extension) { let defaultPackr = new Packr({ useRecords: false }) exports.pack = defaultPackr.pack exports.encode = defaultPackr.pack -Object.assign(exports, { - ALWAYS: 1, - DECIMAL_ROUND: 3, - DECIMAL_FIT: 4 -}) +Object.assign(exports, exports.FLOAT32_OPTIONS = unpackModule.FLOAT32_OPTIONS) diff --git a/pack.mjs b/pack.mjs index 5f56c46..83181ff 100644 --- a/pack.mjs +++ b/pack.mjs @@ -1,2 +1,2 @@ import packModule from './pack.js' -export const { Packr, Encoder, pack, encode, addExtension, ALWAYS, DECIMAL_ROUND, DECIMAL_FIT } = packModule \ No newline at end of file +export const { Packr, Encoder, pack, encode, addExtension, FLOAT32_OPTIONS } = packModule \ No newline at end of file diff --git a/tests/test.js b/tests/test.js index ec8afc2..10f5e4a 100644 --- a/tests/test.js +++ b/tests/test.js @@ -15,7 +15,7 @@ var PackrStream = msgpackr.PackrStream var UnpackrStream = msgpackr.UnpackrStream var unpack = msgpackr.unpack var pack = msgpackr.pack -var DECIMAL_FIT = msgpackr.DECIMAL_FIT +var DECIMAL_FIT = msgpackr.FLOAT32_OPTIONS.DECIMAL_FIT var addExtension = msgpackr.addExtension @@ -188,12 +188,10 @@ suite('msgpackr basic tests', function(){ Class: TestClass, type: 0x01, pack() { - return Buffer.alloc(256) + return typeof Buffer != 'undefined' ? Buffer.alloc(256) : new Uint8Array(256) }, unpack(data) { return data.length - // here data.length equals to 0 - assert(data.length == 256); } }); let result = unpack(pack(new TestClass())); diff --git a/unpack.js b/unpack.js index 016ca3b..d055ca6 100644 --- a/unpack.js +++ b/unpack.js @@ -823,3 +823,9 @@ exports.C1Type = C1Type let defaultUnpackr = new Unpackr({ useRecords: false }) exports.unpack = defaultUnpackr.unpack exports.decode = defaultUnpackr.unpack +exports.FLOAT32_OPTIONS = { + NEVER: 0, + ALWAYS: 1, + DECIMAL_ROUND: 3, + DECIMAL_FIT: 4 +} \ No newline at end of file diff --git a/unpack.mjs b/unpack.mjs index 35cd14d..5ec477b 100644 --- a/unpack.mjs +++ b/unpack.mjs @@ -1,2 +1,2 @@ import unpackModule from './unpack.js' -export const { Unpackr, Decoder, unpack, decode, addExtension, C1, mult10, typedArrays, C1Type } = unpackModule \ No newline at end of file +export const { Unpackr, Decoder, unpack, decode, addExtension, C1, mult10, typedArrays, C1Type, FLOAT32_OPTIONS } = unpackModule \ No newline at end of file