reading-time
reading-time copied to clipboard
reading-time v2
Here are a few changes we can make in v2 (most of which @ngryman has also mentioned), roughly in order of decreasing importance:
- Refactor the API to expose two separate functions;
- Remove
textfrom the function return; - ~~Remove the badly named
IOptionsexport;~~ - ~~Migrate to TypeScript completely;~~
- Prefer ESM to CJS (once we have TypeScript this is just a matter of setting the transpilation target);
- ~~Use a class-based implementation of
readingTimeStream;~~ - ~~Change the testing library from mocha to Jest.~~
@ngryman If you have limited availability, I can be here to help.
All of this sounds great to me, thanks!
I finally moved so I should be more available starting next week. I should be able to help here.
Ref #18 for stuff related to the API changes.
Number 2, 3 and 5 will be resolved in #40.
Number 6 will be resolved by #41.
Just jumping in to say that, with my current setup, v1.4.0 worked fine without any changes, but updating to v1.5.0 required me to add the following to my webpack config:
node: {
global: true
},
resolve: {
fallback: {
stream: 'stream-browserify'
}
},
plugins: [
new webpack.ProvidePlugin({
process: 'process/browser',
Buffer: ['buffer', 'Buffer']
})
]
and had to install stream-browserify.
The problematic line was const Transform = require('stream').Transform, but this line is also present in v1.4.0. This is a node core package, so it is expected for some kind of polyfill to be needed, but for some strange reason, v1.4.0 just works without any particular configuration change. 🤷♂️
Just jumping in to say that, with my current setup,
v1.4.0worked fine without any changes, but updating tov1.5.0required me to add the following to my webpack config:]
Not sure if this is the same issue but I had problems with 1.5 on Vite. Using 1.4 for now.
util.inherits is not a function
TypeError: util.inherits is not a function
@sanderjson Yes, your problem is the same as the previous one. util is a Node library and is not polyfilled by Vite. You can either use 1.4, use 2.0.0-1 (which has a browser field in package.json), or import from reading-time/lib/reading-time instead.