Skip to content

Commit 5b49d36

Browse files
ci: Fix lint
1 parent d4b1afc commit 5b49d36

13 files changed

Lines changed: 203 additions & 402 deletions

biome.json

Lines changed: 105 additions & 303 deletions
Large diffs are not rendered by default.

source/errors/error-serializer.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { expect } from "chai";
22
import { it } from "mocha";
3-
import { InternalError } from "./InternalError.js";
4-
import { InvalidArgumentError } from "./InvalidArgumentError.js";
53
import {
64
errorToJSON,
75
errorToRecord,
86
errorToSimpleSerializable,
97
isError,
108
unknownToError,
119
} from "./error-serializer.js";
10+
import { InternalError } from "./InternalError.js";
11+
import { InvalidArgumentError } from "./InvalidArgumentError.js";
1212

1313
function generateDefaultError() {
1414
try {

source/format/bytes.test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,12 @@ it("binary option", () => {
126126
});
127127

128128
it("bits and binary option", () => {
129-
expect(formatBytes(0, { bits: true, binary: true })).to.equal("0 b");
130-
expect(formatBytes(4, { bits: true, binary: true })).to.equal("4 b");
131-
expect(formatBytes(10, { bits: true, binary: true })).to.equal("10 b");
132-
expect(formatBytes(999, { bits: true, binary: true })).to.equal("999 b");
133-
expect(formatBytes(1025, { bits: true, binary: true })).to.equal("1 kibit");
134-
expect(formatBytes(1e6, { bits: true, binary: true })).to.equal("977 kibit");
129+
expect(formatBytes(0, { binary: true, bits: true })).to.equal("0 b");
130+
expect(formatBytes(4, { binary: true, bits: true })).to.equal("4 b");
131+
expect(formatBytes(10, { binary: true, bits: true })).to.equal("10 b");
132+
expect(formatBytes(999, { binary: true, bits: true })).to.equal("999 b");
133+
expect(formatBytes(1025, { binary: true, bits: true })).to.equal("1 kibit");
134+
expect(formatBytes(1e6, { binary: true, bits: true })).to.equal("977 kibit");
135135
});
136136

137137
it("fractional digits options", () => {
@@ -141,20 +141,20 @@ it("fractional digits options", () => {
141141
expect(formatBytes(1111, { maximumFractionDigits: 2 })).to.equal("1.11 kB");
142142
expect(formatBytes(1019, { maximumFractionDigits: 3 })).to.equal("1.019 kB");
143143
expect(formatBytes(1001, { maximumFractionDigits: 3 })).to.equal("1.001 kB");
144-
expect(formatBytes(1000, { minimumFractionDigits: 1, maximumFractionDigits: 3 })).to.equal(
144+
expect(formatBytes(1000, { maximumFractionDigits: 3, minimumFractionDigits: 1 })).to.equal(
145145
"1.0 kB",
146146
);
147-
expect(formatBytes(3942, { minimumFractionDigits: 1, maximumFractionDigits: 2 })).to.equal(
147+
expect(formatBytes(3942, { maximumFractionDigits: 2, minimumFractionDigits: 1 })).to.equal(
148148
"3.94 kB",
149149
);
150-
expect(formatBytes(4001, { maximumFractionDigits: 3, binary: true })).to.equal("3.907 KiB");
151-
expect(formatBytes(18_717, { maximumFractionDigits: 2, binary: true })).to.equal("18.28 KiB");
152-
expect(formatBytes(18_717, { maximumFractionDigits: 4, binary: true })).to.equal("18.2783 KiB");
150+
expect(formatBytes(4001, { binary: true, maximumFractionDigits: 3 })).to.equal("3.907 KiB");
151+
expect(formatBytes(18_717, { binary: true, maximumFractionDigits: 2 })).to.equal("18.28 KiB");
152+
expect(formatBytes(18_717, { binary: true, maximumFractionDigits: 4 })).to.equal("18.2783 KiB");
153153
expect(
154-
formatBytes(32_768, { minimumFractionDigits: 2, maximumFractionDigits: 3, binary: true }),
154+
formatBytes(32_768, { binary: true, maximumFractionDigits: 3, minimumFractionDigits: 2 }),
155155
).to.equal("32.00 KiB");
156156
expect(
157-
formatBytes(65_536, { minimumFractionDigits: 1, maximumFractionDigits: 3, binary: true }),
157+
formatBytes(65_536, { binary: true, maximumFractionDigits: 3, minimumFractionDigits: 1 }),
158158
).to.equal("64.0 KiB");
159159
});
160160

source/format/bytes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ export const formatBytes = (
165165
}
166166

167167
options = {
168-
bits: false,
169168
binary: false,
169+
bits: false,
170170
space: true,
171171
...options,
172172
};

source/format/milliseconds.test.ts

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ function runTests({
4545
}
4646

4747
runTests({
48-
title: "prettify milliseconds",
4948
cases: [
5049
[0, "0ms"],
5150
[0.1, "1ms"],
@@ -67,21 +66,21 @@ runTests({
6766
[120_000, "2m"],
6867
[Number.MAX_SAFE_INTEGER, "285616y 151d 8h 59m 0.9s"],
6968
],
69+
title: "prettify milliseconds",
7070
});
7171

7272
runTests({
73-
title: "have a compact option",
74-
defaultOptions: { compact: true },
7573
cases: [
7674
[1000 + 4, "1s"],
7775
[1000 * 60 * 60 * 999, "41d"],
7876
[1000 * 60 * 60 * 24 * 465, "1y"],
7977
[1000 * 60 * 67 * 24 * 465, "1y"],
8078
],
79+
defaultOptions: { compact: true },
80+
title: "have a compact option",
8181
});
8282

8383
runTests({
84-
title: "have a unitCount option",
8584
cases: [
8685
[1000 * 60, { unitCount: 0 }, "1m"],
8786
[1000 * 60, { unitCount: 1 }, "1m"],
@@ -91,10 +90,10 @@ runTests({
9190
[1000 * 60 * 67 * 24 * 465, { unitCount: 2 }, "1y 154d"],
9291
[1000 * 60 * 67 * 24 * 465, { unitCount: 3 }, "1y 154d 6h"],
9392
],
93+
title: "have a unitCount option",
9494
});
9595

9696
runTests({
97-
title: "have a secondsDecimalDigits option",
9897
cases: [
9998
[10_000, "10s"],
10099
[33_333, "33.3s"],
@@ -105,29 +104,28 @@ runTests({
105104
[33_333, { secondsDecimalDigits: 0 }, "33s"],
106105
[33_333, { secondsDecimalDigits: 4 }, "33.3330s"],
107106
],
107+
title: "have a secondsDecimalDigits option",
108108
});
109109

110110
runTests({
111-
title: "have a millisecondsDecimalDigits option",
112111
cases: [
113112
[33.333, "33ms"],
114113
[33.333, { millisecondsDecimalDigits: 0 }, "33ms"],
115114
[33.333, { millisecondsDecimalDigits: 4 }, "33.3330ms"],
116115
],
116+
title: "have a millisecondsDecimalDigits option",
117117
});
118118

119119
runTests({
120-
title: "have a keepDecimalsOnWholeSeconds option",
121-
defaultOptions: { keepDecimalsOnWholeSeconds: true },
122120
cases: [
123121
[1000 * 33, { secondsDecimalDigits: 2 }, "33.00s"],
124122
[1000 * 33.000_04, { secondsDecimalDigits: 2 }, "33.00s"],
125123
],
124+
defaultOptions: { keepDecimalsOnWholeSeconds: true },
125+
title: "have a keepDecimalsOnWholeSeconds option",
126126
});
127127

128128
runTests({
129-
title: "have a verbose option",
130-
defaultOptions: { verbose: true },
131129
cases: [
132130
[0, "0 milliseconds"],
133131
[0.1, "1 millisecond"],
@@ -146,30 +144,30 @@ runTests({
146144
[1000 * 60 * 60 * 24 * 465, "1 year 100 days"],
147145
[1000 * 60 * 67 * 24 * 465, "1 year 154 days 6 hours"],
148146
],
147+
defaultOptions: { verbose: true },
148+
title: "have a verbose option",
149149
});
150150

151151
runTests({
152-
title: "have a separateMilliseconds option",
153152
cases: [
154153
[1100, { separateMilliseconds: false }, "1.1s"],
155154
[1100, { separateMilliseconds: true }, "1s 100ms"],
156155
],
156+
title: "have a separateMilliseconds option",
157157
});
158158

159159
runTests({
160-
title: "have a formatSubMilliseconds option",
161-
defaultOptions: { formatSubMilliseconds: true },
162160
cases: [
163161
[0.4, "400µs"],
164162
[0.123_571, "123µs 571ns"],
165163
[0.123_456_789, "123µs 456ns"],
166164
[60 * 60 * 1000 + 23 * 1000 + 433 + 0.123_456, "1h 23s 433ms 123µs 456ns"],
167165
],
166+
defaultOptions: { formatSubMilliseconds: true },
167+
title: "have a formatSubMilliseconds option",
168168
});
169169

170170
runTests({
171-
title: "work with verbose and compact options",
172-
defaultOptions: { verbose: true, compact: true },
173171
cases: [
174172
[1000, "1 second"],
175173
[1000 + 400, "1 second"],
@@ -185,11 +183,11 @@ runTests({
185183
[1000 * 60 * 60 * 24 * 465, "1 year"],
186184
[1000 * 60 * 67 * 24 * 750, "2 years"],
187185
],
186+
defaultOptions: { compact: true, verbose: true },
187+
title: "work with verbose and compact options",
188188
});
189189

190190
runTests({
191-
title: "work with verbose and unitCount options",
192-
defaultOptions: { verbose: true },
193191
cases: [
194192
[1000 * 60, { unitCount: 1 }, "1 minute"],
195193
[1000 * 60 * 67, { unitCount: 1 }, "1 hour"],
@@ -198,60 +196,62 @@ runTests({
198196
[1000 * 60 * 67 * 24 * 465, { unitCount: 2 }, "1 year 154 days"],
199197
[1000 * 60 * 67 * 24 * 465, { unitCount: 3 }, "1 year 154 days 6 hours"],
200198
],
199+
defaultOptions: { verbose: true },
200+
title: "work with verbose and unitCount options",
201201
});
202202

203203
runTests({
204-
title: "work with verbose and secondsDecimalDigits options",
205-
defaultOptions: { verbose: true, secondsDecimalDigits: 4 },
206204
cases: [
207205
[1000, "1 second"],
208206
[1000 + 400, "1.4000 seconds"],
209207
[1000 * 2 + 400, "2.4000 seconds"],
210208
[1000 * 5 + 254, "5.2540 seconds"],
211209
[33_333, "33.3330 seconds"],
212210
],
211+
defaultOptions: { secondsDecimalDigits: 4, verbose: true },
212+
title: "work with verbose and secondsDecimalDigits options",
213213
});
214214

215215
runTests({
216-
title: "work with verbose and millisecondsDecimalDigits options",
217-
defaultOptions: { verbose: true, millisecondsDecimalDigits: 4 },
218216
cases: [
219217
[1, "1.0000 millisecond"],
220218
[1 + 0.4, "1.4000 milliseconds"],
221219
[1 * 2 + 0.4, "2.4000 milliseconds"],
222220
[1 * 5 + 0.254, "5.2540 milliseconds"],
223221
[33.333, "33.3330 milliseconds"],
224222
],
223+
defaultOptions: { millisecondsDecimalDigits: 4, verbose: true },
224+
title: "work with verbose and millisecondsDecimalDigits options",
225225
});
226226

227227
runTests({
228-
title: "work with verbose and formatSubMilliseconds options",
229-
defaultOptions: { formatSubMilliseconds: true, verbose: true },
230228
cases: [
231229
[0.4, "400 microseconds"],
232230
[0.123_571, "123 microseconds 571 nanoseconds"],
233231
[0.123_456_789, "123 microseconds 456 nanoseconds"],
234232
[0.001, "1 microsecond"],
235233
],
234+
defaultOptions: { formatSubMilliseconds: true, verbose: true },
235+
title: "work with verbose and formatSubMilliseconds options",
236236
});
237237

238238
runTests({
239-
title: "compact option overrides unitCount option",
240-
defaultOptions: { verbose: true, compact: true },
241239
cases: [
242240
[1000 * 60 * 67 * 24 * 465, { unitCount: 1 }, "1 year"],
243241
[1000 * 60 * 67 * 24 * 465, { unitCount: 2 }, "1 year"],
244242
[1000 * 60 * 67 * 24 * 465, { unitCount: 3 }, "1 year"],
245243
],
244+
defaultOptions: { compact: true, verbose: true },
245+
title: "compact option overrides unitCount option",
246246
});
247247

248248
runTests({
249-
title: "work with separateMilliseconds and formatSubMilliseconds options",
250-
defaultOptions: { separateMilliseconds: true, formatSubMilliseconds: true },
251249
cases: [
252250
[1010.340_067, "1s 10ms 340µs 67ns"],
253251
[60 * 1000 + 34 + 0.000_005, "1m 34ms 5ns"],
254252
],
253+
defaultOptions: { formatSubMilliseconds: true, separateMilliseconds: true },
254+
title: "work with separateMilliseconds and formatSubMilliseconds options",
255255
});
256256

257257
it("throw on invalid", () => {
@@ -269,8 +269,6 @@ it("throw on invalid", () => {
269269
});
270270

271271
runTests({
272-
title: "properly rounds milliseconds with secondsDecimalDigits",
273-
defaultOptions: { verbose: true, secondsDecimalDigits: 0 },
274272
cases: [
275273
[3 * 60 * 1000, "3 minutes"],
276274
[3 * 60 * 1000 - 1, "2 minutes 59 seconds"],
@@ -283,11 +281,11 @@ runTests({
283281
[2 * 3600 * 1e3, "2 hours"],
284282
[2 * 3600 * 1e3 - 1, "1 hour 59 minutes 59 seconds"],
285283
],
284+
defaultOptions: { secondsDecimalDigits: 0, verbose: true },
285+
title: "properly rounds milliseconds with secondsDecimalDigits",
286286
});
287287

288288
runTests({
289-
title: "`colonNotation` option",
290-
defaultOptions: { colonNotation: true },
291289
cases: [
292290
// Default formats
293291
[1000, "0:01"],
@@ -328,17 +326,17 @@ runTests({
328326
],
329327

330328
// Together with `keepDecimalsOnWholeSeconds`
331-
[999, { secondsDecimalDigits: 0, keepDecimalsOnWholeSeconds: true }, "0:00"],
332-
[999, { secondsDecimalDigits: 1, keepDecimalsOnWholeSeconds: true }, "0:00.9"],
333-
[999, { secondsDecimalDigits: 2, keepDecimalsOnWholeSeconds: true }, "0:00.99"],
334-
[999, { secondsDecimalDigits: 3, keepDecimalsOnWholeSeconds: true }, "0:00.999"],
329+
[999, { keepDecimalsOnWholeSeconds: true, secondsDecimalDigits: 0 }, "0:00"],
330+
[999, { keepDecimalsOnWholeSeconds: true, secondsDecimalDigits: 1 }, "0:00.9"],
331+
[999, { keepDecimalsOnWholeSeconds: true, secondsDecimalDigits: 2 }, "0:00.99"],
332+
[999, { keepDecimalsOnWholeSeconds: true, secondsDecimalDigits: 3 }, "0:00.999"],
335333
[1000, { keepDecimalsOnWholeSeconds: true }, "0:01.0"],
336-
[1000, { secondsDecimalDigits: 0, keepDecimalsOnWholeSeconds: true }, "0:01"],
337-
[1000, { secondsDecimalDigits: 1, keepDecimalsOnWholeSeconds: true }, "0:01.0"],
338-
[1000, { secondsDecimalDigits: 3, keepDecimalsOnWholeSeconds: true }, "0:01.000"],
334+
[1000, { keepDecimalsOnWholeSeconds: true, secondsDecimalDigits: 0 }, "0:01"],
335+
[1000, { keepDecimalsOnWholeSeconds: true, secondsDecimalDigits: 1 }, "0:01.0"],
336+
[1000, { keepDecimalsOnWholeSeconds: true, secondsDecimalDigits: 3 }, "0:01.000"],
339337
[1000 * 90, { keepDecimalsOnWholeSeconds: true }, "1:30.0"],
340-
[1000 * 90, { secondsDecimalDigits: 3, keepDecimalsOnWholeSeconds: true }, "1:30.000"],
341-
[1000 * 60 * 10, { secondsDecimalDigits: 3, keepDecimalsOnWholeSeconds: true }, "10:00.000"],
338+
[1000 * 90, { keepDecimalsOnWholeSeconds: true, secondsDecimalDigits: 3 }, "1:30.000"],
339+
[1000 * 60 * 10, { keepDecimalsOnWholeSeconds: true, secondsDecimalDigits: 3 }, "10:00.000"],
342340

343341
// Together with `unitCount`
344342
[1000 * 90, { secondsDecimalDigits: 0, unitCount: 1 }, "1"],
@@ -357,6 +355,8 @@ runTests({
357355
// Big numbers
358356
[Number.MAX_SAFE_INTEGER, "285616:151:08:59:00.9"],
359357
],
358+
defaultOptions: { colonNotation: true },
359+
title: "`colonNotation` option",
360360
});
361361

362362
it("Big numbers", () => {

source/format/milliseconds.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,23 +74,23 @@ const parseNumber = (milliseconds: number) => {
7474
return {
7575
days: Math.trunc(milliseconds / 86_400_000),
7676
hours: Math.trunc((milliseconds / 3_600_000) % 24),
77-
minutes: Math.trunc((milliseconds / 60_000) % 60),
78-
seconds: Math.trunc((milliseconds / 1000) % 60),
79-
milliseconds: Math.trunc(milliseconds % 1000),
8077
microseconds: Math.trunc(toZeroIfInfinity(milliseconds * 1000) % 1000),
78+
milliseconds: Math.trunc(milliseconds % 1000),
79+
minutes: Math.trunc((milliseconds / 60_000) % 60),
8180
nanoseconds: Math.trunc(toZeroIfInfinity(milliseconds * 1e6) % 1000),
81+
seconds: Math.trunc((milliseconds / 1000) % 60),
8282
};
8383
};
8484

8585
const parseBigint = (milliseconds: bigint) => {
8686
return {
8787
days: milliseconds / 86_400_000n,
8888
hours: (milliseconds / 3_600_000n) % 24n,
89-
minutes: (milliseconds / 60_000n) % 60n,
90-
seconds: (milliseconds / 1000n) % 60n,
91-
milliseconds: milliseconds % 1000n,
9289
microseconds: 0n,
90+
milliseconds: milliseconds % 1000n,
91+
minutes: (milliseconds / 60_000n) % 60n,
9392
nanoseconds: 0n,
93+
seconds: (milliseconds / 1000n) % 60n,
9494
};
9595
};
9696

source/format/string.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ it("formats index-based template strings", () => {
1010

1111
it("formats literal-based template strings", () => {
1212
expect(formatStringTemplate("'#{foo}'", { foo: "foo" })).to.equal("'foo'");
13-
expect(formatStringTemplate("'#{foo}': #{bar}", { foo: "foo", bar: "bar" })).to.equal(
13+
expect(formatStringTemplate("'#{foo}': #{bar}", { bar: "bar", foo: "foo" })).to.equal(
1414
"'foo': bar",
1515
);
1616
expect(formatStringTemplate("'#{foo}': #{bar}", { foo: "foo" })).to.equal(

0 commit comments

Comments
 (0)