We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
最近一个项目接入了pinyin这个库,提供了一个接口给前端调用,框架是基于nestjs的 接入后这个项目过一段时间就会OOM,后来把pinyin这个库去掉了,就正常了 也不知道是不是我使用的方法有问题
相关代码
@Controller('/dict') export class DictController { @Post('/pinyin') async getPinyin(@Body('str') str: string) { return { pinyin: getPinyin(str) }; } }
import { uniq } from 'lodash'; import pinyin from 'pinyin'; const replaceNumber = (i: string) => { let temp: string = i; const numbers = { 1: '一', 2: '二', 3: '三', 4: '四', 5: '五', 6: '六', 7: '七', 8: '八', 9: '九', }; Object.keys(numbers).map((number) => { temp = temp.replace(new RegExp(String(number), 'g'), numbers[number]); }); return temp; }; export const getPinyin = (str) => { try { let str1 = replaceNumber(str); if (str1 !== str) str1 = `${str} ${str1}`; const py = pinyin(str1, { heteronym: true, style: 'first_letter', compact: true, segment: true, }); return uniq( py .map((i) => i.join('')) .join(' ') .toLowerCase() .split(/\s/) .filter((i) => !!i), ).join(' '); } catch (error) { return ''; } };
The text was updated successfully, but these errors were encountered:
@rojer95 把 new RegExp 去掉,或者固化正则表达式不要每次 new。
Sorry, something went wrong.
No branches or pull requests
最近一个项目接入了pinyin这个库,提供了一个接口给前端调用,框架是基于nestjs的
接入后这个项目过一段时间就会OOM,后来把pinyin这个库去掉了,就正常了
也不知道是不是我使用的方法有问题
整体内存占用走势
使用pinyin库
刚刚启动
运行一段时间
去掉pinyin库后
刚刚启动
运行一段时间
相关代码
The text was updated successfully, but these errors were encountered: