Skip to content

Commit

Permalink
Added check against empty input
Browse files Browse the repository at this point in the history
  • Loading branch information
andreihar committed May 1, 2024
1 parent 7630833 commit 1b8155e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 22 deletions.
21 changes: 5 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 15 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "taibun",
"version": "0.0.1",
"version": "1.0.0",
"description": "Taiwanese Hokkien Transliterator and Tokeniser",
"main": "taibun/index.js",
"scripts": {
Expand All @@ -10,8 +10,21 @@
"type": "git",
"url": "git+https://github.com/andreihar/taibun.js.git"
},
"files": [
"taibun/**/*",
"LICENSE",
"README.md"
],
"keywords": [
"hokkien"
"taiwan",
"taiwanese",
"taigi",
"hokkien",
"romanization",
"transliteration",
"transliterator",
"tokenization",
"tokenizer"
],
"author": "Andrei Harbachov",
"license": "MIT",
Expand Down
20 changes: 16 additions & 4 deletions taibun/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
const fs = require('fs');
const path = require('path');
let wordDict, tradDict;

if (typeof window === 'undefined') {
// Node js
const fs = require('fs');
const path = require('path');
wordDict = JSON.parse(fs.readFileSync(path.join(__dirname, 'data/words.json'), 'utf8'));
tradDict = JSON.parse(fs.readFileSync(path.join(__dirname, 'data/simplified.json'), 'utf8'));
} else {
// Browser
wordDict = require('./data/words.json');
tradDict = require('./data/simplified.json');
}

const wordDict = JSON.parse(fs.readFileSync(path.join(__dirname, 'data/words.json'), 'utf8'));
const tradDict = JSON.parse(fs.readFileSync(path.join(__dirname, 'data/simplified.json'), 'utf8'));
const simplifiedDict = Object.entries(tradDict).reduce((acc, [k, v]) => ({ ...acc, [v]: k }), { '臺': '台' });

// Helper to check if the character is a Chinese character
Expand Down Expand Up @@ -66,6 +75,9 @@ class Converter {

// Convert tokenised text into specified transliteration system
get(input) {
if (!input.trim()) {
return "";
}
let converted = new (require('./index.js').Tokeniser)().tokenise(toTraditional(input));
converted = this.toneSandhiPosition(converted).map(i => this.convertTokenised(i).trim()).join(' ').trim();
if (this.punctuation === 'format') {
Expand Down

0 comments on commit 1b8155e

Please sign in to comment.