thai-typo-check
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -1,4 +0,4 @@ | ||
declare function thaiTypoCheck(inputText: string, dict: string[]): boolean; | ||
declare function thaiTypoCheck(inputText: string): boolean; | ||
declare namespace thaiTypoCheck {} | ||
export = thaiTypoCheck; |
13
index.js
const wordBreak = require("word-break-trie"); | ||
const trie = require("trie-prefix-tree"); | ||
const fileSync = require("fs"); | ||
@@ -17,8 +18,14 @@ const THAI_REGEX = /([\u0E00-\u0E7F]{2,})/; | ||
function thaiTypoCheck(inputText, dict) { | ||
function thaiTypoCheck(inputText) { | ||
// return true when input is empty string, null, or undefined | ||
if (!inputText) return true; | ||
const longestWordLength = dict[0].length; | ||
const currentTrie = trie(dict); | ||
const dict = fileSync.readFileSync("./dictionary/dict.txt", { | ||
encoding: "UTF-8" | ||
}); | ||
const dictArray = dict.split("\n"); | ||
const longestWordLength = dictArray[0].length; | ||
const currentTrie = trie(dictArray); | ||
const inputs = sentenceSplit(correctContent(inputText)); | ||
@@ -25,0 +32,0 @@ |
{ | ||
"name": "thai-typo-check", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "for check thai typo", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -11,6 +11,7 @@ # thai-typo-check | ||
test("thaiTypoCheck", () => { | ||
const input = "ฉันอยากกินข้าว"; | ||
const dict = ["อยาก", "ข้าว", "มาก", "กิน", "ฉัน"]; | ||
expect(thaiTypoCheck(input, dict).toBe(true)); | ||
const wordBreakableInput = "ฉันอยากกินยำ"; | ||
const wordUnBreakableInput = "ฉันอยากกินผฟใก่ร์"; | ||
expect(thaiTypoCheck(wordBreakableInput).toBe(true)); | ||
expect(thaiTypoCheck(wordUnBreakableInput).toBe(false)); | ||
}); | ||
``` |
16
test.js
const thaiTypoCheck = require("."); | ||
describe("thaiTypoCheck", () => { | ||
const dict = ["อยาก", "ข้าว", "มาก", "กิน", "ฉัน"]; | ||
it("should return true when no typo", () => { | ||
expect(thaiTypoCheck("ฉันอยากกินข้าว", dict)).toBe(true); | ||
expect(thaiTypoCheck("ฉัน อยากกิน ข้าว", dict)).toBe(true); | ||
expect(thaiTypoCheck("ฉันอยากกินยำ")).toBe(true); | ||
expect(thaiTypoCheck("ฉัน อยากกิน ยำ")).toBe(true); | ||
}); | ||
it("should return false when found typos", () => { | ||
expect(thaiTypoCheck("ฉนอยากกินข้าว", dict)).toBe(false); | ||
expect(thaiTypoCheck("ฉันอยากกินข้าววว", dict)).toBe(false); | ||
expect(thaiTypoCheck("ฉนอยากกินยำ")).toBe(false); | ||
expect(thaiTypoCheck("ฉันอยากกินยำา")).toBe(false); | ||
}); | ||
it("should skip and return true when inputText is null or empty", () => { | ||
expect(thaiTypoCheck("", dict)).toBe(true); | ||
expect(thaiTypoCheck(null, dict)).toBe(true); | ||
expect(thaiTypoCheck(undefined, dict)).toBe(true); | ||
expect(thaiTypoCheck("")).toBe(true); | ||
expect(thaiTypoCheck(null)).toBe(true); | ||
expect(thaiTypoCheck(undefined)).toBe(true); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
856964
6
53
17
1