-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add bundler and linter * Update opencc-data to 1.0.5 * Remove old speed test * Add linter to check * Update README * Update documentation
- Loading branch information
Showing
15 changed files
with
1,969 additions
and
396 deletions.
There are no files selected for viewing
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,17 @@ | ||
module.exports = { | ||
env: { | ||
browser: true, | ||
es2021: true, | ||
node: true, | ||
}, | ||
extends: [ | ||
'airbnb-base', | ||
], | ||
parserOptions: { | ||
ecmaVersion: 12, | ||
sourceType: 'module', | ||
}, | ||
rules: { | ||
'no-restricted-syntax': ['error', 'ForInStatement', 'LabeledStatement', 'WithStatement'], | ||
}, | ||
}; |
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 |
---|---|---|
@@ -1,33 +1,25 @@ | ||
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created | ||
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages | ||
|
||
name: Node.js Package | ||
|
||
on: | ||
release: | ||
types: [created] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v1 | ||
with: | ||
node-version: 14 | ||
- run: npm ci | ||
- run: npm test | ||
|
||
publish-npm: | ||
needs: build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v1 | ||
with: | ||
node-version: 14 | ||
registry-url: https://registry.npmjs.org/ | ||
- run: npm ci | ||
- run: npm publish | ||
env: | ||
NODE_AUTH_TOKEN: ${{secrets.npm_token}} | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v1 | ||
with: | ||
node-version: 14 | ||
registry-url: https://registry.npmjs.org/ | ||
- name: Install bundler | ||
run: npm install -g rollup | ||
- name: Install dependencies | ||
run: npm ci | ||
- name: Bundle | ||
run: npm run bundle | ||
- name: Publish | ||
run: npm publish | ||
env: | ||
NODE_AUTH_TOKEN: ${{secrets.npm_token}} |
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 |
---|---|---|
|
@@ -2,3 +2,5 @@ node_modules | |
|
||
/test/神雕侠侣.txt | ||
/test/天龙八部.txt | ||
|
||
/bundle.js |
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 |
---|---|---|
|
@@ -4,10 +4,10 @@ Pure JavaScript implementation of OpenCC | |
|
||
## Import | ||
|
||
In HTML file: | ||
In HTML: | ||
|
||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected].6"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected].7"></script> | ||
``` | ||
|
||
Or in Node.js: | ||
|
@@ -19,7 +19,6 @@ const OpenCC = require('opencc-js'); | |
## Usage | ||
|
||
```javascript | ||
|
||
OpenCC.Converter('hk', 'cn') // Traditional Chinese (Hong Kong) to Simplified Chinese | ||
.then(convert => console.log(convert('漢字,簡體字'))); // output: 汉字,简体字 | ||
``` | ||
|
@@ -33,25 +32,31 @@ The first argument is the source type, the second argument is the destination ty | |
- Simplified Chinese (Mainland China):`cn` | ||
- Japanese _Shinjitai_:`jp` | ||
|
||
Trad (Hong Kong, with Hong Kong phrases) is currently not supported. | ||
Traditional Chinese (Hong Kong, with Hong Kong phrases) is currently not supported. | ||
|
||
## Custom Converter | ||
|
||
```javascript | ||
const convert = OpenCC.CustomConverter({ '香蕉': '🍌️', '蘋果': '🍎️', '梨': '🍐️' }); | ||
console.log(convert('香蕉蘋果梨')); // output: 🍌️🍎️🍐️ | ||
const dict = { | ||
'香蕉': 'banana', | ||
'蘋果': 'apple', | ||
'梨': 'pear', | ||
}; | ||
const convert = OpenCC.CustomConverter(dict); | ||
console.log(convert('香蕉 蘋果 梨')); | ||
// outputs: banana apple pear | ||
``` | ||
|
||
## DOM operation | ||
|
||
```javascript | ||
(async () => { | ||
const convert = await OpenCC.Converter('hk', 'cn'); | ||
const startNode = document.documentElement; // Convert the whole page | ||
const HTMLConvertHandler = OpenCC.HTMLConverter(convert, startNode, 'zh-HK', 'zh-CN'); // Convert all zh-HK to zh-CN | ||
HTMLConvertHandler.convert(); // Start conversion | ||
HTMLConvertHandler.restore(); // Restore | ||
})() | ||
((async () => { | ||
const convert = await OpenCC.Converter('hk', 'cn'); | ||
const startNode = document.documentElement; // Convert the whole page | ||
const HTMLConvertHandler = OpenCC.HTMLConverter(convert, startNode, 'zh-HK', 'zh-CN'); // Convert all zh-HK to zh-CN | ||
HTMLConvertHandler.convert(); // Start conversion | ||
HTMLConvertHandler.restore(); // Restore | ||
})()); | ||
``` | ||
|
||
The conversion is skipped if the class list of a node contains `ignore-opencc`. All child nodes of the node will not be converted. |
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 |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
在 HTML 中引入: | ||
|
||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected].6"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected].7"></script> | ||
``` | ||
|
||
或在 Node.js 中引入: | ||
|
@@ -39,20 +39,26 @@ OpenCC.Converter('hk', 'cn') // 香港繁體轉簡體 | |
## 自訂轉換器 | ||
|
||
```javascript | ||
const convert = OpenCC.CustomConverter({ '香蕉': '🍌️', '蘋果': '🍎️', '梨': '🍐️' }); | ||
console.log(convert('香蕉蘋果梨')); // output: 🍌️🍎️🍐️ | ||
const dict = { | ||
'香蕉': 'banana', | ||
'蘋果': 'apple', | ||
'梨': 'pear', | ||
}; | ||
const convert = OpenCC.CustomConverter(dict); | ||
console.log(convert('香蕉 蘋果 梨')); | ||
// outputs: banana apple pear | ||
``` | ||
|
||
## DOM 操作 | ||
|
||
```javascript | ||
(async () => { | ||
const convert = await OpenCC.Converter('hk', 'cn'); | ||
const startNode = document.documentElement; // 轉換整個頁面 | ||
const HTMLConvertHandler = OpenCC.HTMLConverter(convert, startNode, 'zh-HK', 'zh-CN'); // 將所有 zh-HK 標籤轉為 zh-CN 標籤 | ||
HTMLConvertHandler.convert(); // 開始轉換 | ||
HTMLConvertHandler.restore(); // 回到原貌 | ||
})() | ||
((async () => { | ||
const convert = await OpenCC.Converter('hk', 'cn'); | ||
const startNode = document.documentElement; // 轉換整個頁面 | ||
const HTMLConvertHandler = OpenCC.HTMLConverter(convert, startNode, 'zh-HK', 'zh-CN'); // 將所有 zh-HK 標籤轉為 zh-CN 標籤 | ||
HTMLConvertHandler.convert(); // 開始轉換 | ||
HTMLConvertHandler.restore(); // 回到原貌 | ||
})()); | ||
``` | ||
|
||
class list 包含 `ignore-opencc` 的元素會跳過後續的轉換,該節點的所有子節點都不會被轉換。 |
Oops, something went wrong.