mirror of
https://github.com/Jerryplusy/rc-plugin.git
synced 2025-10-14 16:19:18 +00:00
🐞 fix: 修复统计字数为统计中文字数
This commit is contained in:
parent
3dceb2a332
commit
76c9518d2f
@ -380,13 +380,15 @@ export async function retryAxiosReq(requestFunction, retries = 3, delay = 1000)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 统计给定文本中的字数
|
* 统计给定文本中的中文字数
|
||||||
*
|
*
|
||||||
* @param {string} text - The text to count words in
|
* @param {string} text - The text to count words in
|
||||||
* @return {number} The number of words in the text
|
* @return {number} The number of words in the text
|
||||||
*/
|
*/
|
||||||
export function countWords(text) {
|
export function countChineseCharacters(text) {
|
||||||
return text.split(/\s+/).filter(word => word.length > 0).length;
|
const chineseCharacterRegex = /[\u4e00-\u9fa5]/g;
|
||||||
|
const matches = text.match(chineseCharacterRegex);
|
||||||
|
return matches ? matches.length : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -397,7 +399,7 @@ export function countWords(text) {
|
|||||||
* @return {Object} An object containing the estimated reading time in minutes and the word count.
|
* @return {Object} An object containing the estimated reading time in minutes and the word count.
|
||||||
*/
|
*/
|
||||||
export function estimateReadingTime(text, wpm = 200) {
|
export function estimateReadingTime(text, wpm = 200) {
|
||||||
const wordCount = countWords(text);
|
const wordCount = countChineseCharacters(text);
|
||||||
const readingTimeMinutes = wordCount / wpm;
|
const readingTimeMinutes = wordCount / wpm;
|
||||||
return {
|
return {
|
||||||
minutes: Math.ceil(readingTimeMinutes),
|
minutes: Math.ceil(readingTimeMinutes),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user