Skip to content

Commit a5f735a

Browse files
committed
isSimpleCodeFile()を別ファイルへ分離
1 parent 7116444 commit a5f735a

File tree

4 files changed

+19
-18
lines changed

4 files changed

+19
-18
lines changed

browser/websocket/updateCodeFile.test.ts renamed to browser/websocket/isSimpleCodeFile.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
/// <reference lib="deno.ns" />
2-
31
import { assert, assertFalse } from "../../deps/testing.ts";
4-
import { isSimpleCodeFile, SimpleCodeFile } from "./updateCodeFile.ts";
2+
import { isSimpleCodeFile } from "./isSimpleCodeFile.ts";
3+
import { SimpleCodeFile } from "./updateCodeFile.ts";
54

65
const codeFile: SimpleCodeFile = {
76
filename: "filename",
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { SimpleCodeFile } from "./updateCodeFile.ts";
2+
3+
/** objectがSimpleCodeFile型かどうかを判別する */
4+
export function isSimpleCodeFile(obj: unknown): obj is SimpleCodeFile {
5+
if (Array.isArray(obj) || !(obj instanceof Object)) return false;
6+
const code = obj as SimpleCodeFile;
7+
const { filename, content, lang } = code;
8+
return (
9+
typeof filename == "string" &&
10+
(typeof content == "string" ||
11+
(Array.isArray(content) &&
12+
(content.length == 0 || typeof content[0] == "string"))) &&
13+
(typeof lang == "string" || lang === undefined)
14+
);
15+
}

browser/websocket/updateCodeBlock.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import {
99
import { TinyCodeBlock } from "../../rest/getCodeBlocks.ts";
1010
import { diffToChanges } from "./diffToChanges.ts";
1111
import { getUserId } from "./id.ts";
12+
import { isSimpleCodeFile } from "./isSimpleCodeFile.ts";
1213
import { pull } from "./pull.ts";
13-
import { isSimpleCodeFile, SimpleCodeFile } from "./updateCodeFile.ts";
14+
import { SimpleCodeFile } from "./updateCodeFile.ts";
1415
import {
1516
applyCommit,
1617
countBodyIndent,

browser/websocket/updateCodeFile.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,6 @@ export interface UpdateCodeFileOptions {
4545
debug?: boolean;
4646
}
4747

48-
/** objectがSimpleCodeFile型かどうかを判別する */
49-
export function isSimpleCodeFile(obj: unknown): obj is SimpleCodeFile {
50-
if (Array.isArray(obj) || !(obj instanceof Object)) return false;
51-
const code = obj as SimpleCodeFile;
52-
const { filename, content, lang } = code;
53-
return (
54-
typeof filename == "string" &&
55-
(typeof content == "string" ||
56-
(Array.isArray(content) &&
57-
(content.length == 0 || typeof content[0] == "string"))) &&
58-
(typeof lang == "string" || lang === undefined)
59-
);
60-
}
61-
6248
/** REST API経由で取得できるようなコードファイルの中身をまるごと書き換える
6349
*
6450
* ファイルが存在していなかった場合、既定では何も書き換えない \

0 commit comments

Comments
 (0)