i18n-helper-babel
Version:
i18n 命令行工具。一键包裹,提取,翻译,统计。支持网页截图,翻译词条检测
33 lines (26 loc) • 842 B
text/typescript
const isChinese = (val: string): boolean => /[\u4e00-\u9fa5]/.test(val);
const needWrap = (regex: string, val: string): boolean => {
const reg = new RegExp(regex);
return reg.test(val);
};
const formatJSON = (val: any): string => JSON.stringify(val, null, 2);
const formatSeconds = (seconds: number): string => {
const day = 8 * 60 * 60;
const hour = 60 * 60;
const minute = 60;
const dd = Math.floor(seconds / day);
const hh = Math.floor((seconds % day) / hour);
const mm = Math.floor((seconds % hour) / minute);
const ss = seconds % minute;
if (dd > 0) {
return `${dd}天${hh}小时${mm}分钟${ss}秒`;
}
if (hh > 0) {
return `${hh}小时${mm}分钟${ss}秒`;
}
if (mm > 0) {
return `${mm}分钟${ss}秒`;
}
return `${ss}秒`;
};
export { isChinese, formatJSON, needWrap, formatSeconds };