Skip to content

Commit c6bc021

Browse files
authored
Merge pull request #69 from takker99/arrow-function
♻️ Converted functions to arrow functions
2 parents 476d66d + 4bf8d8e commit c6bc021

18 files changed

+247
-221
lines changed

browser/dom/caret.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ interface ReactFiber {
4141
* @return カーソルと選択範囲の情報
4242
* @throws {Error} #text-inputとReact Componentの隠しpropertyが見つからなかった
4343
*/
44-
export function caret(): CaretInfo {
44+
export const caret = (): CaretInfo => {
4545
const textarea = textInput();
4646
if (!textarea) {
4747
throw Error(`#text-input is not found.`);
@@ -59,4 +59,4 @@ export function caret(): CaretInfo {
5959
return (textarea[
6060
reactKey
6161
] as ReactFiber).return.return.stateNode.props;
62-
}
62+
};

browser/dom/click.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ export interface ClickOptions {
1515
}
1616

1717
/** Emulate click event sequences */
18-
export async function click(
18+
export const click = async (
1919
element: HTMLElement,
2020
options: ClickOptions,
21-
): Promise<void> {
21+
): Promise<void> => {
2222
const mouseOptions: MouseEventInit = {
2323
button: options.button ?? 0,
2424
clientX: options.X,
@@ -37,17 +37,17 @@ export async function click(
3737
// ScrapboxのReactの処理が終わるまで少し待つ
3838
// 待ち時間は感覚で決めた
3939
await sleep(10);
40-
}
40+
};
4141

4242
export interface HoldDownOptions extends ClickOptions {
4343
holding?: number;
4444
}
4545

4646
/** Emulate long tap event sequence */
47-
export async function holdDown(
47+
export const holdDown = async (
4848
element: HTMLElement,
4949
options: HoldDownOptions,
50-
): Promise<void> {
50+
): Promise<void> => {
5151
const touch = new Touch({
5252
identifier: 0,
5353
target: element,
@@ -79,4 +79,4 @@ export async function holdDown(
7979
// ScrapboxのReactの処理が終わるまで少し待つ
8080
// 待ち時間は感覚で決めた
8181
await sleep(10);
82-
}
82+
};

browser/dom/edit.ts

Lines changed: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,58 @@ import { textInput } from "./dom.ts";
66
import { isArray, isNumber, isString } from "../../is.ts";
77
import { sleep } from "../../sleep.ts";
88

9-
export function undo(count = 1) {
9+
export const undo = (count = 1): void => {
1010
for (const _ of range(0, count)) {
1111
press("z", { ctrlKey: true });
1212
}
13-
}
14-
export function redo(count = 1) {
13+
};
14+
export const redo = (count = 1): void => {
1515
for (const _ of range(0, count)) {
1616
press("z", { shiftKey: true, ctrlKey: true });
1717
}
18-
}
18+
};
1919

20-
export function insertIcon(count = 1) {
20+
export const insertIcon = (count = 1): void => {
2121
for (const _ of range(0, count)) {
2222
press("i", { ctrlKey: true });
2323
}
24-
}
24+
};
2525

26-
export function insertTimestamp(index = 1) {
26+
export const insertTimestamp = (index = 1): void => {
2727
for (const _ of range(0, index)) {
2828
press("t", { altKey: true });
2929
}
30-
}
30+
};
3131

32-
export async function insertLine(lineNo: number, text: string) {
32+
export const insertLine = async (
33+
lineNo: number,
34+
text: string,
35+
): Promise<void> => {
3336
await goLine(lineNo);
3437
goHead();
3538
press("Enter");
3639
press("ArrowUp");
3740
await insertText(text);
38-
}
41+
};
3942

40-
export async function replaceLines(start: number, end: number, text: string) {
43+
export const replaceLines = async (
44+
start: number,
45+
end: number,
46+
text: string,
47+
): Promise<void> => {
4148
await goLine(start);
4249
goHead();
4350
for (const _ of range(start, end)) {
4451
press("ArrowDown", { shiftKey: true });
4552
}
4653
press("End", { shiftKey: true });
4754
await insertText(text);
48-
}
55+
};
4956

50-
export async function deleteLines(from: number | string | string[], count = 1) {
57+
export const deleteLines = async (
58+
from: number | string | string[],
59+
count = 1,
60+
): Promise<void> => {
5161
if (isNumber(from)) {
5262
if (getLineCount() === from + count) {
5363
await goLine(from - 1);
@@ -78,74 +88,74 @@ export async function deleteLines(from: number | string | string[], count = 1) {
7888
throw new TypeError(
7989
`The type of value must be number | string | string[] but actual is "${typeof from}"`,
8090
);
81-
}
91+
};
8292

83-
export function indentLines(count = 1) {
93+
export const indentLines = (count = 1): void => {
8494
for (const _ of range(0, count)) {
8595
press("ArrowRight", { ctrlKey: true });
8696
}
87-
}
88-
export function outdentLines(count = 1) {
97+
};
98+
export const outdentLines = (count = 1): void => {
8999
for (const _ of range(0, count)) {
90100
press("ArrowLeft", { ctrlKey: true });
91101
}
92-
}
93-
export function moveLines(count: number) {
102+
};
103+
export const moveLines = (count: number): void => {
94104
if (count > 0) {
95105
downLines(count);
96106
} else {
97107
upLines(-count);
98108
}
99-
}
109+
};
100110
// to行目の後ろに移動させる
101-
export function moveLinesBefore(from: number, to: number) {
111+
export const moveLinesBefore = (from: number, to: number): void => {
102112
const count = to - from;
103113
if (count >= 0) {
104114
downLines(count);
105115
} else {
106116
upLines(-count - 1);
107117
}
108-
}
109-
export function upLines(count = 1) {
118+
};
119+
export const upLines = (count = 1): void => {
110120
for (const _ of range(0, count)) {
111121
press("ArrowUp", { ctrlKey: true });
112122
}
113-
}
114-
export function downLines(count = 1) {
123+
};
124+
export const downLines = (count = 1): void => {
115125
for (const _ of range(0, count)) {
116126
press("ArrowDown", { ctrlKey: true });
117127
}
118-
}
128+
};
119129

120-
export function indentBlocks(count = 1) {
130+
export const indentBlocks = (count = 1): void => {
121131
for (const _ of range(0, count)) {
122132
press("ArrowRight", { altKey: true });
123133
}
124-
}
125-
export function outdentBlocks(count = 1) {
134+
};
135+
export const outdentBlocks = (count = 1): void => {
126136
for (const _ of range(0, count)) {
127137
press("ArrowLeft", { altKey: true });
128138
}
129-
}
130-
export function moveBlocks(count: number) {
139+
};
140+
export const moveBlocks = (count: number): void => {
131141
if (count > 0) {
132142
downBlocks(count);
133143
} else {
134144
upBlocks(-count);
135145
}
136-
}
137-
export function upBlocks(count = 1) {
146+
};
147+
export const upBlocks = (count = 1): void => {
138148
for (const _ of range(0, count)) {
139149
press("ArrowUp", { altKey: true });
140150
}
141-
}
142-
export function downBlocks(count = 1) {
151+
};
152+
export const downBlocks = (count = 1): void => {
143153
for (const _ of range(0, count)) {
144154
press("ArrowDown", { altKey: true });
145155
}
146-
}
156+
};
147157

148-
export async function insertText(text: string) {
158+
export const insertText = async (text: string): Promise<void> => {
149159
const cursor = textInput();
150160
if (!cursor) {
151161
throw Error("#text-input is not ditected.");
@@ -156,4 +166,4 @@ export async function insertText(text: string) {
156166
const event = new InputEvent("input", { bubbles: true });
157167
cursor.dispatchEvent(event);
158168
await sleep(1); // 待ち時間は感覚で決めた
159-
}
169+
};

browser/dom/isHeightViewable.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/// <reference lib="esnext"/>
33
/// <reference lib="dom" />
44

5-
export function isHeightViewable(element: HTMLElement) {
5+
export const isHeightViewable = (element: HTMLElement): boolean => {
66
const { top, bottom } = element.getBoundingClientRect();
77
return top >= 0 && bottom <= window.innerHeight;
8-
}
8+
};

0 commit comments

Comments
 (0)