1 Star 0 Fork 92

同名自定义/cnchar

forked from theajack/cnchar 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
tool.js 1.42 KB
一键复制 编辑 原始数据 按行查看 历史
theajack 提交于 2021-12-17 12:03 . feat: 3.0.5
const fs = require('fs');
const childProcess = require('child_process');
const plugins = [
'poly',
'order',
'trad',
'draw',
'idiom',
'xhy',
'radical',
];
const allPackage = 'all';
const mainPackage = 'main';
const npmPackage = 'npm';
const types = 'types';
const utils = ['hanzi-util', 'hanzi-util-base'];
function read (file, cb) {
fs.readFile(file, 'utf8', (err, code) => {
if (err) throw err;
cb(code);
});
}
function write (file, txt, cb) {
fs.writeFile(file, txt, 'utf8', (err) => {
if (err) throw err;
if (cb)cb();
});
}
function pick ({data = {}, target, attrs}) {
if (!attrs) {
attrs = Object.keys(target);
}
attrs.forEach(name => {
if (typeof target[name] !== 'undefined')
data[name] = target[name];
});
return data;
}
async function exec (cmd) {
return new Promise(resolve => {
childProcess.exec(cmd, function (error, stdout, stderr) {
if (error) {
resolve({success: false, stdout, stderr});
} else {
resolve({
success: true,
stdout,
stderr
});
}
});
});
}
module.exports = {
read,
write,
pick,
exec,
Packages: {
plugins,
mainPackage,
npmPackage,
allPackage,
types,
utils,
}
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/LYTB/cnchar.git
git@gitee.com:LYTB/cnchar.git
LYTB
cnchar
cnchar
master

搜索帮助