Skip to content

Commit c44a52a

Browse files
committed
style(eslint): format
1 parent 79b0b61 commit c44a52a

File tree

116 files changed

+784
-786
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+784
-786
lines changed

__tests__/array/array-async.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { sleep, forEachAsync, mapAsync, reduceAsync } from '../../src';
1+
import { forEachAsync, reduceAsync, mapAsync, sleep } from '../../src';
22

33
describe('promise', function () {
44
test('forEachAsync', async () => {
@@ -7,7 +7,7 @@ describe('promise', function () {
77
await fn(arr1, async (_v, k) => (arr1[k] = k));
88
expect(arr1).toEqual([0, 1, 2]);
99
// ArrayLike
10-
await fn({ 0: 1, 1: 2, length: 2 }, async (_v, k) => (arr1[k] = k + k));
10+
await fn({ length: 2, 0: 1, 1: 2 }, async (_v, k) => (arr1[k] = k + k));
1111
expect(arr1).toEqual([0, 2, 2]);
1212
// const arr = thisArg || this;
1313
await fn.call(arr1, arr1, async (_v, k) => (arr1[k] = k + 2));

__tests__/array/array.test.ts

+61-61
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
import {
2+
getYangHuiTriangleOne,
3+
arrayRemoveItemsBy,
4+
getYangHuiTriangle,
5+
binaryFindIndex,
6+
arrayRemoveItem,
7+
findIndexRight,
8+
insertToArray,
9+
forEachAround,
10+
forEachRight,
211
createArray,
3-
forEach,
412
forEachObj,
5-
isEqual,
6-
forEachRight,
7-
findIndex,
8-
findIndexRight,
913
binaryFind,
10-
binaryFindIndex,
11-
insertToArray,
12-
arrayRemoveItem,
13-
arrayRemoveItemsBy,
14-
unique,
15-
chunk,
16-
inRange,
17-
inRanges,
18-
groupBy,
1914
someInList,
15+
findIndex,
2016
castArray,
17+
joinArray,
18+
inRanges,
19+
forEach,
20+
isEqual,
21+
inRange,
22+
groupBy,
23+
unique,
24+
chunk,
2125
sum,
2226
avg,
23-
getYangHuiTriangle,
24-
getYangHuiTriangleOne,
25-
forEachAround,
26-
joinArray,
2727
} from '../../src';
2828

2929
describe('array', function () {
@@ -38,21 +38,21 @@ describe('array', function () {
3838
expect(createArray({ start: 3, len: 1, end: 5 })).toEqual([3]);
3939
expect(
4040
createArray({
41-
start: 3,
42-
len: 5,
43-
end: 5,
4441
fill(item, index) {
4542
return item + '' + index;
4643
},
44+
start: 3,
45+
len: 5,
46+
end: 5,
4747
}),
4848
).toEqual(['30', '41']);
49-
expect(createArray({ start: 3, len: 5, end: 6, fill: 0 })).toEqual([0, 0, 0]);
49+
expect(createArray({ start: 3, fill: 0, len: 5, end: 6 })).toEqual([0, 0, 0]);
5050

5151
// 测试fill参数
5252
const fn = jest.fn((a) => a);
5353

5454
// end为len
55-
createArray({ len: 5, fill: fn });
55+
createArray({ fill: fn, len: 5 });
5656
expect(fn.mock.calls).toEqual([
5757
[0, 0, 5],
5858
[1, 1, 5],
@@ -64,7 +64,7 @@ describe('array', function () {
6464
fn.mock.calls.length = 0;
6565

6666
// end为start+len
67-
createArray({ start: 3, len: 5, fill: fn });
67+
createArray({ start: 3, fill: fn, len: 5 });
6868
expect(fn.mock.calls).toEqual([
6969
[3, 0, 8],
7070
[4, 1, 8],
@@ -76,7 +76,7 @@ describe('array', function () {
7676
fn.mock.calls.length = 0;
7777

7878
// end为end
79-
createArray({ start: 2, end: 3, fill: fn });
79+
createArray({ start: 2, fill: fn, end: 3 });
8080
expect(fn.mock.calls).toEqual([[2, 0, 3]]);
8181
});
8282
test('forEach', () => {
@@ -86,7 +86,7 @@ describe('array', function () {
8686
expect(isDone).toBe(true);
8787

8888
// ArrayLike
89-
isDone = forEach({ 0: 1, 1: 2, length: 2 }, (_v, k) => (arr1[k] = k + k));
89+
isDone = forEach({ length: 2, 0: 1, 1: 2 }, (_v, k) => (arr1[k] = k + k));
9090
expect(isEqual(arr1, [0, 2, 2])).toBe(true);
9191
expect(isDone).toBe(true);
9292

@@ -209,12 +209,12 @@ describe('array', function () {
209209
const list: { id: number }[] = Array.from({ length: 100 }).map((_, i) => ({ id: i * 2 }));
210210

211211
function find(target: number): {
212-
times: number;
213212
index: ReturnType<typeof binaryFindIndex>;
213+
times: number;
214214
} {
215215
// 查找次数
216216
let times = 0;
217-
const index = binaryFindIndex(list, function ({ item, index, start, end }) {
217+
const index = binaryFindIndex(list, function ({ index, start, item, end }) {
218218
times++;
219219
// console.log(index);
220220
// 判断index是否正确
@@ -281,9 +281,9 @@ describe('array', function () {
281281
test('binaryFind', () => {
282282
const list: { id: number }[] = [...Array(100).keys()].map((i) => ({ id: i * 2 }));
283283

284-
function find(target: number): { times: number; value: ReturnType<typeof binaryFind> } {
284+
function find(target: number): { value: ReturnType<typeof binaryFind>; times: number } {
285285
let times = 0;
286-
const value = binaryFind(list, ({ item, index }) => {
286+
const value = binaryFind(list, ({ index, item }) => {
287287
times++;
288288
// console.log(index);
289289
// 判断index是否正确
@@ -315,23 +315,23 @@ describe('array', function () {
315315
// 正常查找
316316
let findTimes = 0;
317317
const arr = [
318-
{ id: 1, text: '1' },
319-
{ id: 2, text: '2' },
320-
{ id: 3, text: '3' },
321-
{ id: 4, text: '4' },
322-
{ id: 5, text: '5' },
323-
{ id: 6, text: '6' },
318+
{ text: '1', id: 1 },
319+
{ text: '2', id: 2 },
320+
{ text: '3', id: 3 },
321+
{ text: '4', id: 4 },
322+
{ text: '5', id: 5 },
323+
{ text: '6', id: 6 },
324324
];
325325

326-
expect(binaryFind(arr, (o) => (findTimes++, 3 - o.item.id))).toEqual({ id: 3, text: '3' });
326+
expect(binaryFind(arr, (o) => (findTimes++, 3 - o.item.id))).toEqual({ text: '3', id: 3 });
327327
expect(findTimes).toBe(3);
328328

329329
findTimes = 0;
330-
expect(binaryFind(arr, (o) => (findTimes++, 2 - o.item.id))).toEqual({ id: 2, text: '2' });
330+
expect(binaryFind(arr, (o) => (findTimes++, 2 - o.item.id))).toEqual({ text: '2', id: 2 });
331331
expect(findTimes).toBe(2);
332332

333333
findTimes = 0;
334-
expect(binaryFind(arr, (o) => (findTimes++, 6 - o.item.id))).toEqual({ id: 6, text: '6' });
334+
expect(binaryFind(arr, (o) => (findTimes++, 6 - o.item.id))).toEqual({ text: '6', id: 6 });
335335
expect(findTimes).toBe(2);
336336

337337
findTimes = 0;
@@ -382,7 +382,7 @@ describe('array', function () {
382382

383383
const a2: number[] = [];
384384
expect(
385-
insertToArray(3, ({ item, insert }) => (a2.push(item), item < insert), arr7, {
385+
insertToArray(3, ({ insert, item }) => (a2.push(item), item < insert), arr7, {
386386
reverse: true,
387387
after: true,
388388
}),
@@ -450,7 +450,7 @@ describe('array', function () {
450450
// 恢复
451451
arr = [1, 2, 3, 2];
452452
// 反向查找
453-
expect(insertToArray(5, (o) => o.item === 2, arr, { after: false, reverse: true })).toBe(3);
453+
expect(insertToArray(5, (o) => o.item === 2, arr, { reverse: true, after: false })).toBe(3);
454454
expect(arr).toEqual([1, 2, 3, 5, 2]);
455455

456456
// 插入多个个 动态位置
@@ -504,7 +504,7 @@ describe('array', function () {
504504
expect(chunk([0, 1, 2, 3, 4, 5, 6], 1)).toEqual([[0], [1], [2], [3], [4], [5], [6]]);
505505
expect(chunk([0, 1, 2, 3, 4, 5, 6], 0)).toEqual([0, 1, 2, 3, 4, 5, 6]);
506506
// 不支持-1
507-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
507+
508508
// @ts-expect-error
509509
expect(chunk([0, 1, 2, 3, 4, 5, 6], -1)).toEqual([0, 1, 2, 3, 4, 5, 6]);
510510
expect(chunk([0, 1, 2, 3, 4, 5, 6], 3)).toEqual([[0, 1, 2], [3, 4, 5], [6]]);
@@ -567,25 +567,25 @@ describe('array', function () {
567567
expect(
568568
groupBy(
569569
[
570-
{ type: 1, value: 111 },
571-
{ type: 2, value: 222 },
572-
{ type: 1, value: 222 },
573-
{ type: 2, value: 33344 },
574-
{ type: 1, value: 333 },
575-
{ type: 1, value: 444 },
570+
{ value: 111, type: 1 },
571+
{ value: 222, type: 2 },
572+
{ value: 222, type: 1 },
573+
{ value: 33344, type: 2 },
574+
{ value: 333, type: 1 },
575+
{ value: 444, type: 1 },
576576
],
577577
'type',
578578
),
579579
).toEqual({
580580
1: [
581-
{ type: 1, value: 111 },
582-
{ type: 1, value: 222 },
583-
{ type: 1, value: 333 },
584-
{ type: 1, value: 444 },
581+
{ value: 111, type: 1 },
582+
{ value: 222, type: 1 },
583+
{ value: 333, type: 1 },
584+
{ value: 444, type: 1 },
585585
],
586586
2: [
587-
{ type: 2, value: 222 },
588-
{ type: 2, value: 33344 },
587+
{ value: 222, type: 2 },
588+
{ value: 33344, type: 2 },
589589
],
590590
});
591591
expect(groupBy([], '')).toEqual({});
@@ -625,7 +625,7 @@ describe('array', function () {
625625
{ name: 'b', score: 90 },
626626
{ name: 'c', score: 70 },
627627
{ name: 'd', score: 10 },
628-
{ name: 'e', score: 100 },
628+
{ score: 100, name: 'e' },
629629
],
630630
(item) => {
631631
const score = item.score;
@@ -637,13 +637,13 @@ describe('array', function () {
637637
).toEqual({
638638
A: [
639639
{ name: 'b', score: 90 },
640-
{ name: 'e', score: 100 },
640+
{ score: 100, name: 'e' },
641641
],
642-
B: [{ name: 'c', score: 70 }],
643642
C: [
644643
{ name: 'a', score: 50 },
645644
{ name: 'd', score: 10 },
646645
],
646+
B: [{ name: 'c', score: 70 }],
647647
});
648648

649649
const b = groupBy([50, 90, 70, 10, 100], (score) => {
@@ -655,7 +655,7 @@ describe('array', function () {
655655

656656
const c = groupBy(
657657
[50, 90, 70, 10, 100],
658-
(score): 'A' | 'B' | void => {
658+
(score): void | 'A' | 'B' => {
659659
if (score >= 90) return 'A';
660660
if (score >= 60) return 'B';
661661
},
@@ -674,8 +674,8 @@ describe('array', function () {
674674
}),
675675
).toEqual({
676676
A: [90, 100],
677-
B: [70],
678677
C: [50, 10],
678+
B: [70],
679679
});
680680
expect(
681681
groupBy(
@@ -688,8 +688,8 @@ describe('array', function () {
688688
),
689689
).toEqual({
690690
A: [90, 100],
691-
B: [70],
692691
C: [50, 10],
692+
B: [70],
693693
});
694694

695695
const list = [
@@ -839,7 +839,7 @@ describe('array', function () {
839839
res.push(v);
840840
if (i[0] === 0 && i[1] === 0) return false;
841841
},
842-
{ startIndexes: [1, 4], startDirect: 'bottom' },
842+
{ startDirect: 'bottom', startIndexes: [1, 4] },
843843
);
844844
expect(res).toEqual([10, 15, 20, 25, 24, 23, 22, 21, 16, 11, 6, 1]);
845845

__tests__/base64.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {
2-
parseBase64,
32
arrayBufferToBase64,
43
base64ToArrayBuffer,
54
stringToArrayBuffer,
65
arrayBufferToString,
6+
parseBase64,
77
} from '../src';
88

99
describe('Base64', () => {

0 commit comments

Comments
 (0)