commit
7c0f09a210
File diff suppressed because one or more lines are too long
|
@ -28,12 +28,13 @@
|
|||
"build:draw": "webpack --config webpack-config/build.plugin.js --env.pluginname=draw",
|
||||
"build:idiom": "webpack --config webpack-config/build.plugin.js --env.pluginname=idiom",
|
||||
"build:xhy": "webpack --config webpack-config/build.plugin.js --env.pluginname=xhy",
|
||||
"build:radical": "webpack --config webpack-config/build.plugin.js --env.pluginname=radical",
|
||||
"build:all": "webpack --config webpack-config/build.plugin.js --env.pluginname=all",
|
||||
"build:plugin": "npm run build:poly && npm run build:order && npm run build:trad && npm run build:draw && npm run build:idiom && npm run build:xhy && npm run build:all",
|
||||
"build:plugin": "npm run build:poly && npm run build:order && npm run build:trad && npm run build:draw && npm run build:idiom && npm run build:xhy && npm run build:radical && npm run build:all",
|
||||
"build:npm": "node ./helper/build-npm.js",
|
||||
"start": "webpack-dev-server --open --config webpack-config/dev.js",
|
||||
"dev": "webpack-dev-server --open --config webpack-config/dev.js",
|
||||
"publish": "npm publish npm/cnchar && npm publish npm/order && npm publish npm/poly && npm publish npm/trad && npm publish npm/draw && npm publish npm/idiom && npm publish npm/xhy && npm publish npm/all && npm publish npm/hanzi-util-base && npm publish npm/hanzi-util",
|
||||
"publish": "npm publish npm/cnchar && npm publish npm/order && npm publish npm/poly && npm publish npm/trad && npm publish npm/draw && npm publish npm/idiom && npm publish npm/xhy && npm publish npm/radical && npm publish npm/all && npm publish npm/hanzi-util-base && npm publish npm/hanzi-util",
|
||||
"lint": "eslint src --ext js",
|
||||
"test": "node test",
|
||||
"test:npm": "node test npm",
|
||||
|
|
|
@ -5,5 +5,6 @@ var poly = require('../poly');
|
|||
var draw = require('../draw');
|
||||
var idiom = require('../idiom');
|
||||
var xhy = require('../xhy');
|
||||
cnchar.use(order, trad, poly, draw, idiom, xhy);
|
||||
var radical = require('../radical');
|
||||
cnchar.use(order, trad, poly, draw, idiom, xhy, radical);
|
||||
module.exports = cnchar;
|
|
@ -0,0 +1,25 @@
|
|||
const radicals = require('./radicals.json');
|
||||
|
||||
function main(cnchar) {
|
||||
if (cnchar.plugins.indexOf('radical') !== -1) {
|
||||
return;
|
||||
}
|
||||
cnchar.plugins.push('radical');
|
||||
cnchar.radical = radical;
|
||||
}
|
||||
|
||||
function init(cnchar) {
|
||||
if (typeof window === 'object' && window.CnChar) {
|
||||
main(window.CnChar);
|
||||
} else if (typeof cnchar !== 'undefined') {
|
||||
main(cnchar);
|
||||
}
|
||||
}
|
||||
|
||||
function radical(char) {
|
||||
return radicals[char];
|
||||
}
|
||||
|
||||
init();
|
||||
|
||||
module.exports = init;
|
|
@ -0,0 +1,58 @@
|
|||
function buildData() {
|
||||
const { createReadStream, promises: fsPromises } = require('fs');
|
||||
const { join } = require('path');
|
||||
const { createInterface } = require('readline');
|
||||
const wordRegex = /"word": "(?<word>.*)"/;
|
||||
const radicalsRegex = /"radicals": "(?<radicals>.*)"/;
|
||||
// https://raw.githubusercontent.com/pwxcoo/chinese-xinhua/master/data/word.json
|
||||
const inputPath = join(__dirname, 'word.json');
|
||||
const outputPath = join(__dirname, 'radicals.json');
|
||||
return new Promise((resolve, reject) => {
|
||||
const words = new Map();
|
||||
let word = null;
|
||||
let radicals = null;
|
||||
const readStream = createReadStream(inputPath, {
|
||||
encoding: 'utf8',
|
||||
autoClose: true,
|
||||
emitClose: true,
|
||||
});
|
||||
const readLine = createInterface({ input: readStream });
|
||||
readStream.on('error', (err) => reject(err));
|
||||
readLine.on('close', () => resolve(words));
|
||||
readLine.on('line', (line) => {
|
||||
let matches = wordRegex.exec(line);
|
||||
if (matches && matches.groups) {
|
||||
word = matches.groups.word;
|
||||
radicals = null;
|
||||
} else {
|
||||
matches = radicalsRegex.exec(line);
|
||||
if (matches && matches.groups) {
|
||||
radicals = matches.groups.radicals;
|
||||
if (word && word.length > 0 && radicals && radicals.length > 0) {
|
||||
words.set(word, radicals);
|
||||
}
|
||||
word = null;
|
||||
radicals = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
}).then(async (words) => {
|
||||
const output = await fsPromises.open(outputPath, 'w');
|
||||
await output.write('{\n');
|
||||
let first = true;
|
||||
for (const [word, radicals] of words) {
|
||||
if (first) {
|
||||
first = false;
|
||||
await output.write(` "${word}": "${radicals}"`);
|
||||
} else {
|
||||
await output.write(`,\n "${word}": "${radicals}"`);
|
||||
}
|
||||
}
|
||||
await output.write('\n}\n');
|
||||
});
|
||||
}
|
||||
|
||||
buildData().then(
|
||||
() => console.log('完成'),
|
||||
(err) => console.error(err)
|
||||
);
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue