javascript-time-ago icon indicating copy to clipboard operation
javascript-time-ago copied to clipboard

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

Open andrejpavlovic opened this issue 5 years ago • 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 avatar Sep 05 '19 18:09 andrejpavlovic

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

catamphetamine avatar Sep 05 '19 18:09 catamphetamine

The RelativeTimeFormat API just got popular on Twitter :)

dandv avatar Oct 25 '19 08:10 dandv

@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...

catamphetamine avatar Oct 25 '19 08:10 catamphetamine

is there any news on this rewrite ?

stof avatar Jul 27 '20 16:07 stof

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

catamphetamine avatar Jul 27 '20 23:07 catamphetamine

In version [email protected] 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

catamphetamine avatar Oct 09 '20 12:10 catamphetamine