cbor-x 1.3.3 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +347 -346
- package/SECURITY.md +11 -11
- package/benchmark.md +73 -73
- package/browser.js +11 -11
- package/decode.d.ts +2 -46
- package/decode.js +47 -29
- package/dist/index.js +1160 -1134
- package/dist/index.min.js +100 -85
- package/dist/node.cjs +1228 -1202
- package/dist/test.js +26 -1
- package/encode.d.ts +1 -6
- package/encode.js +1041 -1033
- package/index.d.ts +61 -12
- package/index.js +3 -3
- package/iterators.js +85 -85
- package/node-index.js +24 -24
- package/package.json +6 -1
- package/rollup.config.js +45 -45
- package/stream.js +57 -57
- package/webpack.config.js +19 -19
- package/dist/index.js.map +0 -1
- package/dist/node-index.js +0 -93
package/dist/test.js
CHANGED
|
@@ -43,7 +43,6 @@
|
|
|
43
43
|
var ITERATIONS = 4000;
|
|
44
44
|
|
|
45
45
|
suite('CBOR basic tests', function(){
|
|
46
|
-
|
|
47
46
|
test('encode/decode with keyMaps (basic)', function() {
|
|
48
47
|
var data = senmlData;
|
|
49
48
|
let cborSenml = new Encoder({ useRecords: false, keyMap: senmlKeys });
|
|
@@ -343,6 +342,15 @@
|
|
|
343
342
|
assert.equal(deserialized.children, deserialized.childrenAgain);
|
|
344
343
|
});
|
|
345
344
|
|
|
345
|
+
test('decode float 16', function() {
|
|
346
|
+
assert.equal(decode(new Uint8Array([0xF9, 0x4A, 0x60])), 12.75);
|
|
347
|
+
assert.equal(decode(new Uint8Array([0xF9, 0xC4, 0x80])), -4.5);
|
|
348
|
+
assert.equal(decode(new Uint8Array([0xF9, 0x5A, 0xF9])), 223.125);
|
|
349
|
+
assert.equal(decode(new Uint8Array([0xF9, 0x45, 0x80])), 5.5);
|
|
350
|
+
assert.equal(decode(new Uint8Array([0xF9, 0x7C, 0])), Infinity);
|
|
351
|
+
assert.equal(decode(new Uint8Array([0xF9, 0xFC, 0])), -Infinity);
|
|
352
|
+
assert.isNaN(decode(new Uint8Array([0xF9, 0x7E, 0])));
|
|
353
|
+
});
|
|
346
354
|
test('structured cloning: types', function() {
|
|
347
355
|
let b = typeof Buffer != 'undefined' ? Buffer.alloc(20) : new Uint8Array(20);
|
|
348
356
|
let fa = new Float32Array(b.buffer, 8, 2);
|
|
@@ -559,6 +567,17 @@
|
|
|
559
567
|
assert.deepEqual(deserialized, data);
|
|
560
568
|
});
|
|
561
569
|
|
|
570
|
+
test('encode ArrayBuffer', function() {
|
|
571
|
+
let ua = new Uint8Array([3, 4, 5]);
|
|
572
|
+
let encoded = encode(ua.buffer);
|
|
573
|
+
let decoded = decode(encoded);
|
|
574
|
+
assert.equal(decoded[0], 3);
|
|
575
|
+
assert.equal(decoded[0], 3);
|
|
576
|
+
assert.equal(decoded[1], 4);
|
|
577
|
+
assert.equal(decoded[2], 5);
|
|
578
|
+
assert.equal(decoded.byteLength, 3);
|
|
579
|
+
});
|
|
580
|
+
|
|
562
581
|
test('iterator/indefinite length array', function(){
|
|
563
582
|
class NotArray {
|
|
564
583
|
}
|
|
@@ -599,6 +618,12 @@
|
|
|
599
618
|
var serialized = encode(data);
|
|
600
619
|
var deserialized = decode(serialized);
|
|
601
620
|
assert.deepEqual(deserialized, data);
|
|
621
|
+
let encoder = new Encoder({ tagUint8Array: true });
|
|
622
|
+
serialized = encoder.encode(new Uint8Array([2,3,4]));
|
|
623
|
+
assert.equal(serialized[0], 0xd8);
|
|
624
|
+
encoder = new Encoder({ tagUint8Array: false });
|
|
625
|
+
serialized = encoder.encode(new Uint8Array([2,3,4]));
|
|
626
|
+
assert.equal(serialized[0], 0x43);
|
|
602
627
|
});
|
|
603
628
|
|
|
604
629
|
test('noteencode test', function() {
|
package/encode.d.ts
CHANGED
|
@@ -1,6 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { addExtension, FLOAT32_OPTIONS } from './decode'
|
|
3
|
-
export class Encoder extends Decoder {
|
|
4
|
-
encode(value: any): Buffer
|
|
5
|
-
}
|
|
6
|
-
export function encode(value: any): Buffer
|
|
1
|
+
export { encode, Encoder, addExtension, FLOAT32_OPTIONS } from '.'
|