Skip to content

Commit

Permalink
chore: bump prettier to version 3
Browse files Browse the repository at this point in the history
This change is necessary to be able to write "import type { ... }".
  • Loading branch information
darrachequesne committed Feb 5, 2024
1 parent 2321385 commit 08cff77
Show file tree
Hide file tree
Showing 13 changed files with 118 additions and 118 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
matrix:
node-version:
- 10
- 14
- 20

steps:
Expand Down
2 changes: 1 addition & 1 deletion lib/commons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ PACKET_TYPES["upgrade"] = "5";
PACKET_TYPES["noop"] = "6";

const PACKET_TYPES_REVERSE = Object.create(null);
Object.keys(PACKET_TYPES).forEach(key => {
Object.keys(PACKET_TYPES).forEach((key) => {
PACKET_TYPES_REVERSE[PACKET_TYPES[key]] = key;
});

Expand Down
12 changes: 6 additions & 6 deletions lib/decodePacket.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@ import {
PACKET_TYPES_REVERSE,
Packet,
BinaryType,
RawData
RawData,
} from "./commons.js";
import { decode } from "./contrib/base64-arraybuffer.js";

const withNativeArrayBuffer = typeof ArrayBuffer === "function";

export const decodePacket = (
encodedPacket: RawData,
binaryType?: BinaryType
binaryType?: BinaryType,
): Packet => {
if (typeof encodedPacket !== "string") {
return {
type: "message",
data: mapBinary(encodedPacket, binaryType)
data: mapBinary(encodedPacket, binaryType),
};
}
const type = encodedPacket.charAt(0);
if (type === "b") {
return {
type: "message",
data: decodeBase64Packet(encodedPacket.substring(1), binaryType)
data: decodeBase64Packet(encodedPacket.substring(1), binaryType),
};
}
const packetType = PACKET_TYPES_REVERSE[type];
Expand All @@ -33,10 +33,10 @@ export const decodePacket = (
return encodedPacket.length > 1
? {
type: PACKET_TYPES_REVERSE[type],
data: encodedPacket.substring(1)
data: encodedPacket.substring(1),
}
: {
type: PACKET_TYPES_REVERSE[type]
type: PACKET_TYPES_REVERSE[type],
};
};

Expand Down
14 changes: 7 additions & 7 deletions lib/decodePacket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@ import {
PACKET_TYPES_REVERSE,
Packet,
BinaryType,
RawData
RawData,
} from "./commons.js";

export const decodePacket = (
encodedPacket: RawData,
binaryType?: BinaryType
binaryType?: BinaryType,
): Packet => {
if (typeof encodedPacket !== "string") {
return {
type: "message",
data: mapBinary(encodedPacket, binaryType)
data: mapBinary(encodedPacket, binaryType),
};
}
const type = encodedPacket.charAt(0);
if (type === "b") {
const buffer = Buffer.from(encodedPacket.substring(1), "base64");
return {
type: "message",
data: mapBinary(buffer, binaryType)
data: mapBinary(buffer, binaryType),
};
}
if (!PACKET_TYPES_REVERSE[type]) {
Expand All @@ -30,10 +30,10 @@ export const decodePacket = (
return encodedPacket.length > 1
? {
type: PACKET_TYPES_REVERSE[type],
data: encodedPacket.substring(1)
data: encodedPacket.substring(1),
}
: {
type: PACKET_TYPES_REVERSE[type]
type: PACKET_TYPES_REVERSE[type],
};
};

Expand All @@ -47,7 +47,7 @@ const mapBinary = (data: RawData, binaryType?: BinaryType) => {
// from HTTP long-polling
return data.buffer.slice(
data.byteOffset,
data.byteOffset + data.byteLength
data.byteOffset + data.byteLength,
);
} else {
// from WebTransport (Uint8Array)
Expand Down
17 changes: 7 additions & 10 deletions lib/encodePacket.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const withNativeBlob =
const withNativeArrayBuffer = typeof ArrayBuffer === "function";

// ArrayBuffer.isView method is not defined in IE10
const isView = obj => {
const isView = (obj) => {
return typeof ArrayBuffer.isView === "function"
? ArrayBuffer.isView(obj)
: obj && obj.buffer instanceof ArrayBuffer;
Expand All @@ -16,7 +16,7 @@ const isView = obj => {
const encodePacket = (
{ type, data }: Packet,
supportsBinary: boolean,
callback: (encodedPacket: RawData) => void
callback: (encodedPacket: RawData) => void,
) => {
if (withNativeBlob && data instanceof Blob) {
if (supportsBinary) {
Expand All @@ -40,10 +40,10 @@ const encodePacket = (

const encodeBlobAsBase64 = (
data: Blob,
callback: (encodedPacket: RawData) => void
callback: (encodedPacket: RawData) => void,
) => {
const fileReader = new FileReader();
fileReader.onload = function() {
fileReader.onload = function () {
const content = (fileReader.result as string).split(",")[1];
callback("b" + (content || ""));
};
Expand All @@ -64,20 +64,17 @@ let TEXT_ENCODER;

export function encodePacketToBinary(
packet: Packet,
callback: (encodedPacket: RawData) => void
callback: (encodedPacket: RawData) => void,
) {
if (withNativeBlob && packet.data instanceof Blob) {
return packet.data
.arrayBuffer()
.then(toArray)
.then(callback);
return packet.data.arrayBuffer().then(toArray).then(callback);
} else if (
withNativeArrayBuffer &&
(packet.data instanceof ArrayBuffer || isView(packet.data))
) {
return callback(toArray(packet.data));
}
encodePacket(packet, false, encoded => {
encodePacket(packet, false, (encoded) => {
if (!TEXT_ENCODER) {
TEXT_ENCODER = new TextEncoder();
}
Expand Down
8 changes: 4 additions & 4 deletions lib/encodePacket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { PACKET_TYPES, Packet, RawData } from "./commons.js";
export const encodePacket = (
{ type, data }: Packet,
supportsBinary: boolean,
callback: (encodedPacket: RawData) => void
callback: (encodedPacket: RawData) => void,
) => {
if (data instanceof ArrayBuffer || ArrayBuffer.isView(data)) {
return callback(
supportsBinary ? data : "b" + toBuffer(data, true).toString("base64")
supportsBinary ? data : "b" + toBuffer(data, true).toString("base64"),
);
}
// plain string
Expand All @@ -31,12 +31,12 @@ let TEXT_ENCODER;

export function encodePacketToBinary(
packet: Packet,
callback: (encodedPacket: RawData) => void
callback: (encodedPacket: RawData) => void,
) {
if (packet.data instanceof ArrayBuffer || ArrayBuffer.isView(packet.data)) {
return callback(toBuffer(packet.data, false));
}
encodePacket(packet, true, encoded => {
encodePacket(packet, true, (encoded) => {
if (!TEXT_ENCODER) {
// lazily created for compatibility with Node.js 10
TEXT_ENCODER = new TextEncoder();
Expand Down
28 changes: 14 additions & 14 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import {
PacketType,
RawData,
BinaryType,
ERROR_PACKET
ERROR_PACKET,
} from "./commons.js";

const SEPARATOR = String.fromCharCode(30); // see https://en.wikipedia.org/wiki/Delimiter#ASCII_delimited_text

const encodePayload = (
packets: Packet[],
callback: (encodedPayload: string) => void
callback: (encodedPayload: string) => void,
) => {
// some packets may be added to the array while encoding, so the initial length must be saved
const length = packets.length;
Expand All @@ -21,7 +21,7 @@ const encodePayload = (

packets.forEach((packet, i) => {
// force base64 encoding for binary packets
encodePacket(packet, false, encodedPacket => {
encodePacket(packet, false, (encodedPacket) => {
encodedPackets[i] = encodedPacket;
if (++count === length) {
callback(encodedPackets.join(SEPARATOR));
Expand All @@ -32,7 +32,7 @@ const encodePayload = (

const decodePayload = (
encodedPayload: string,
binaryType?: BinaryType
binaryType?: BinaryType,
): Packet[] => {
const encodedPackets = encodedPayload.split(SEPARATOR);
const packets = [];
Expand All @@ -49,7 +49,7 @@ const decodePayload = (
export function createPacketEncoderStream() {
return new TransformStream({
transform(packet: Packet, controller) {
encodePacketToBinary(packet, encodedPacket => {
encodePacketToBinary(packet, (encodedPacket) => {
const payloadLength = encodedPacket.length;
let header;
// inspired by the WebSocket format: https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_servers#decoding_payload_length
Expand All @@ -74,7 +74,7 @@ export function createPacketEncoderStream() {
controller.enqueue(header);
controller.enqueue(encodedPacket);
});
}
},
});
}

Expand Down Expand Up @@ -107,12 +107,12 @@ const enum State {
READ_HEADER,
READ_EXTENDED_LENGTH_16,
READ_EXTENDED_LENGTH_64,
READ_PAYLOAD
READ_PAYLOAD,
}

export function createPacketDecoderStream(
maxPayload: number,
binaryType: BinaryType
binaryType: BinaryType,
) {
if (!TEXT_DECODER) {
TEXT_DECODER = new TextDecoder();
Expand Down Expand Up @@ -148,7 +148,7 @@ export function createPacketDecoderStream(
expectedLength = new DataView(
headerArray.buffer,
headerArray.byteOffset,
headerArray.length
headerArray.length,
).getUint16(0);
state = State.READ_PAYLOAD;
} else if (state === State.READ_EXTENDED_LENGTH_64) {
Expand All @@ -160,7 +160,7 @@ export function createPacketDecoderStream(
const view = new DataView(
headerArray.buffer,
headerArray.byteOffset,
headerArray.length
headerArray.length,
);

const n = view.getUint32(0);
Expand All @@ -181,8 +181,8 @@ export function createPacketDecoderStream(
controller.enqueue(
decodePacket(
isBinary ? data : TEXT_DECODER.decode(data),
binaryType
)
binaryType,
),
);
state = State.READ_HEADER;
}
Expand All @@ -192,7 +192,7 @@ export function createPacketDecoderStream(
break;
}
}
}
},
});
}

Expand All @@ -205,5 +205,5 @@ export {
Packet,
PacketType,
RawData,
BinaryType
BinaryType,
};
21 changes: 12 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"expect.js": "0.3.1",
"mocha": "^5.2.0",
"nyc": "~15.0.1",
"prettier": "^1.19.1",
"prettier": "^3.2.5",
"rimraf": "^3.0.2",
"socket.io-browsers": "^1.0.4",
"ts-node": "^10.2.1",
Expand Down
Loading

0 comments on commit 08cff77

Please sign in to comment.