Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

thai-typo-check

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

thai-typo-check - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

dictionary/dict.txt

2

index.d.ts

@@ -1,4 +0,4 @@

declare function thaiTypoCheck(inputText: string, dict: string[]): boolean;
declare function thaiTypoCheck(inputText: string): boolean;
declare namespace thaiTypoCheck {}
export = thaiTypoCheck;
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));
});
```
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);
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc