-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1a12647
commit 10d5d33
Showing
4 changed files
with
96 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"cSpell.words": ["vocabphrase"] | ||
"cSpell.words": ["anikilot", "vocabphrase"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { fileType } from "@/@types/fileType"; | ||
import { uuidv7 as createUUID } from "uuidv7"; | ||
|
||
export function csvToFileContent( | ||
csv: string[][], | ||
mode?: "en-ja" | "ja-en" | ||
): fileType["content"] { | ||
const lines = csv[1].length; | ||
if (!mode) mode = isEnglish(csv[1][lines % 2]) ? "en-ja" : "ja-en"; | ||
let fileContent: fileType["content"]; | ||
if (lines === 2) { | ||
fileContent = csv.map((line) => ({ | ||
id: createUUID(), | ||
en: line[mode === "en-ja" ? 0 : 1], | ||
ja: line[mode === "ja-en" ? 0 : 1], | ||
})); | ||
} else if (lines === 3) { | ||
fileContent = csv.map((line) => ({ | ||
id: createUUID(), | ||
en: line[mode === "en-ja" ? 0 : 1], | ||
ja: line[mode === "ja-en" ? 0 : 1], | ||
hint: line[2], | ||
})); | ||
} else if (lines === 4) { | ||
fileContent = csv.map((line) => ({ | ||
id: createUUID(), | ||
en: `${line[mode === "en-ja" ? 0 : 1]} ${ | ||
line[mode === "en-ja" ? 2 : 3] ? `(${[mode === "en-ja" ? 2 : 3]})` : `` | ||
}`, | ||
ja: `${line[mode === "ja-en" ? 0 : 1]}${ | ||
line[mode === "ja-en" ? 2 : 3] ? `(${[mode === "ja-en" ? 2 : 3]})` : `` | ||
}`, | ||
})); | ||
} else if (lines === 5) { | ||
fileContent = csv.map((line) => ({ | ||
id: createUUID(), | ||
en: `${line[mode === "en-ja" ? 1 : 2]} ${ | ||
line[mode === "en-ja" ? 3 : 4] ? `(${[mode === "en-ja" ? 3 : 4]})` : `` | ||
}`, | ||
ja: `${line[mode === "ja-en" ? 1 : 2]}${ | ||
line[mode === "ja-en" ? 3 : 4] ? `(${[mode === "ja-en" ? 3 : 4]})` : `` | ||
}`, | ||
})); | ||
} else throw new Error("ファイル形式が不正です"); | ||
return fileContent; | ||
} | ||
export function isEnglish(text: string) { | ||
/** | ||
* 英語の判定(unicode上で225以上の数が入っていないか) | ||
* @param text 判定する文字列 | ||
*/ | ||
return !text.split("").some((char) => char.charCodeAt(0) >= 225); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters