-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Description
Have you read the Contributing Guidelines on issues?
- I have read the Contributing Guidelines on issues.
Motivation
We could get rid of some npm lib/code in our blog readingTime API by relying on built-in Intl.Segmenter APIs (Node.js v16+)
const segmenter = new Intl.Segmenter('en', { granularity: 'word' });
const segments = segmenter.segment('This is a test');
let count = 0;
for (const seg of segments) {
console.log({seg});
count++;
}
console.log(count);The library code is more complex, likely less performant, and less accurate (doesn't take the locale as param) than the native implementation
https://github.com/ngryman/reading-time/blob/master/src/reading-time.ts
This is not a critical feature but if someone from the community want to contribute, PRs welcome.
I'd appreciate if you start by writing unit tests / snapshots for the reading-time lib usage.
Then we can see how the new implementation gives a different result depending on inputs.
Based on that result we can decide if it's safe to ship immediately, or if it requires a future flag + breaking change.
Note that Docusaurus exposes a way to pass your own readingTime function, and we may need to change that API: https://docusaurus.io/docs/api/plugins/@docusaurus/plugin-content-blog#ReadingTimeFn
Self-service
- I'd be willing to do some initial work on this proposal myself.