-
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.
transform data before insert to supabase
- Loading branch information
Showing
10 changed files
with
92 additions
and
30 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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,32 @@ | ||
export const transform = (content: string) => { | ||
return content.split("\n").reduce( | ||
(p, c) => { | ||
// console.log("p", p); | ||
// console.log("c", c.split(":")); | ||
const [k, v] = c.split(":"); | ||
return { ...p, [key(k)]: v.trim() }; | ||
}, | ||
{ | ||
thai: "", | ||
english: "", | ||
type: "", | ||
example: "", | ||
remark: "", | ||
} | ||
); | ||
}; | ||
|
||
const key = (k: string) => { | ||
switch (k.replace("-", "").trim()) { | ||
case "แปลเป็นภาษาไทย": | ||
return "thai"; | ||
case "คำอ่านในภาษาอังกฤษ": | ||
return "english"; | ||
case "ประเภทของคำ": | ||
return "type"; | ||
case "ตัวอย่างประโยคในภาษาอังกฤษ": | ||
return "example"; | ||
default: | ||
return "remark"; | ||
} | ||
}; |
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,16 @@ | ||
import { assertEquals } from "jsr:@std/assert"; | ||
import { transform } from "../libs/utils/common/transform.ts"; | ||
|
||
Deno.test("transform", () => { | ||
const input = `- แปลเป็นภาษาไทย: บรรพบุรุษ, สิ่งที่มาก่อน\n- คำอ่านในภาษาอังกฤษ: แอน-ติ-ซี-เดนท์\n- ประเภทของคำ: คำนาม (Noun)\n- ตัวอย่างประโยคในภาษาอังกฤษ: In grammar, the noun "dog" is the antecedent of the pronoun "it" in the sentence "The dog chased its tail."`; | ||
const result = transform(input); | ||
console.log("result", result); | ||
assertEquals(result, { | ||
thai: "บรรพบุรุษ, สิ่งที่มาก่อน", | ||
english: "แอน-ติ-ซี-เดนท์", | ||
type: "คำนาม (Noun)", | ||
example: | ||
'In grammar, the noun "dog" is the antecedent of the pronoun "it" in the sentence "The dog chased its tail."', | ||
remark: "", | ||
}); | ||
}); |