Skip to content

Commit 184ee92

Browse files
committed
prettier
1 parent fb50658 commit 184ee92

File tree

9 files changed

+49
-28
lines changed

9 files changed

+49
-28
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"prepublishOnly": "TEST_DIST=true npm run test",
1010
"test": "TS_NODE_FILES=true mocha 'test/**/*.test.ts'",
1111
"test:cover": "TS_NODE_FILES=true npx nyc mocha 'test/**/*.test.ts'",
12+
"format": "prettier --write 'src/**/*.ts' 'test/**/*.ts'",
1213
"profile:encode": "rm -f isolate-*.log ; node --prof --require ts-node/register -e 'require(\"./benchmark/profile-encode\")' && node --prof-process --preprocess -j isolate-*.log | npx flamebearer",
1314
"profile:decode": "rm -f isolate-*.log ; node --prof --require ts-node/register -e 'require(\"./benchmark/profile-decode\")' && node --prof-process --preprocess -j isolate-*.log | npx flamebearer",
1415
"benchmark": "npx ts-node benchmark/benchmark-from-msgpack-lite.ts"
@@ -35,6 +36,7 @@
3536
"mocha": "^6.1.4",
3637
"msgpack-lite": "^0.1.26",
3738
"msgpack-test-js": "^1.0.0",
39+
"prettier": "^1.17.0",
3840
"ts-loader": "^5.4.5",
3941
"ts-node": "^8.1.0",
4042
"typescript": "^3.4.5"

src/BufferType.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
21
export type BufferType = ArrayLike<number> | Uint8Array;

src/utils/is.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
export function isNodeJsBuffer(object: unknown): object is Buffer {
32
return typeof Buffer !== "undefined" && Buffer.isBuffer(object);
43
}

src/utils/prettyByte.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
export function prettyByte(byte: number): string {
32
return `0x${byte.toString(16).padStart(2, "0")}`;
43
}

src/utils/uf8Encode.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { prettyByte } from "./prettyByte";
22

33
// Using TextEncoder is opt-in because NodeJS v12's impl is much slower than pure-JavaScript version (i.e. _utf8Encode).
44
// Set `PREFER_TEXT_ENOCDER=true` to use TextEncoder if available.
5-
const USE_TEXT_ENCODER = (process.env.PREFER_TEXT_ENOCDER === 'true' && typeof TextEncoder !== "undefined");
5+
const USE_TEXT_ENCODER = process.env.PREFER_TEXT_ENOCDER === "true" && typeof TextEncoder !== "undefined";
66

77
function _utf8Encode(str: string): ReadonlyArray<number> {
88
const len = str.length;
@@ -22,22 +22,26 @@ function _utf8Encode(str: string): ReadonlyArray<number> {
2222
}
2323
}
2424
if (value >= 0xd800 && value <= 0xdbff) {
25-
continue; // drop lone surrogate
25+
continue; // drop lone surrogate
2626
}
2727
}
2828

29-
if ((value & 0xffffff80) === 0) { // 1-byte
29+
if ((value & 0xffffff80) === 0) {
30+
// 1-byte
3031
bytes.push(value);
3132
continue;
32-
} else if ((value & 0xfffff800) === 0) { // 2-bytes
33-
bytes.push(((value >> 6) & 0x1f) | 0xc0)
34-
} else if ((value & 0xffff0000) === 0) { // 3-byte
33+
} else if ((value & 0xfffff800) === 0) {
34+
// 2-bytes
35+
bytes.push(((value >> 6) & 0x1f) | 0xc0);
36+
} else if ((value & 0xffff0000) === 0) {
37+
// 3-byte
3538
bytes.push(((value >> 12) & 0x0f) | 0xe0);
36-
bytes.push(((value >> 6) & 0x3f) | 0x80);
37-
} else if ((value & 0xffe00000) === 0) { // 4-byte
39+
bytes.push(((value >> 6) & 0x3f) | 0x80);
40+
} else if ((value & 0xffe00000) === 0) {
41+
// 4-byte
3842
bytes.push(((value >> 18) & 0x07) | 0xf0);
3943
bytes.push(((value >> 12) & 0x3f) | 0x80);
40-
bytes.push(((value >> 6) & 0x3f) | 0x80);
44+
bytes.push(((value >> 6) & 0x3f) | 0x80);
4145
} else {
4246
throw new Error(`Invalid UTF-8 byte in encode: ${prettyByte(value)} at ${pos}`);
4347
}

test/ExtensionCodec.test.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,36 @@ import util from "util";
33
import { ExtensionCodec, EXT_TIMESTAMP } from "../src/ExtensionCodec";
44

55
describe("ExtensionCodec", () => {
6-
76
const defaultCodec = ExtensionCodec.defaultCodec;
87
context("timestamp", () => {
98
it("encodes and decodes a date without milliseconds (timestamp 32)", () => {
109
const date = new Date(1556633024000);
1110
const encoded = defaultCodec.tryToEncode(date);
12-
assert.deepStrictEqual(defaultCodec.decode(EXT_TIMESTAMP, encoded!.data), date, `date: ${date.toISOString()}, encoded: ${util.inspect(encoded)}`);
11+
assert.deepStrictEqual(
12+
defaultCodec.decode(EXT_TIMESTAMP, encoded!.data),
13+
date,
14+
`date: ${date.toISOString()}, encoded: ${util.inspect(encoded)}`,
15+
);
1316
});
1417

1518
it("encodes and decodes a date with milliseconds (timestamp 64)", () => {
1619
const date = new Date(1556633024123);
1720
const encoded = defaultCodec.tryToEncode(date);
18-
assert.deepStrictEqual(defaultCodec.decode(EXT_TIMESTAMP, encoded!.data), date, `date: ${date.toISOString()}, encoded: ${util.inspect(encoded)}`);
21+
assert.deepStrictEqual(
22+
defaultCodec.decode(EXT_TIMESTAMP, encoded!.data),
23+
date,
24+
`date: ${date.toISOString()}, encoded: ${util.inspect(encoded)}`,
25+
);
1926
});
2027

2128
it("encodes and decodes a future date (timestamp 96)", () => {
2229
const date = new Date(0x400000000 * 1000);
2330
const encoded = defaultCodec.tryToEncode(date);
24-
assert.deepStrictEqual(defaultCodec.decode(EXT_TIMESTAMP, encoded!.data), date, `date: ${date.toISOString()}, encoded: ${util.inspect(encoded)}`);
31+
assert.deepStrictEqual(
32+
defaultCodec.decode(EXT_TIMESTAMP, encoded!.data),
33+
date,
34+
`date: ${date.toISOString()}, encoded: ${util.inspect(encoded)}`,
35+
);
2536
});
2637
});
2738
});

test/codec-timestamp.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ const SPECS = {
1616
} as Record<string, Date>;
1717

1818
describe("codec: timestamp 32/64/96", () => {
19-
for (const name of Object.keys(SPECS)) {
20-
const value = SPECS[name];
19+
for (const name of Object.keys(SPECS)) {
20+
const value = SPECS[name];
2121

22-
it(`encodes and decodes ${name} (${value.toISOString()})`, () => {
23-
const encoded = encode(value);
24-
assert.deepStrictEqual(decode(encoded), value, `encoded: ${util.inspect(encoded)}`);
25-
});
26-
}
22+
it(`encodes and decodes ${name} (${value.toISOString()})`, () => {
23+
const encoded = encode(value);
24+
assert.deepStrictEqual(decode(encoded), value, `encoded: ${util.inspect(encoded)}`);
25+
});
26+
}
2727
});

test/encode-edge-cases.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import assert from "assert";
2-
import { encode, decode } from '../src';
2+
import { encode, decode } from "../src";
33

44
describe("edge cases", () => {
55
context("try to encode trycyclic refs", () => {
@@ -9,15 +9,15 @@ describe("edge cases", () => {
99
assert.throws(() => {
1010
encode(cyclicRefs);
1111
}, /too deep/i);
12-
})
12+
});
1313
});
1414

1515
context("try to encode non-encodable objects", () => {
1616
it("throws errors", () => {
1717
assert.throws(() => {
18-
encode(Symbol('this is a symbol!'));
18+
encode(Symbol("this is a symbol!"));
1919
}, /unrecognized object/i);
20-
})
20+
});
2121
});
2222

2323
context("try to decode invlid MessagePack binary", () => {

test/types/ieee754.d.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
declare module "ieee754" {
22
function read(buf: ArrayLike<number>, offset: number, isLE: boolean, mLen: number, nBytes: number): number;
3-
function write(buf: ArrayLike<number>, value: number, index: number, isLE: boolean, mLen: number, nBytes: number): void;
3+
function write(
4+
buf: ArrayLike<number>,
5+
value: number,
6+
index: number,
7+
isLE: boolean,
8+
mLen: number,
9+
nBytes: number,
10+
): void;
411
}

0 commit comments

Comments
 (0)