Skip to content

Commit 7b13f34

Browse files
committed
chore(style): lint and format all code files
1 parent d339dbc commit 7b13f34

File tree

9 files changed

+77
-77
lines changed

9 files changed

+77
-77
lines changed

src/lz4js.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
declare module 'lz4js' {
22
export function compress(
33
buffer: number[] | Uint8Array,
4-
maxSize?: number
4+
maxSize?: number,
55
): number[] | Uint8Array;
66

77
export function decompress(
88
buffer: number[] | Uint8Array,
9-
maxSize?: number
9+
maxSize?: number,
1010
): number[] | Uint8Array;
1111
}

src/parse.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export function parse<T = any>(
7373
text: string,
7474
reviver?: ParseReviverFunction | ParseOptions | null,
7575
options?: ParseOptions,
76-
typeGuard?: ParseTypeGuardFunction<T>
76+
typeGuard?: ParseTypeGuardFunction<T>,
7777
): T {
7878
let _reviver: ParseReviverFunction | undefined = undefined;
7979
if (typeof reviver === 'function') {
@@ -109,7 +109,7 @@ export function parse<T = any>(
109109
try {
110110
if (typeGuard?.(result) === false) {
111111
throw new Error(
112-
'Please throw a custom error in the type guard function to track the problems'
112+
'Please throw a custom error in the type guard function to track the problems',
113113
);
114114
}
115115
} catch (err: unknown) {
@@ -125,7 +125,7 @@ export function parse<T = any>(
125125
function unminifyKeys(
126126
obj: any,
127127
keyMap?: Record<string, string>,
128-
level?: number
128+
level?: number,
129129
): any {
130130
let _level: number;
131131
if (level == null || level === 0) {
@@ -165,7 +165,7 @@ function unminifyKeys(
165165
export function decompressString(str: string): string {
166166
try {
167167
return new TextDecoder().decode(
168-
Uint8Array.from(decompress(Base64.toUint8Array(str)))
168+
Uint8Array.from(decompress(Base64.toUint8Array(str))),
169169
);
170170
} catch (err: unknown) {
171171
// str is not a base64 encoded string of a byte array

src/serialize.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export function serialize(obj: any) {
1212
extended: { enable: false },
1313
decompress: { enable: false },
1414
unminify: { enable: false },
15-
}
15+
},
1616
);
1717
}
1818

@@ -27,6 +27,6 @@ export function deserialize(obj: any) {
2727
extended: { enable: true, relaxed: true },
2828
decompress: { enable: false },
2929
unminify: { enable: false },
30-
}
30+
},
3131
);
3232
}

src/stringify.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export type StringifyReplacerArray = (string | number)[];
1111
export type StringifyReplacerFunction = (
1212
this: any,
1313
key: string,
14-
value: any
14+
value: any,
1515
) => any;
1616

1717
export interface StringifyOptions {
@@ -86,7 +86,7 @@ export function stringify(
8686
| StringifyOptions
8787
| null,
8888
space?: string | number,
89-
options?: StringifyOptions
89+
options?: StringifyOptions,
9090
): string {
9191
let _replacer: any = undefined;
9292
if (Array.isArray(replacer)) {
@@ -199,7 +199,7 @@ function getMinifyKeyMap<T>(obj: T): Record<string, string> {
199199

200200
function findAllJsonKeys(
201201
obj: any,
202-
keyCounts: Record<string, number> = {}
202+
keyCounts: Record<string, number> = {},
203203
): Record<string, number> {
204204
if (Array.isArray(obj)) {
205205
obj.forEach((o) => {
@@ -219,7 +219,7 @@ function findAllJsonKeys(
219219
function minifyKeys(
220220
obj: any,
221221
keyMap: Record<string, string>,
222-
level?: number
222+
level?: number,
223223
): any {
224224
let _level: number;
225225
if (level == null || level === 0) {
@@ -250,6 +250,6 @@ function minifyKeys(
250250
export function compressString(str: string): string {
251251
return Base64.fromUint8Array(
252252
compress(new TextEncoder().encode(str)) as Uint8Array,
253-
true
253+
true,
254254
);
255255
}

test/parse.perf.test.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,49 @@ import { formatDuration, timer } from './util/index.js';
55

66
const test = (data: any): void => {
77
const [original, originalStringifyDuration] = timer(() =>
8-
JSON.stringify(data)
8+
JSON.stringify(data),
99
);
1010
const [, originalDuration] = timer(() => JSON.parse(original));
1111

1212
const [basic, basicStringifyDuration] = timer(() => JsonKit.stringify(data));
1313
const [, basicDuration] = timer(() =>
14-
JsonKit.parse(basic, { unminify: false, decompress: false })
14+
JsonKit.parse(basic, { unminify: false, decompress: false }),
1515
);
1616

1717
const [minified, minifiedStringifyDuration] = timer(() =>
18-
JsonKit.stringify(data, { minify: true })
18+
JsonKit.stringify(data, { minify: true }),
1919
);
2020
const [, unminifiedDuration] = timer(() =>
21-
JsonKit.parse(minified, { unminify: true, decompress: false })
21+
JsonKit.parse(minified, { unminify: true, decompress: false }),
2222
);
2323

2424
const [compressed, compressedStringifyDuration] = timer(() =>
25-
JsonKit.stringify(data, { compress: true })
25+
JsonKit.stringify(data, { compress: true }),
2626
);
2727
const [, decompressedDuration] = timer(() =>
28-
JsonKit.parse(compressed, { unminify: false, decompress: true })
28+
JsonKit.parse(compressed, { unminify: false, decompress: true }),
2929
);
3030

3131
const [minifiedAndCompressed, minifiedAndCompressedStringifyDuration] = timer(
3232
() =>
3333
JsonKit.stringify(data, {
3434
minify: true,
3535
compress: true,
36-
})
36+
}),
3737
);
3838
const [, unminifiedAndDecompressedDuration] = timer(() =>
3939
JsonKit.parse(minifiedAndCompressed, {
4040
unminify: true,
4141
decompress: true,
42-
})
42+
}),
4343
);
4444

4545
console.info(
4646
`baseline: [parse: ${formatDuration(
47-
originalDuration
47+
originalDuration,
4848
)} (±0.00%)] [stringify: ${formatDuration(
49-
originalStringifyDuration
50-
)} (±0.00%)]`
49+
originalStringifyDuration,
50+
)} (±0.00%)]`,
5151
);
5252

5353
console.info(
@@ -58,49 +58,49 @@ const test = (data: any): void => {
5858
((basicStringifyDuration - originalStringifyDuration) /
5959
originalStringifyDuration) *
6060
100
61-
).toFixed(2)}%)]`
61+
).toFixed(2)}%)]`,
6262
);
6363

6464
console.info(
6565
`unminify: [parse: ${formatDuration(unminifiedDuration)} (${(
6666
((unminifiedDuration - originalDuration) / originalDuration) *
6767
100
6868
).toFixed(2)}%)] [stringify: ${formatDuration(
69-
minifiedStringifyDuration
69+
minifiedStringifyDuration,
7070
)} (${(
7171
((minifiedStringifyDuration - originalStringifyDuration) /
7272
originalStringifyDuration) *
7373
100
74-
).toFixed(2)}%)]`
74+
).toFixed(2)}%)]`,
7575
);
7676

7777
console.info(
7878
`decompress: [parse: ${formatDuration(decompressedDuration)} (${(
7979
((decompressedDuration - originalDuration) / originalDuration) *
8080
100
8181
).toFixed(2)}%)] [stringify: ${formatDuration(
82-
compressedStringifyDuration
82+
compressedStringifyDuration,
8383
)} (${(
8484
((compressedStringifyDuration - originalStringifyDuration) /
8585
originalStringifyDuration) *
8686
100
87-
).toFixed(2)}%)]`
87+
).toFixed(2)}%)]`,
8888
);
8989

9090
console.info(
9191
`unminify + decompress: [parse: ${formatDuration(
92-
unminifiedAndDecompressedDuration
92+
unminifiedAndDecompressedDuration,
9393
)} (${(
9494
((unminifiedAndDecompressedDuration - originalDuration) /
9595
originalDuration) *
9696
100
9797
).toFixed(2)}%)] [stringify: ${formatDuration(
98-
minifiedAndCompressedStringifyDuration
98+
minifiedAndCompressedStringifyDuration,
9999
)} (${(
100100
((minifiedAndCompressedStringifyDuration - originalStringifyDuration) /
101101
originalStringifyDuration) *
102102
100
103-
).toFixed(2)}%)]`
103+
).toFixed(2)}%)]`,
104104
);
105105
};
106106

test/parse.test.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,23 @@ describe('[parse] basic', () => {
1313
expect(JsonKit.parse(text)).toStrictEqual(JSON.parse(text));
1414

1515
expect(JsonKit.parse(text, reviver)).toStrictEqual(
16-
JSON.parse(text, reviver)
16+
JSON.parse(text, reviver),
1717
);
1818
});
1919

2020
it('parse should have identical behavior as bson.EJSON.parse', () => {
2121
const reviver: ParseReviverFunction = () => 'test';
2222

2323
expect(
24-
JsonKit.parse(text, { extended: { enable: true, relaxed: false } })
24+
JsonKit.parse(text, { extended: { enable: true, relaxed: false } }),
2525
).toStrictEqual(EJSON.parse(text, { relaxed: false }));
2626

2727
expect(
28-
JsonKit.parse(text, { extended: { enable: true, relaxed: true } })
28+
JsonKit.parse(text, { extended: { enable: true, relaxed: true } }),
2929
).toStrictEqual(EJSON.parse(text, { relaxed: true }));
3030

3131
expect(JsonKit.parse(text, reviver, { extended: true })).toStrictEqual(
32-
EJSON.parse(text)
32+
EJSON.parse(text),
3333
);
3434
});
3535

@@ -86,7 +86,7 @@ describe('[parse] unminify', () => {
8686
expect(
8787
JsonKit.parse(text, (key, value) => (key !== 'arr' ? value : undefined), {
8888
unminify: { enable: true, keyMap: undefined },
89-
})
89+
}),
9090
).toStrictEqual({
9191
'very-long-name': obj['very-long-name'],
9292
normal: obj['normal'],
@@ -102,7 +102,7 @@ describe('[parse] unminify', () => {
102102
enable: true,
103103
keyMap: { vln: 'very-long-name', vln2: 'very-long-name-2' },
104104
},
105-
})
105+
}),
106106
).toStrictEqual(obj);
107107
});
108108
});
@@ -130,11 +130,11 @@ describe('[parse] decompress', () => {
130130
const reviver: ParseReviverFunction = () => 'test';
131131

132132
expect(JsonKit.parse(text, { decompress: true })).toStrictEqual(
133-
JSON.parse(JsonKit.decompressString(text))
133+
JSON.parse(JsonKit.decompressString(text)),
134134
);
135135

136136
expect(JsonKit.parse(text, reviver, { decompress: true })).toStrictEqual(
137-
JSON.parse(JsonKit.decompressString(text), reviver)
137+
JSON.parse(JsonKit.decompressString(text), reviver),
138138
);
139139
});
140140

@@ -154,22 +154,22 @@ describe('[parse] decompress', () => {
154154
JsonKit.parse(text, {
155155
extended: { enable: true, relaxed: false },
156156
decompress: { enable: true },
157-
})
157+
}),
158158
).toStrictEqual(
159-
EJSON.parse(JsonKit.decompressString(text), { relaxed: false })
159+
EJSON.parse(JsonKit.decompressString(text), { relaxed: false }),
160160
);
161161

162162
expect(
163163
JsonKit.parse(textRelaxed, {
164164
extended: { enable: true, relaxed: true },
165165
decompress: { enable: true },
166-
})
166+
}),
167167
).toStrictEqual(
168-
EJSON.parse(JsonKit.decompressString(textRelaxed), { relaxed: true })
168+
EJSON.parse(JsonKit.decompressString(textRelaxed), { relaxed: true }),
169169
);
170170

171171
expect(
172-
JsonKit.parse(textRelaxed, reviver, { extended: true, decompress: true })
172+
JsonKit.parse(textRelaxed, reviver, { extended: true, decompress: true }),
173173
).toStrictEqual(EJSON.parse(JsonKit.decompressString(textRelaxed)));
174174
});
175175
});
@@ -191,8 +191,8 @@ describe('[parse] type guard', () => {
191191
text,
192192
null,
193193
{ extended: false, unminify: false, decompress: false },
194-
typeGuard
195-
)
194+
typeGuard,
195+
),
196196
).not.toThrow();
197197
});
198198

@@ -203,8 +203,8 @@ describe('[parse] type guard', () => {
203203
text,
204204
null,
205205
{ extended: false, unminify: false, decompress: false },
206-
typeGuard
207-
)
206+
typeGuard,
207+
),
208208
).toThrow();
209209
});
210210
});

test/stringify.perf.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,49 +9,49 @@ const test = (data: any): void => {
99
const [basic, basicDuration] = timer(() => JsonKit.stringify(data));
1010

1111
const [minified, minifiedDuration] = timer(() =>
12-
JsonKit.stringify(data, { minify: true })
12+
JsonKit.stringify(data, { minify: true }),
1313
);
1414

1515
const [compressed, compressedDuration] = timer(() =>
16-
JsonKit.stringify(data, { compress: true })
16+
JsonKit.stringify(data, { compress: true }),
1717
);
1818

1919
const [minifiedAndCompressed, minifiedAndCompressedDuration] = timer(() =>
2020
JsonKit.stringify(data, {
2121
minify: true,
2222
compress: true,
23-
})
23+
}),
2424
);
2525

2626
console.info(
2727
`baseline: ${original.length} (±0.00%) [${formatDuration(
28-
originalDuration
29-
)}]`
28+
originalDuration,
29+
)}]`,
3030
);
3131

3232
console.info(
33-
`basic: ${basic.length} (±0.00%) [${formatDuration(basicDuration)}]`
33+
`basic: ${basic.length} (±0.00%) [${formatDuration(basicDuration)}]`,
3434
);
3535

3636
console.info(
3737
`minify: ${minified.length} (${(
3838
((minified.length - original.length) / original.length) *
3939
100
40-
).toFixed(2)}%) [${formatDuration(minifiedDuration)}]`
40+
).toFixed(2)}%) [${formatDuration(minifiedDuration)}]`,
4141
);
4242

4343
console.info(
4444
`compress: ${compressed.length} (${(
4545
((compressed.length - original.length) / original.length) *
4646
100
47-
).toFixed(2)}%) [${formatDuration(compressedDuration)}]`
47+
).toFixed(2)}%) [${formatDuration(compressedDuration)}]`,
4848
);
4949

5050
console.info(
5151
`minify + compress: ${minifiedAndCompressed.length} (${(
5252
((minifiedAndCompressed.length - original.length) / original.length) *
5353
100
54-
).toFixed(2)}%) [${formatDuration(minifiedAndCompressedDuration)}]`
54+
).toFixed(2)}%) [${formatDuration(minifiedAndCompressedDuration)}]`,
5555
);
5656
};
5757

0 commit comments

Comments
 (0)