Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
m80126colin committed Sep 7, 2020
2 parents 1318868 + 9c44d72 commit 8e74c58
Show file tree
Hide file tree
Showing 14 changed files with 158 additions and 1,582 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
dist/
dist/
test-dist/
10 changes: 10 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
data/
lib/
test/
webpack/

node_modules/
test-dist/

webpack.config.js
tsconfig.*
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ hakka.inspect('來去')

``` js
[
Inspector {
UniHakkaInspector {
position: [ 0, 2 ],
original: '',
code: 'e72c',
Expand All @@ -63,14 +63,19 @@ hakka.inspect('來去')
* 教育部《臺灣客家語常用詞辭典》
* 客家委員會 2009 年《客語造字檔內碼表》
* 客家委員會《客語能力認證基本詞彙》
* 2011-2019 年全國語文競賽客家語朗讀
* 20112019 年全國語文競賽客家語朗讀

## References 參考資料

* [CHISE IDS 漢字検索](http://www.chise.org/ids-find)
* [CNS11643 中文全字庫](https://www.cns11643.gov.tw/index.jsp)
* [本土語言外字表 - 再會豆腐字](https://tauhu.tw/gua-ji-pio/)

## Contributers 貢獻者

* [Hsu Subang](https://github.com/m80126colin)
* [David Kuo](https://github.com/david50407)

## License 授權

MIT
34 changes: 0 additions & 34 deletions babel.config.json

This file was deleted.

6 changes: 6 additions & 0 deletions lib/@typings/tsv.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
declare module '*.tsv' {
import { UniHakkaTSVRow } from '@/lib/types'

const data : UniHakkaTSVRow[];
export default data;
}
5 changes: 2 additions & 3 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { formatTSV } from './tool';
import {
UniHakkaInspector,
UniHakkaInspectorOptions
Expand Down Expand Up @@ -36,14 +35,14 @@ class UniHakka {
hakka.unicodeToCNS11643 = new Map()
hakka.puaInfo = new Map()
// process table.tsv
const [ x, ...tableRows ] = formatTSV(table)
const [ x, ...tableRows ] = table
tableRows.map(({ pua, unicode, description }) => {
hakka.puaToUnicode.set(pua, unicode)
hakka.unicodeToCNS11643.set(unicode, unicode)
hakka.puaInfo.set(pua, description)
})
// process cns11643.tsv
const [ y, ...cnsRows ] = formatTSV(cns)
const [ y, ...cnsRows ] = cns
cnsRows.map(({ pua, unicode, description }) => {
hakka.puaToUnicode.set(pua, unicode)
hakka.unicodeToCNS11643.set(unicode, pua)
Expand Down
9 changes: 0 additions & 9 deletions lib/tool.ts

This file was deleted.

4 changes: 0 additions & 4 deletions lib/tsv.d.ts

This file was deleted.

29 changes: 11 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
{
"name": "@m80126colin/uni-hakka",
"version": "0.3.0",
"version": "0.3.1",
"description": "Convert Hakka characters from PUA to Unicode.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"author": "Hsu Subang<m80126colin@gmail.com>",
"license": "MIT",
"scripts": {
"clean": "rm -rf dist/",
"prebuild": "yarn clean",
"build": "BABEL_ENV=production webpack && tsc",
"clean": "yarn clean:test && yarn clean:build",
"clean:test": "rm -rf test-dist/",
"clean:build": "rm -rf dist/",
"prebuild": "yarn clean:build",
"build": "PROJ_ENV=production webpack",
"prepublish": "yarn build",
"test": "BABEL_ENV=development babel-node --extensions '.ts' test/"
"pretest": "yarn clean:test",
"test": "PROJ_ENV=development webpack && node test-dist/index.js"
},
"repository": {
"type": "git",
Expand All @@ -24,23 +28,12 @@
"registry": "https://npm.pkg.github.com/"
},
"devDependencies": {
"@babel/cli": "^7.10.5",
"@babel/core": "^7.11.4",
"@babel/node": "^7.10.5",
"@babel/plugin-proposal-class-properties": "^7.10.4",
"@babel/preset-env": "^7.11.0",
"@babel/preset-typescript": "^7.10.4",
"@types/node": "^14.6.2",
"babel-loader": "^8.1.0",
"babel-plugin-module-resolver": "^4.0.0",
"babel-plugin-transform-import-to-read-file-sync": "^0.2.2",
"raw-loader": "^4.0.1",
"terser-webpack-plugin": "^4.1.0",
"ts-loader": "^8.0.3",
"tsconfig-paths-webpack-plugin": "^3.3.0",
"typescript": "^4.0.2",
"webpack": "^4.44.1",
"webpack-cli": "^3.3.12"
},
"dependencies": {
"@babel/polyfill": "^7.10.4"
}
}
15 changes: 15 additions & 0 deletions tsconfig.dev.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"include": ["lib/**/*"],
"exclude": ["node_modules"],
"compilerOptions": {
"noImplicitAny": true,
"esModuleInterop": true,
"sourceMap": true,
"module": "commonjs",
"target": "es6",
"baseUrl": ".",
"paths": {
"@/*": ["./*"]
}
}
}
2 changes: 1 addition & 1 deletion tsconfig.json → tsconfig.prod.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"include": ["lib/**/*"],
"exclude": ["node_modules"],
"compilerOptions": {
"noImplicitAny": true,
"esModuleInterop": true,
"module": "commonjs",
"target": "es6",
"declaration": true,
"emitDeclarationOnly": true,
"outDir": "dist",
"baseUrl": ".",
"paths": {
Expand Down
38 changes: 32 additions & 6 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,42 @@
const path = require('path');
const TerserPlugin = require('terser-webpack-plugin');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');

let mode = 'production';
let entry = './lib/index.ts';
let outputPath = path.resolve(__dirname, 'dist');
let configFile = path.resolve(__dirname, 'tsconfig.prod.json');
let devtool = false;

if ('development' === process.env.PROJ_ENV) {
mode = 'development';
entry = './test/index.ts';
outputPath = path.resolve(__dirname, 'test-dist');
configFile = path.resolve(__dirname, 'tsconfig.dev.json');
devtool = 'source-map';
}

module.exports = {
entry: './lib/index.ts',
mode: "production",
entry: entry,
mode: mode,
devtool: devtool,
output: {
path: path.resolve(__dirname, 'dist'),
path: outputPath,
library: '@m80126colin/uni-hakka',
libraryTarget: 'commonjs2',
filename: 'index.js'
},
resolve: {
extensions: ['.ts']
extensions: ['.ts', '.tsv'],
plugins: [
new TsconfigPathsPlugin({ configFile: configFile })
]
},
resolveLoader: {
modules: [
path.resolve(__dirname, 'webpack/loaders'),
'node_modules',
],
},
optimization: {
minimizer: [
Expand All @@ -28,14 +53,15 @@ module.exports = {
{
test: /\.tsv$/,
use: {
loader: 'raw-loader'
loader: 'pua-tsv-loader'
}
},
{
test: /\.ts$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
loader: 'ts-loader',
options: { configFile: configFile }
}
}
]
Expand Down
11 changes: 11 additions & 0 deletions webpack/loaders/pua-tsv-loader/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Use node syntax here

module.exports = function(data) {
const rows = data.split(/\r?\n/)
.map(line => line.trim().split('\t'))
.map(([ pua, unicode, description ]) => ({ pua, unicode, description }))

return `export default ${JSON.stringify(rows, null)
.replace(/\u2028/g, '\\u2028')
.replace(/\u2029/g, '\\u2029')}`
}
Loading

0 comments on commit 8e74c58

Please sign in to comment.