Skip to content

Commit

Permalink
More exports of FLOAT32_OPTIONS, #13
Browse files Browse the repository at this point in the history
  • Loading branch information
kriszyp committed Feb 3, 2021
1 parent 6ca21ac commit 562d2ab
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 16 deletions.
1 change: 1 addition & 0 deletions browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 2 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion pack.mjs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import packModule from './pack.js'
export const { Packr, Encoder, pack, encode, addExtension, ALWAYS, DECIMAL_ROUND, DECIMAL_FIT } = packModule
export const { Packr, Encoder, pack, encode, addExtension, FLOAT32_OPTIONS } = packModule
6 changes: 2 additions & 4 deletions tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()));
Expand Down
6 changes: 6 additions & 0 deletions unpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion unpack.mjs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import unpackModule from './unpack.js'
export const { Unpackr, Decoder, unpack, decode, addExtension, C1, mult10, typedArrays, C1Type } = unpackModule
export const { Unpackr, Decoder, unpack, decode, addExtension, C1, mult10, typedArrays, C1Type, FLOAT32_OPTIONS } = unpackModule

0 comments on commit 562d2ab

Please sign in to comment.