Skip to content

Commit a273f0e

Browse files
committed
refactor(react): move reading time constants to constants.mjs
Assisted-by: Claude Opus 5.5 <[email protected]>
1 parent de85063 commit a273f0e

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

‎packages/react/src/jsx-ast/constants.mjs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ export const TOC_MAX_HEADING_DEPTH = 3;
5050
// 'Type: '.length
5151
export const TYPE_PREFIX_LENGTH = 6;
5252

53+
// Reading speed behind a page's estimated reading time
54+
export const WORDS_PER_MINUTE = 200;
55+
56+
// Hiragana, CJK ideographs and Hangul syllables each read as one word
57+
export const CJK_CHARACTERS = /[\u3040-\u309f\u4e00-\u9fff\uac00-\ud7a3]/gu;
58+
5359
/**
5460
* HTML tag to UI component mappings
5561
*/

‎packages/react/src/jsx-ast/utils/buildContent.mjs‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import {
2626
ALERT_LEVELS,
2727
TYPES_WITH_METHOD_SIGNATURES,
2828
TYPE_PREFIX_LENGTH,
29+
WORDS_PER_MINUTE,
30+
CJK_CHARACTERS,
2931
} from '../constants.mjs';
3032
import { createJSXElement } from './ast.mjs';
3133
import { extractHeadings, extractTextContent } from './buildBarProps.mjs';
@@ -38,12 +40,8 @@ import {
3840

3941
const wordSegmenter = new Intl.Segmenter('en', { granularity: 'word' });
4042

41-
// Hiragana, CJK ideographs and Hangul syllables each read as one word
42-
const CJK_CHARACTERS = /[\u3040-\u309f\u4e00-\u9fff\uac00-\ud7a3]/gu;
43-
4443
/**
45-
* Estimates the reading time of a page's text, as display text,
46-
* at 200 words per minute.
44+
* Estimates the reading time of a page's text, as display text.
4745
*
4846
* @param {string} text
4947
* @returns {string}
@@ -57,7 +55,7 @@ const readingTime = text => {
5755
}
5856
}
5957

60-
return `${Math.ceil(words / 200)} min read`;
58+
return `${Math.ceil(words / WORDS_PER_MINUTE)} min read`;
6159
};
6260

6361
/**

0 commit comments

Comments
 (0)