catamphetamine/javascript-time-ago

Depend on Intl.RelativeTimeFormat directly instead of loading 'relative-time-format' library.

andrejpavlovic opened this issue · 6 comments

Would it be possible to use this library without relative-time-format being a required dependency? I would like to load "relative-time-format" as a polyfill only where necessary, and rely on browser native Intl.RelativeTimeFormat when it is available.

@andrejpavlovic Yes, there's currently a rewrite pending that will allow optional importing of the polyfill.
Maybe somewhere in October.

dandv commented

The RelativeTimeFormat API just got popular on Twitter :)

@dandv Woow, that's where all those recent stars came from...
I figured someone popular has shared it somewhere on social media.
Cool )

As an update to this issue, I still haven't started it yet (have had some other things to do).
I was planning to move this package into relative-time-format as a subpackage.
Maybe something like relative-time-format/advanced (or a better name).
I also thought whether I should move the present relative-time-format into relative-time-format/polyfill instead, and then the default export of relative-time-format would be this package's API.
I guess it depends on which package is more popular.
We'll see...

stof commented

is there any news on this rewrite ?

@stof I guess I should.
Maybe in August or September.

In version javascript-time-ago@2.2.0 I've added the ability to use native Intl.RelativeTimeFormat and Intl.PluralRules instead of the polyfills: in this case, pass polyfill: false option when creating a TimeAgo instance.

The polyfill: false option still doesn't skip importing the polyfill, so it won't affect the bundle size.
It's of no concern though, because the polyfill is 3.5 kB in size which is small enough.
https://github.com/tc39/proposal-intl-relative-time#polyfills