2026/1/18 5:18:55
网站建设
项目流程
郑州外贸网站制作,软文广告范例大全,如何制作优秀的网页,关于公司建设网站的意义一、使用场景
在汉字学习、识字类项目中#xff0c;通常需要提前生成#xff1a;
汉字拼音#xff08;带声调#xff09;笔画数笔画类型#xff08;横竖撇捺等#xff09;常见组词
本文使用 Node.js cnchar 生成 JSON 数据#xff0c;供后端直接导入数据库使用。二、安…一、使用场景在汉字学习、识字类项目中通常需要提前生成汉字拼音带声调笔画数笔画类型横竖撇捺等常见组词本文使用Node.js cnchar生成 JSON 数据供后端直接导入数据库使用。二、安装依赖npminstallcnchar cnchar-order cnchar-poly cnchar-words cnchar-voice三、生成脚本generate_char_data1.js// generate_char_data_for_execjs.js// Node ESM / execjs / cnchar// 生成拼音 / 笔画数 / 笔画名 / 原始笔画数据importcncharfromcnchar;importorderfromcnchar-order;importpolyfromcnchar-poly;importwordsfromcnchar-words;importvoicefromcnchar-voice;importfsfromfs;// // 1️ 注册插件// cnchar.use(order,poly,words,voice);// // 2️ 获取单字数据// functiongetCharacterData(char){try{// 拼音constspellcnchar.spell(char,tone);constpinyinArray.isArray(spell)?spell.join( / ):spell||;// 笔画数conststrokeCountcnchar.stroke(char)||1;// 笔画名称标准conststrokeNameListcnchar.stroke(char,order,name);conststrokeNamesArray.isArray(strokeNameList)?strokeNameList.join(,):;// ⭐ 原始笔画detail 模式conststrokeDetailListcnchar.stroke(char,order,detail);conststrokesRawcnchar.stroke(char,order,shape)// 组词constwordListcnchar.words(char);constwordsStrArray.isArray(wordList)?wordList.slice(0,8).join(,):;return{character:char,pinyin,stroke_count:strokeCount,stroke_names:strokeNames,strokes_raw:strokesRaw,// 新增字段words:wordsStr};}catch(err){return{character:char,pinyin:,stroke_count:1,stroke_names:,strokes_raw:[],words:};}}// // 3️Node 直接运行示例// if(process.argv[1]process.argv[1].includes(generate_char_data)){constchars[一,人,好,学,你,我];constdatachars.map(getCharacterData);fs.writeFileSync(./char_data.json,JSON.stringify({generated_at:newDate().toISOString(),total:data.length,characters:data},null,2),utf-8);console.log( 已生成 char_data.json含原始笔画);}// // 4️ execjs 导出// export{getCharacterData};四、运行脚本nodegenerate_char_data1.js生成文件generated_characters.json五、生成结果示例{generated_at:2025-12-27T02:47:57.131Z,total:6,characters:[{character:一,pinyin:Yī,stroke_count:1,stroke_names:横,strokes_raw:[[一]],words:八一,八一队,不一,不一定,创一流,初一,单一,第一},{character:人,pinyin:Rén,stroke_count:2,stroke_names:撇,捺,strokes_raw:[[丿,㇏]],words:爱人,爱人民,保护人,被告人,北京人,本人,辩护人,别人},{character:好,pinyin:Hǎo,stroke_count:6,stroke_names:撇点,撇,横,横撇|横钩,竖钩,横,strokes_raw:[[,丿,一,㇇|乛,亅,一]],words:爱好,爱好者,办好,备好,变好,不好,大好,打好},{character:学,pinyin:Xué,stroke_count:8,stroke_names:点,点,撇,点2,横撇|横钩,横撇|横钩,竖钩,横,strokes_raw:[[丶,丶,丿,㇀,㇇|乛,㇇|乛,亅,一]],words:爱科学,爱学习,办学,博学,不科学,才学,辍学,初学},{character:你,pinyin:Nǐ,stroke_count:7,stroke_names:撇,竖,撇,横撇|横钩,竖钩,撇,点,strokes_raw:[[丿,丨,丿,㇇|乛,亅,丿,丶]],words:你的,你好,迷你,你们,你我},{character:我,pinyin:Wǒ,stroke_count:7,stroke_names:撇,横,竖钩,提,斜钩|卧钩,撇,点,strokes_raw:[[丿,一,亅,㇀,㇂|㇃,丿,丶]],words:你我,忘我,我厂,我处,我方,我国,我局,我军}]}六、注意事项重要stroke_count可靠stroke_names仅用于基础展示教学级笔顺 / 动画建议前端使用HanziWriter不推荐在 Django / Java 中直接计算笔画七、总结cnchar 适合数据预生成Node.js 非常适合做汉字数据工具脚本后端只负责存储前端负责交互与动画