New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

peerjs-js-binarypack

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

peerjs-js-binarypack - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

__test__/blobs.spec.ts

6

__test__/bugs.spec.ts

@@ -8,3 +8,3 @@ import { expect, describe, it } from "@jest/globals";

it("replaces undefined with null ", async () => {
expect(await packAndUnpack(undefined)).toBe(null);
expect(packAndUnpack(undefined)).toBe(null);
});

@@ -14,7 +14,5 @@ });

it("gives back wrong value on INT64_MAX ", async () => {
expect(await packAndUnpack(0x7fffffffffffffff)).toBe(
-9223372036854776000,
);
expect(packAndUnpack(0x7fffffffffffffff)).not.toEqual(0x7fffffffffffffff);
});
});
});

@@ -27,7 +27,7 @@ import { expect, describe, it } from "@jest/globals";

];
expect.assertions(values.length);
// expect.assertions(values.length);
for (const v of values) {
expect(await packAndUnpack(v)).toEqual(v);
expect(packAndUnpack(v)).toEqual(v);
}
});
});
import { expect, describe, it } from "@jest/globals";
import commit_data from "./data.json";
import commit_data from "./data";
import { packAndUnpack } from "./util";

@@ -9,5 +9,5 @@

const values = commit_data;
expect.assertions(values.length);
// expect.assertions(values.length);
for (const v of values) {
expect(await packAndUnpack(v)).toEqual(v);
expect(packAndUnpack(v)).toEqual(v);
}

@@ -20,16 +20,16 @@ });

}
expect(await packAndUnpack(v)).toEqual(v);
expect(packAndUnpack(v)).toEqual(v);
});
it("should keep arrays of objects intact", async () => {
expect(await packAndUnpack(commit_data)).toEqual(commit_data);
expect(packAndUnpack(commit_data)).toEqual(commit_data);
});
it("should keep empty and very large arrays intact", async () => {
const values = [[], Array(0xffff).fill(0)];
expect.assertions(values.length);
// expect.assertions(values.length);
for (const v of values) {
expect(await packAndUnpack(v)).toEqual(v);
expect(packAndUnpack(v)).toEqual(v);
}
});
it("should keep null", async () => {
expect(await packAndUnpack(null)).toEqual(null);
expect(packAndUnpack(null)).toEqual(null);
});

@@ -41,4 +41,7 @@

const v = new Uint8Array(arr.buffer, 4); // Half the array
const result = packAndUnpack<ArrayBuffer>(v);
expect(new Uint8Array(await packAndUnpack<ArrayBuffer>(v))).toEqual(v);
expect(result).toBeInstanceOf(ArrayBuffer);
if (result instanceof ArrayBuffer)
expect(new Uint8Array(result)).toEqual(v);
});

@@ -57,5 +60,8 @@

];
expect.assertions(values.length);
// expect.assertions(values.length);
for (const v of values) {
expect(new Uint8Array(await packAndUnpack<ArrayBuffer>(v))).toEqual(v);
const result = packAndUnpack<ArrayBuffer>(v);
expect(result).toBeInstanceOf(ArrayBuffer);
if (result instanceof ArrayBuffer)
expect(new Uint8Array(result)).toEqual(v);
}

@@ -78,5 +84,8 @@ });

];
expect.assertions(values.length);
// expect.assertions(values.length);
for (const v of values) {
expect(new Int32Array(await packAndUnpack<ArrayBuffer>(v))).toEqual(v);
const result = packAndUnpack<ArrayBuffer>(v);
expect(result).toBeInstanceOf(ArrayBuffer);
if (result instanceof ArrayBuffer)
expect(new Int32Array(result)).toEqual(v);
}

@@ -96,5 +105,5 @@ });

];
expect.assertions(values.length);
// expect.assertions(values.length);
for (const v of values) {
expect(await packAndUnpack<ArrayBuffer>(v)).toEqual(v);
expect(packAndUnpack<ArrayBuffer>(v)).toEqual(v);
}

@@ -105,7 +114,7 @@ });

const values = [new Date(), new Date(Date.UTC(1, 1, 1, 1, 1, 1, 1))];
expect.assertions(values.length);
// expect.assertions(values.length);
for (const v of values) {
expect(await packAndUnpack(v)).toEqual(v.toString());
expect(packAndUnpack(v)).toEqual(v.toString());
}
});
});

@@ -15,5 +15,5 @@ import { expect, describe, it } from "@jest/globals";

];
expect.assertions(values.length);
// expect.assertions(values.length);
for (const v of values) {
expect(await packAndUnpack(v)).toEqual(v);
expect(packAndUnpack(v)).toEqual(v);
}

@@ -20,0 +20,0 @@ });

import { pack, Packable, unpack, Unpackable } from "../lib/binarypack";
export const packAndUnpack = async <T extends Unpackable>(data: Packable) => {
export const packAndUnpack = <T extends Unpackable>(data: Packable) => {
const encoded = pack(data);
if (encoded instanceof Promise) {
return encoded.then(unpack<T>);
}
return unpack<T>(encoded);
};
{
"standard.semistandard": true,
"standard.usePackageJson": true,
"standard.autoFixOnSave": true,
"javascript.validate.enable": false,
"eslint.autoFixOnSave": true
"editor.defaultFormatter": "biomejs.biome"
}

@@ -0,1 +1,9 @@

# [2.1.0](https://github.com/peers/js-binarypack/compare/v2.0.0...v2.1.0) (2023-12-03)
### Features
* re-add Blob support ([cd17d63](https://github.com/peers/js-binarypack/commit/cd17d638e06dd4388145ac62f24c109030ee0e36)), closes [#61](https://github.com/peers/js-binarypack/issues/61)
* re-add Blob support ([#62](https://github.com/peers/js-binarypack/issues/62)) ([e79d1ee](https://github.com/peers/js-binarypack/commit/e79d1eef75a6a9e6f07f5af0aa031925583359ad)), closes [#61](https://github.com/peers/js-binarypack/issues/61)
# [2.0.0](https://github.com/peers/js-binarypack/compare/v1.0.2...v2.0.0) (2023-06-22)

@@ -2,0 +10,0 @@

@@ -1,2 +0,2 @@

export type Packable = null | undefined | string | number | boolean | Date | ArrayBuffer | Array<Packable> | {
export type Packable = null | undefined | string | number | boolean | Date | ArrayBuffer | Blob | Array<Packable> | {
[key: string]: Packable;

@@ -10,9 +10,9 @@ } | ({

export function unpack<T extends Unpackable>(data: ArrayBuffer): T;
export function pack(data: Packable): ArrayBufferLike;
export function pack(data: Packable): ArrayBuffer | Promise<ArrayBuffer | SharedArrayBuffer>;
export class Packer {
getBuffer(): ArrayBufferLike;
pack(value: Packable): void;
pack(value: Packable): Promise<void> | undefined;
pack_bin(blob: Uint8Array): void;
pack_string(str: string): void;
pack_array(ary: Packable[]): void;
pack_array(ary: Packable[]): void | Promise<void>;
pack_integer(num: number): void;

@@ -22,3 +22,3 @@ pack_double(num: number): void;

[key: string]: Packable;
}): void;
}): void | Promise<void>;
pack_uint8(num: number): void;

@@ -25,0 +25,0 @@ pack_uint16(num: number): void;

@@ -11,2 +11,3 @@ import { BufferBuilder } from "./bufferbuilder";

| ArrayBuffer
| Blob
| Array<Packable>

@@ -32,3 +33,6 @@ | { [key: string]: Packable }

const packer = new Packer();
packer.pack(data);
const res = packer.pack(data);
if (res instanceof Promise) {
return res.then(() => packer.getBuffer());
}
return packer.getBuffer();

@@ -324,3 +328,6 @@ }

if (value instanceof Array) {
this.pack_array(value);
const res = this.pack_array(value);
if (res instanceof Promise) {
return res.then(() => this._bufferBuilder.flush());
}
} else if (value instanceof ArrayBuffer) {

@@ -333,2 +340,8 @@ this.pack_bin(new Uint8Array(value));

this.pack_string(value.toString());
} else if (value instanceof Blob) {
return value.arrayBuffer().then((buffer) => {
this.pack_bin(new Uint8Array(buffer));
this._bufferBuilder.flush();
});
// this.pack_bin(new Uint8Array(await value.arrayBuffer()));
} else if (

@@ -338,3 +351,6 @@ constructor == Object ||

) {
this.pack_object(value);
const res = this.pack_object(value);
if (res instanceof Promise) {
return res.then(() => this._bufferBuilder.flush());
}
} else {

@@ -398,5 +414,14 @@ throw new Error(`Type "${constructor.toString()}" not yet supported`);

}
for (let i = 0; i < length; i++) {
this.pack(ary[i]);
}
const packNext = (index: number): Promise<void> | void => {
if (index < length) {
const res = this.pack(ary[index]);
if (res instanceof Promise) {
return res.then(() => packNext(index + 1));
}
return packNext(index + 1);
}
};
return packNext(0);
}

@@ -468,9 +493,19 @@

}
for (const prop in obj) {
// eslint-disable-next-line no-prototype-builtins
if (obj.hasOwnProperty(prop)) {
this.pack(prop);
this.pack(obj[prop]);
const packNext = (index: number): Promise<void> | void => {
if (index < keys.length) {
const prop = keys[index];
// eslint-disable-next-line no-prototype-builtins
if (obj.hasOwnProperty(prop)) {
this.pack(prop);
const res = this.pack(obj[prop]);
if (res instanceof Promise) {
return res.then(() => packNext(index + 1));
}
}
return packNext(index + 1);
}
}
};
return packNext(0);
}

@@ -477,0 +512,0 @@

{
"name": "peerjs-js-binarypack",
"version": "2.0.0",
"version": "2.1.0",
"description": "BinaryPack serialization",

@@ -26,5 +26,3 @@ "homepage": "https://github.com/peers/js-binarypack",

"build": "parcel build",
"test": "jest",
"coverage": "jest --coverage",
"format": "prettier --write .",
"format": "biome format --write .",
"lint": "eslint --ext .js,.ts .",

@@ -105,2 +103,4 @@ "check": "tsc --noEmit"

"devDependencies": {
"@biomejs/biome": "1.4.1",
"@jest/globals": "^29.7.0",
"@parcel/packager-ts": "^2.8.3",

@@ -110,13 +110,7 @@ "@parcel/transformer-typescript-types": "^2.8.3",

"@semantic-release/git": "^10.0.1",
"@swc/core": "^1.3.35",
"@swc/jest": "^0.2.24",
"@types/jest": "^29.4.0",
"@typescript-eslint/eslint-plugin": "^5.52.0",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"eslint": "^8.34.0",
"jest": "^29.4.3",
"jest-environment-jsdom": "^29.4.3",
"parcel": "^2.8.3",
"prettier": "^2.8.4",
"semantic-release": "^20.1.0",
"typescript": "^4.9.5"
"typescript": "^5.0.0"
},

@@ -123,0 +117,0 @@ "license": "MIT",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc