javascript-time-ago 2.5.11 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (452) hide show
  1. package/CHANGELOG.md +10 -1
  2. package/README.md +410 -272
  3. package/bundle/javascript-time-ago.js +1 -1
  4. package/bundle/javascript-time-ago.js.map +1 -1
  5. package/bundle/javascript-time-ago.min.js +1 -1
  6. package/bundle/javascript-time-ago.min.js.map +1 -1
  7. package/commonjs/FullDateFormatter.js +72 -0
  8. package/commonjs/FullDateFormatter.js.map +1 -0
  9. package/commonjs/FullDateFormatter.test.js +26 -0
  10. package/commonjs/FullDateFormatter.test.js.map +1 -0
  11. package/commonjs/LocaleDataStore.js +2 -5
  12. package/commonjs/LocaleDataStore.js.map +1 -1
  13. package/commonjs/PropTypes.js +12 -12
  14. package/commonjs/PropTypes.js.map +1 -1
  15. package/commonjs/TimeAgo.js +300 -253
  16. package/commonjs/TimeAgo.js.map +1 -1
  17. package/commonjs/TimeAgo.test.js +214 -135
  18. package/commonjs/TimeAgo.test.js.map +1 -1
  19. package/commonjs/cache.js +7 -25
  20. package/commonjs/cache.js.map +1 -1
  21. package/commonjs/cache.test.js +1 -3
  22. package/commonjs/cache.test.js.map +1 -1
  23. package/commonjs/isStyleObject.js +9 -9
  24. package/commonjs/isStyleObject.js.map +1 -1
  25. package/commonjs/isStyleObject.test.js +1 -3
  26. package/commonjs/isStyleObject.test.js.map +1 -1
  27. package/commonjs/locale.js +6 -19
  28. package/commonjs/locale.js.map +1 -1
  29. package/commonjs/locale.test.js +2 -11
  30. package/commonjs/locale.test.js.map +1 -1
  31. package/commonjs/round.js +2 -5
  32. package/commonjs/round.js.map +1 -1
  33. package/commonjs/steps/approximate.js +1 -4
  34. package/commonjs/steps/approximate.js.map +1 -1
  35. package/commonjs/steps/approximate.test.js +1 -6
  36. package/commonjs/steps/approximate.test.js.map +1 -1
  37. package/commonjs/steps/getStep.js +36 -53
  38. package/commonjs/steps/getStep.js.map +1 -1
  39. package/commonjs/steps/getStep.test.js +7 -7
  40. package/commonjs/steps/getStep.test.js.map +1 -1
  41. package/commonjs/steps/getStepDenominator.js +2 -5
  42. package/commonjs/steps/getStepDenominator.js.map +1 -1
  43. package/commonjs/steps/getStepDenominator.test.js +1 -3
  44. package/commonjs/steps/getStepDenominator.test.js.map +1 -1
  45. package/commonjs/steps/getStepMinTime.js +31 -39
  46. package/commonjs/steps/getStepMinTime.js.map +1 -1
  47. package/commonjs/steps/getStepMinTime.test.js +1 -3
  48. package/commonjs/steps/getStepMinTime.test.js.map +1 -1
  49. package/commonjs/steps/getTimeToNextUpdate.js +27 -41
  50. package/commonjs/steps/getTimeToNextUpdate.js.map +1 -1
  51. package/commonjs/steps/getTimeToNextUpdate.test.js +29 -25
  52. package/commonjs/steps/getTimeToNextUpdate.test.js.map +1 -1
  53. package/commonjs/steps/getTimeToNextUpdateForUnit.js +3 -12
  54. package/commonjs/steps/getTimeToNextUpdateForUnit.js.map +1 -1
  55. package/commonjs/steps/getTimeToNextUpdateForUnit.test.js +1 -7
  56. package/commonjs/steps/getTimeToNextUpdateForUnit.test.js.map +1 -1
  57. package/commonjs/steps/helpers.js +1 -2
  58. package/commonjs/steps/helpers.js.map +1 -1
  59. package/commonjs/steps/helpers.test.js +0 -1
  60. package/commonjs/steps/helpers.test.js.map +1 -1
  61. package/commonjs/steps/index.js +1 -6
  62. package/commonjs/steps/index.js.map +1 -1
  63. package/commonjs/steps/renameLegacyProperties.js +6 -14
  64. package/commonjs/steps/renameLegacyProperties.js.map +1 -1
  65. package/commonjs/steps/renameLegacyProperties.test.js +1 -3
  66. package/commonjs/steps/renameLegacyProperties.test.js.map +1 -1
  67. package/commonjs/steps/round.js +1 -2
  68. package/commonjs/steps/round.js.map +1 -1
  69. package/commonjs/steps/round.test.js +1 -7
  70. package/commonjs/steps/round.test.js.map +1 -1
  71. package/commonjs/steps/units.js +10 -21
  72. package/commonjs/steps/units.js.map +1 -1
  73. package/commonjs/style/approximate.js +2 -6
  74. package/commonjs/style/approximate.js.map +1 -1
  75. package/commonjs/style/approximateTime.js +2 -6
  76. package/commonjs/style/approximateTime.js.map +1 -1
  77. package/commonjs/style/approximateTime.test.js +116 -75
  78. package/commonjs/style/approximateTime.test.js.map +1 -1
  79. package/commonjs/style/getStyleByName.js +3 -29
  80. package/commonjs/style/getStyleByName.js.map +1 -1
  81. package/commonjs/style/mini.js +9 -6
  82. package/commonjs/style/mini.js.map +1 -1
  83. package/commonjs/style/mini.test.js +15 -25
  84. package/commonjs/style/mini.test.js.map +1 -1
  85. package/commonjs/style/miniMinute.js +8 -13
  86. package/commonjs/style/miniMinute.js.map +1 -1
  87. package/commonjs/style/miniMinute.test.js +11 -17
  88. package/commonjs/style/miniMinute.test.js.map +1 -1
  89. package/commonjs/style/miniMinuteNow.js +8 -13
  90. package/commonjs/style/miniMinuteNow.js.map +1 -1
  91. package/commonjs/style/miniMinuteNow.test.js +11 -17
  92. package/commonjs/style/miniMinuteNow.test.js.map +1 -1
  93. package/commonjs/style/miniNow.js +8 -13
  94. package/commonjs/style/miniNow.js.map +1 -1
  95. package/commonjs/style/miniNow.test.js +11 -17
  96. package/commonjs/style/miniNow.test.js.map +1 -1
  97. package/commonjs/style/renameLegacyProperties.js +7 -13
  98. package/commonjs/style/renameLegacyProperties.js.map +1 -1
  99. package/commonjs/style/renameLegacyProperties.test.js +1 -4
  100. package/commonjs/style/renameLegacyProperties.test.js.map +1 -1
  101. package/commonjs/style/round.js +2 -6
  102. package/commonjs/style/round.js.map +1 -1
  103. package/commonjs/style/round.test.js +51 -67
  104. package/commonjs/style/round.test.js.map +1 -1
  105. package/commonjs/style/roundMinute.js +8 -13
  106. package/commonjs/style/roundMinute.js.map +1 -1
  107. package/commonjs/style/roundMinute.test.js +20 -27
  108. package/commonjs/style/roundMinute.test.js.map +1 -1
  109. package/commonjs/style/twitter.js +34 -39
  110. package/commonjs/style/twitter.js.map +1 -1
  111. package/commonjs/style/twitter.test.js +54 -57
  112. package/commonjs/style/twitter.test.js.map +1 -1
  113. package/commonjs/style/twitterFirstMinute.js +10 -15
  114. package/commonjs/style/twitterFirstMinute.js.map +1 -1
  115. package/commonjs/style/twitterFirstMinute.test.js +16 -23
  116. package/commonjs/style/twitterFirstMinute.test.js.map +1 -1
  117. package/commonjs/style/twitterMinute.js +8 -13
  118. package/commonjs/style/twitterMinute.js.map +1 -1
  119. package/commonjs/style/twitterMinute.test.js +20 -25
  120. package/commonjs/style/twitterMinute.test.js.map +1 -1
  121. package/commonjs/style/twitterMinuteNow.js +8 -13
  122. package/commonjs/style/twitterMinuteNow.js.map +1 -1
  123. package/commonjs/style/twitterMinuteNow.test.js +20 -25
  124. package/commonjs/style/twitterMinuteNow.test.js.map +1 -1
  125. package/commonjs/style/twitterNow.js +8 -13
  126. package/commonjs/style/twitterNow.js.map +1 -1
  127. package/commonjs/style/twitterNow.test.js +18 -24
  128. package/commonjs/style/twitterNow.test.js.map +1 -1
  129. package/full-date-formatter/index.cjs +4 -0
  130. package/full-date-formatter/index.cjs.js +9 -0
  131. package/full-date-formatter/index.d.ts +6 -0
  132. package/full-date-formatter/index.js +1 -0
  133. package/full-date-formatter/package.json +15 -0
  134. package/index.cjs +1 -1
  135. package/index.cjs.js +2 -2
  136. package/index.d.ts +14 -4
  137. package/index.js +3 -1
  138. package/load-all-locales/index.cjs +32 -0
  139. package/load-all-locales/index.cjs.js +32 -0
  140. package/load-all-locales/index.js +64 -0
  141. package/locale/ak/package.json +16 -0
  142. package/locale/ak.json +267 -0
  143. package/locale/ak.json.d.ts +4 -0
  144. package/locale/ak.json.js +267 -0
  145. package/locale/bal-Latn/package.json +16 -0
  146. package/locale/bal-Latn.json +240 -0
  147. package/locale/bal-Latn.json.d.ts +4 -0
  148. package/locale/bal-Latn.json.js +240 -0
  149. package/locale/be-tarask/package.json +16 -0
  150. package/locale/be-tarask.json +259 -0
  151. package/locale/be-tarask.json.d.ts +4 -0
  152. package/locale/be-tarask.json.js +259 -0
  153. package/locale/blo/package.json +16 -0
  154. package/locale/blo.json +159 -0
  155. package/locale/blo.json.d.ts +4 -0
  156. package/locale/blo.json.js +159 -0
  157. package/locale/bn.json +5 -2
  158. package/locale/bn.json.js +5 -2
  159. package/locale/bs.json +8 -2
  160. package/locale/bs.json.js +8 -2
  161. package/locale/ccp.json +2 -8
  162. package/locale/ccp.json.js +2 -8
  163. package/locale/csw/package.json +16 -0
  164. package/locale/csw.json +180 -0
  165. package/locale/csw.json.d.ts +4 -0
  166. package/locale/csw.json.js +180 -0
  167. package/locale/cy.json +6 -12
  168. package/locale/cy.json.js +6 -12
  169. package/locale/doi/package.json +16 -0
  170. package/locale/doi.json +159 -0
  171. package/locale/doi.json.d.ts +4 -0
  172. package/locale/doi.json.js +159 -0
  173. package/locale/en-AU.json +12 -12
  174. package/locale/en-AU.json.js +12 -12
  175. package/locale/en-CZ/package.json +16 -0
  176. package/locale/en-CZ.json +219 -0
  177. package/locale/en-CZ.json.d.ts +4 -0
  178. package/locale/en-CZ.json.js +219 -0
  179. package/locale/en-ES/package.json +16 -0
  180. package/locale/en-ES.json +219 -0
  181. package/locale/en-ES.json.d.ts +4 -0
  182. package/locale/en-ES.json.js +219 -0
  183. package/locale/en-FR/package.json +16 -0
  184. package/locale/en-FR.json +219 -0
  185. package/locale/en-FR.json.d.ts +4 -0
  186. package/locale/en-FR.json.js +219 -0
  187. package/locale/en-GS/package.json +16 -0
  188. package/locale/en-GS.json +219 -0
  189. package/locale/en-GS.json.d.ts +4 -0
  190. package/locale/en-GS.json.js +219 -0
  191. package/locale/en-HU/package.json +16 -0
  192. package/locale/en-HU.json +219 -0
  193. package/locale/en-HU.json.d.ts +4 -0
  194. package/locale/en-HU.json.js +219 -0
  195. package/locale/en-ID/package.json +16 -0
  196. package/locale/en-ID.json +219 -0
  197. package/locale/en-ID.json.d.ts +4 -0
  198. package/locale/en-ID.json.js +219 -0
  199. package/locale/en-IT/package.json +16 -0
  200. package/locale/en-IT.json +219 -0
  201. package/locale/en-IT.json.d.ts +4 -0
  202. package/locale/en-IT.json.js +219 -0
  203. package/locale/en-NO/package.json +16 -0
  204. package/locale/en-NO.json +219 -0
  205. package/locale/en-NO.json.d.ts +4 -0
  206. package/locale/en-NO.json.js +219 -0
  207. package/locale/en-PL/package.json +16 -0
  208. package/locale/en-PL.json +219 -0
  209. package/locale/en-PL.json.d.ts +4 -0
  210. package/locale/en-PL.json.js +219 -0
  211. package/locale/en-PT/package.json +16 -0
  212. package/locale/en-PT.json +219 -0
  213. package/locale/en-PT.json.d.ts +4 -0
  214. package/locale/en-PT.json.js +219 -0
  215. package/locale/en-RO/package.json +16 -0
  216. package/locale/en-RO.json +219 -0
  217. package/locale/en-RO.json.d.ts +4 -0
  218. package/locale/en-RO.json.js +219 -0
  219. package/locale/en-SK/package.json +16 -0
  220. package/locale/en-SK.json +219 -0
  221. package/locale/en-SK.json.d.ts +4 -0
  222. package/locale/en-SK.json.js +219 -0
  223. package/locale/es-MX.json +12 -9
  224. package/locale/es-MX.json.js +12 -9
  225. package/locale/es-SV.json +2 -2
  226. package/locale/es-SV.json.js +2 -2
  227. package/locale/eu.json +24 -24
  228. package/locale/eu.json.js +24 -24
  229. package/locale/ha.json +119 -65
  230. package/locale/ha.json.js +119 -65
  231. package/locale/he.json +0 -6
  232. package/locale/he.json.js +0 -6
  233. package/locale/hi-Latn.json +2 -2
  234. package/locale/hi-Latn.json.js +2 -2
  235. package/locale/ht/package.json +16 -0
  236. package/locale/ht.json +207 -0
  237. package/locale/ht.json.d.ts +4 -0
  238. package/locale/ht.json.js +207 -0
  239. package/locale/id.json +1 -1
  240. package/locale/id.json.js +1 -1
  241. package/locale/ie/package.json +16 -0
  242. package/locale/ie.json +159 -0
  243. package/locale/ie.json.d.ts +4 -0
  244. package/locale/ie.json.js +159 -0
  245. package/locale/ig.json +17 -17
  246. package/locale/ig.json.js +17 -17
  247. package/locale/ii/package.json +16 -0
  248. package/locale/ii.json +165 -0
  249. package/locale/ii.json.d.ts +4 -0
  250. package/locale/ii.json.js +165 -0
  251. package/locale/is.json +4 -1
  252. package/locale/is.json.js +4 -1
  253. package/locale/kaa/package.json +16 -0
  254. package/locale/kaa.json +159 -0
  255. package/locale/kaa.json.d.ts +4 -0
  256. package/locale/kaa.json.js +159 -0
  257. package/locale/kok-Latn/package.json +16 -0
  258. package/locale/kok-Latn.json +159 -0
  259. package/locale/kok-Latn.json.d.ts +4 -0
  260. package/locale/kok-Latn.json.js +159 -0
  261. package/locale/kok.json +8 -8
  262. package/locale/kok.json.js +8 -8
  263. package/locale/ks.json +9 -9
  264. package/locale/ks.json.js +9 -9
  265. package/locale/ku.json +55 -46
  266. package/locale/ku.json.js +55 -46
  267. package/locale/lld/package.json +16 -0
  268. package/locale/lld.json +291 -0
  269. package/locale/lld.json.d.ts +4 -0
  270. package/locale/lld.json.js +291 -0
  271. package/locale/mi.json +22 -22
  272. package/locale/mi.json.js +22 -22
  273. package/locale/ms-Arab/package.json +16 -0
  274. package/locale/ms-Arab.json +159 -0
  275. package/locale/ms-Arab.json.d.ts +4 -0
  276. package/locale/ms-Arab.json.js +159 -0
  277. package/locale/nb.json +2 -2
  278. package/locale/nb.json.js +2 -2
  279. package/locale/ne.json +1 -1
  280. package/locale/ne.json.js +1 -1
  281. package/locale/nn.json +4 -4
  282. package/locale/nn.json.js +4 -4
  283. package/locale/no.json +2 -2
  284. package/locale/no.json.js +2 -2
  285. package/locale/nqo/package.json +16 -0
  286. package/locale/nqo.json +159 -0
  287. package/locale/nqo.json.d.ts +4 -0
  288. package/locale/nqo.json.js +159 -0
  289. package/locale/om/package.json +16 -0
  290. package/locale/om.json +213 -0
  291. package/locale/om.json.d.ts +4 -0
  292. package/locale/om.json.js +213 -0
  293. package/locale/or.json +1 -1
  294. package/locale/or.json.js +1 -1
  295. package/locale/qu.json +46 -46
  296. package/locale/qu.json.js +46 -46
  297. package/locale/rhg/package.json +16 -0
  298. package/locale/rhg.json +159 -0
  299. package/locale/rhg.json.d.ts +4 -0
  300. package/locale/rhg.json.js +159 -0
  301. package/locale/sl.json +12 -12
  302. package/locale/sl.json.js +12 -12
  303. package/locale/sr-Cyrl-BA.json +2 -2
  304. package/locale/sr-Cyrl-BA.json.js +2 -2
  305. package/locale/sr-Latn-BA.json +2 -2
  306. package/locale/sr-Latn-BA.json.js +2 -2
  307. package/locale/sv.json +1 -1
  308. package/locale/sv.json.js +1 -1
  309. package/locale/syr/package.json +16 -0
  310. package/locale/syr.json +303 -0
  311. package/locale/syr.json.d.ts +4 -0
  312. package/locale/syr.json.js +303 -0
  313. package/locale/ti.json +6 -6
  314. package/locale/ti.json.js +6 -6
  315. package/locale/tn/package.json +16 -0
  316. package/locale/tn.json +159 -0
  317. package/locale/tn.json.d.ts +4 -0
  318. package/locale/tn.json.js +159 -0
  319. package/locale/to.json +26 -26
  320. package/locale/to.json.js +26 -26
  321. package/locale/uk.json +1 -1
  322. package/locale/uk.json.js +1 -1
  323. package/locale/ur-IN.json +9 -6
  324. package/locale/ur-IN.json.js +9 -6
  325. package/locale/vec/package.json +16 -0
  326. package/locale/vec.json +267 -0
  327. package/locale/vec.json.d.ts +4 -0
  328. package/locale/vec.json.js +267 -0
  329. package/locale/xnr/package.json +16 -0
  330. package/locale/xnr.json +159 -0
  331. package/locale/xnr.json.d.ts +4 -0
  332. package/locale/xnr.json.js +159 -0
  333. package/locale/yo-BJ.json +17 -17
  334. package/locale/yo-BJ.json.js +17 -17
  335. package/locale/yo.json +17 -17
  336. package/locale/yo.json.js +17 -17
  337. package/modules/FullDateFormatter.js +67 -0
  338. package/modules/FullDateFormatter.js.map +1 -0
  339. package/modules/FullDateFormatter.test.js +22 -0
  340. package/modules/FullDateFormatter.test.js.map +1 -0
  341. package/modules/LocaleDataStore.js +2 -3
  342. package/modules/LocaleDataStore.js.map +1 -1
  343. package/modules/PropTypes.js +11 -7
  344. package/modules/PropTypes.js.map +1 -1
  345. package/modules/TimeAgo.js +299 -237
  346. package/modules/TimeAgo.js.map +1 -1
  347. package/modules/TimeAgo.test.js +217 -119
  348. package/modules/TimeAgo.test.js.map +1 -1
  349. package/modules/cache.js +6 -22
  350. package/modules/cache.js.map +1 -1
  351. package/modules/cache.test.js.map +1 -1
  352. package/modules/isStyleObject.js +9 -7
  353. package/modules/isStyleObject.js.map +1 -1
  354. package/modules/isStyleObject.test.js.map +1 -1
  355. package/modules/locale.js +6 -16
  356. package/modules/locale.js.map +1 -1
  357. package/modules/locale.test.js +0 -4
  358. package/modules/locale.test.js.map +1 -1
  359. package/modules/round.js +2 -3
  360. package/modules/round.js.map +1 -1
  361. package/modules/steps/approximate.js +6 -2
  362. package/modules/steps/approximate.js.map +1 -1
  363. package/modules/steps/approximate.test.js +0 -2
  364. package/modules/steps/approximate.test.js.map +1 -1
  365. package/modules/steps/getStep.js +36 -48
  366. package/modules/steps/getStep.js.map +1 -1
  367. package/modules/steps/getStep.test.js +6 -2
  368. package/modules/steps/getStep.test.js.map +1 -1
  369. package/modules/steps/getStepDenominator.js +2 -3
  370. package/modules/steps/getStepDenominator.js.map +1 -1
  371. package/modules/steps/getStepDenominator.test.js.map +1 -1
  372. package/modules/steps/getStepMinTime.js +31 -36
  373. package/modules/steps/getStepMinTime.js.map +1 -1
  374. package/modules/steps/getStepMinTime.test.js.map +1 -1
  375. package/modules/steps/getTimeToNextUpdate.js +28 -32
  376. package/modules/steps/getTimeToNextUpdate.js.map +1 -1
  377. package/modules/steps/getTimeToNextUpdate.test.js +27 -18
  378. package/modules/steps/getTimeToNextUpdate.test.js.map +1 -1
  379. package/modules/steps/getTimeToNextUpdateForUnit.js +4 -10
  380. package/modules/steps/getTimeToNextUpdateForUnit.js.map +1 -1
  381. package/modules/steps/getTimeToNextUpdateForUnit.test.js +0 -4
  382. package/modules/steps/getTimeToNextUpdateForUnit.test.js.map +1 -1
  383. package/modules/steps/helpers.js +1 -1
  384. package/modules/steps/helpers.js.map +1 -1
  385. package/modules/steps/helpers.test.js.map +1 -1
  386. package/modules/steps/index.js +2 -1
  387. package/modules/steps/index.js.map +1 -1
  388. package/modules/steps/renameLegacyProperties.js +6 -13
  389. package/modules/steps/renameLegacyProperties.js.map +1 -1
  390. package/modules/steps/renameLegacyProperties.test.js.map +1 -1
  391. package/modules/steps/round.js.map +1 -1
  392. package/modules/steps/round.test.js +0 -3
  393. package/modules/steps/round.test.js.map +1 -1
  394. package/modules/steps/units.js +5 -9
  395. package/modules/steps/units.js.map +1 -1
  396. package/modules/style/approximate.js +5 -1
  397. package/modules/style/approximate.js.map +1 -1
  398. package/modules/style/approximateTime.js +6 -2
  399. package/modules/style/approximateTime.js.map +1 -1
  400. package/modules/style/approximateTime.test.js +115 -70
  401. package/modules/style/approximateTime.test.js.map +1 -1
  402. package/modules/style/getStyleByName.js +4 -17
  403. package/modules/style/getStyleByName.js.map +1 -1
  404. package/modules/style/mini.js +8 -4
  405. package/modules/style/mini.js.map +1 -1
  406. package/modules/style/mini.test.js +14 -20
  407. package/modules/style/mini.test.js.map +1 -1
  408. package/modules/style/miniMinute.js +6 -6
  409. package/modules/style/miniMinute.js.map +1 -1
  410. package/modules/style/miniMinute.test.js +10 -12
  411. package/modules/style/miniMinute.test.js.map +1 -1
  412. package/modules/style/miniMinuteNow.js +6 -6
  413. package/modules/style/miniMinuteNow.js.map +1 -1
  414. package/modules/style/miniMinuteNow.test.js +10 -12
  415. package/modules/style/miniMinuteNow.test.js.map +1 -1
  416. package/modules/style/miniNow.js +6 -6
  417. package/modules/style/miniNow.js.map +1 -1
  418. package/modules/style/miniNow.test.js +10 -12
  419. package/modules/style/miniNow.test.js.map +1 -1
  420. package/modules/style/renameLegacyProperties.js +8 -10
  421. package/modules/style/renameLegacyProperties.js.map +1 -1
  422. package/modules/style/renameLegacyProperties.test.js +0 -1
  423. package/modules/style/renameLegacyProperties.test.js.map +1 -1
  424. package/modules/style/round.js +3 -2
  425. package/modules/style/round.js.map +1 -1
  426. package/modules/style/round.test.js +50 -62
  427. package/modules/style/round.test.js.map +1 -1
  428. package/modules/style/roundMinute.js +8 -7
  429. package/modules/style/roundMinute.js.map +1 -1
  430. package/modules/style/roundMinute.test.js +19 -22
  431. package/modules/style/roundMinute.test.js.map +1 -1
  432. package/modules/style/twitter.js +36 -33
  433. package/modules/style/twitter.js.map +1 -1
  434. package/modules/style/twitter.test.js +53 -52
  435. package/modules/style/twitter.test.js.map +1 -1
  436. package/modules/style/twitterFirstMinute.js +8 -7
  437. package/modules/style/twitterFirstMinute.js.map +1 -1
  438. package/modules/style/twitterFirstMinute.test.js +15 -18
  439. package/modules/style/twitterFirstMinute.test.js.map +1 -1
  440. package/modules/style/twitterMinute.js +6 -6
  441. package/modules/style/twitterMinute.js.map +1 -1
  442. package/modules/style/twitterMinute.test.js +19 -20
  443. package/modules/style/twitterMinute.test.js.map +1 -1
  444. package/modules/style/twitterMinuteNow.js +6 -6
  445. package/modules/style/twitterMinuteNow.js.map +1 -1
  446. package/modules/style/twitterMinuteNow.test.js +19 -20
  447. package/modules/style/twitterMinuteNow.test.js.map +1 -1
  448. package/modules/style/twitterNow.js +6 -6
  449. package/modules/style/twitterNow.js.map +1 -1
  450. package/modules/style/twitterNow.test.js +17 -19
  451. package/modules/style/twitterNow.test.js.map +1 -1
  452. package/package.json +275 -13
@@ -1,25 +1,16 @@
1
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
-
3
- function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
-
5
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
6
-
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _createForOfIteratorHelperLoose(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (t) return (t = t.call(r)).next.bind(t); if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var o = 0; return function () { return o >= r.length ? { done: !0 } : { done: !1, value: r[o++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
7
4
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
8
-
9
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
10
-
11
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
12
-
13
- function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
14
-
15
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
16
-
17
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
18
-
19
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
20
-
21
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
22
-
5
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
6
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) { n[e] = r[e]; } return n; }
7
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0) { ; } } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
8
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
9
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
10
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
11
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
12
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
13
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
23
14
  import RelativeTimeFormatPolyfill from 'relative-time-format';
24
15
  import Cache from './cache.js';
25
16
  import chooseLocale from './locale.js';
@@ -30,11 +21,7 @@ import getTimeToNextUpdate from './steps/getTimeToNextUpdate.js';
30
21
  import { addLocaleData, getLocaleData } from './LocaleDataStore.js';
31
22
  import defaultStyle from './style/roundMinute.js';
32
23
  import getStyleByName from './style/getStyleByName.js';
33
- import { getRoundFunction } from './round.js'; // Valid time units.
34
-
35
- var UNITS = ['now', // The rest are the same as in `Intl.RelativeTimeFormat`.
36
- 'second', 'minute', 'hour', 'day', 'week', 'month', 'quarter', 'year'];
37
-
24
+ import { getRoundFunction } from './round.js';
38
25
  var TimeAgo = /*#__PURE__*/function () {
39
26
  /**
40
27
  * @param {(string|string[])} locales=[] - Preferred locales (or locale).
@@ -42,46 +29,44 @@ var TimeAgo = /*#__PURE__*/function () {
42
29
  */
43
30
  function TimeAgo() {
44
31
  var locales = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
45
-
46
32
  var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
47
- polyfill = _ref.polyfill;
48
-
33
+ polyfill = _ref.polyfill;
49
34
  _classCallCheck(this, TimeAgo);
50
-
51
35
  // Convert `locales` to an array.
52
36
  if (typeof locales === 'string') {
53
37
  locales = [locales];
54
- } // Choose the most appropriate locale
38
+ }
39
+
40
+ // Choose the most appropriate locale
55
41
  // from the list of `locales` added by the user.
56
42
  // For example, new TimeAgo("en-US") -> "en".
57
-
58
-
59
43
  this.locale = chooseLocale(locales.concat(TimeAgo.getDefaultLocale()), getLocaleData);
60
-
61
44
  if (typeof Intl !== 'undefined') {
62
45
  // Use `Intl.NumberFormat` for formatting numbers (when available).
63
46
  if (Intl.NumberFormat) {
64
47
  this.numberFormat = new Intl.NumberFormat(this.locale);
65
48
  }
66
- } // Some people have requested the ability to use native
49
+ }
50
+
51
+ // Some people have requested the ability to use native
67
52
  // `Intl.RelativeTimeFormat` and `Intl.PluralRules`
68
53
  // instead of the polyfills.
69
54
  // https://github.com/catamphetamine/javascript-time-ago/issues/21
70
-
71
-
72
55
  if (polyfill === false) {
73
56
  this.IntlRelativeTimeFormat = Intl.RelativeTimeFormat;
74
57
  this.IntlPluralRules = Intl.PluralRules;
75
58
  } else {
76
59
  this.IntlRelativeTimeFormat = RelativeTimeFormatPolyfill;
77
60
  this.IntlPluralRules = RelativeTimeFormatPolyfill.PluralRules;
78
- } // Cache `Intl.RelativeTimeFormat` instance.
79
-
61
+ }
80
62
 
81
- this.relativeTimeFormatCache = new Cache(); // Cache `Intl.PluralRules` instance.
63
+ // Cache `Intl.RelativeTimeFormat` instance.
64
+ this.relativeTimeFormatCache = new Cache();
82
65
 
66
+ // Cache `Intl.PluralRules` instance.
83
67
  this.pluralRulesCache = new Cache();
84
68
  }
69
+
85
70
  /**
86
71
  * Formats relative date/time.
87
72
  *
@@ -101,13 +86,16 @@ var TimeAgo = /*#__PURE__*/function () {
101
86
  *
102
87
  * @param {boolean} [options.getTimeToNextUpdate] — Pass `true` to return `[formattedDate, timeToNextUpdate]` instead of just `formattedDate`.
103
88
  *
89
+ * @param {boolean} [options.getTimeToNextUpdateUncapped] — Pass `true` to not apply the workaround for `setTimeout()` bug. https://stackoverflow.com/questions/3468607/why-does-settimeout-break-for-large-millisecond-delay-values
90
+ *
91
+ * @param {function} [options.refresh] — When `refresh` function is passed, it will be automatically called with a new text when it's time to refresh the label.
92
+ *
104
93
  * @return {string} The formatted relative date/time. If no eligible `step` is found, then an empty string is returned.
105
94
  */
106
-
107
-
108
95
  _createClass(TimeAgo, [{
109
96
  key: "format",
110
97
  value: function format(input, style, options) {
98
+ var _this = this;
111
99
  if (!options) {
112
100
  if (style && !isStyle(style)) {
113
101
  options = style;
@@ -116,144 +104,216 @@ var TimeAgo = /*#__PURE__*/function () {
116
104
  options = {};
117
105
  }
118
106
  }
119
-
120
107
  if (!style) {
121
108
  style = defaultStyle;
122
109
  }
123
-
124
110
  if (typeof style === 'string') {
125
111
  style = getStyleByName(style);
126
112
  }
113
+ var timestamp = getTimestamp(input);
127
114
 
128
- var timestamp = getTimestamp(input); // Get locale messages for this type of labels.
115
+ // Get locale messages for this type of labels.
129
116
  // "flavour" is a legacy name for "labels".
130
-
131
117
  var _this$getLabels = this.getLabels(style.flavour || style.labels),
132
- labels = _this$getLabels.labels,
133
- labelsType = _this$getLabels.labelsType;
118
+ labels = _this$getLabels.labels,
119
+ labelsType = _this$getLabels.labelsType;
134
120
 
135
- var now; // Can pass a custom `now`, e.g. for testing purposes.
136
- //
137
- // Legacy way was passing `now` in `style`.
138
- // That way is deprecated.
121
+ // `round` setting could be passed as a parameter to `.format()` function
122
+ // or be configured globally for a style.
123
+ var round = options.round || style.round;
139
124
 
125
+ // A developer can pass a custom `now`, e.g. for testing purposes.
126
+ var now;
127
+ var nowRealWhenCalled = Date.now();
128
+ // (deprecated)
129
+ // Legacy way was passing `now` in `style`.
140
130
  if (style.now !== undefined) {
141
131
  now = style.now;
142
- } // The new way is passing `now` option to `.format()`.
143
-
144
-
132
+ }
133
+ // One could pass `now` option to `.format()`.
145
134
  if (now === undefined && options.now !== undefined) {
146
135
  now = options.now;
147
136
  }
148
-
137
+ // The default `now` is `Date.now()`.
149
138
  if (now === undefined) {
150
- now = Date.now();
151
- } // how much time has passed (in seconds)
152
-
153
-
154
- var secondsPassed = (now - timestamp) / 1000; // in seconds
155
-
156
- var future = options.future || secondsPassed < 0;
157
- var nowLabel = getNowLabel(labels, getLocaleData(this.locale).now, getLocaleData(this.locale)["long"], future); // `custom` A function of `{ elapsed, time, date, now, locale }`.
158
- //
159
- // Looks like `custom` function is deprecated and will be removed
160
- // in the next major version.
161
- //
162
- // If this function returns a value, then the `.format()` call will return that value.
163
- // Otherwise the relative date/time is formatted as usual.
164
- // This feature is currently not used anywhere and is here
165
- // just for providing the ultimate customization point
166
- // in case anyone would ever need that. Prefer using
167
- // `steps[step].format(value, locale)` instead.
168
- //
169
-
170
- if (style.custom) {
171
- var custom = style.custom({
172
- now: now,
173
- date: new Date(timestamp),
174
- time: timestamp,
175
- elapsed: secondsPassed,
176
- locale: this.locale
177
- });
178
-
179
- if (custom !== undefined) {
180
- // Won't return `timeToNextUpdate` here
181
- // because `custom()` seems deprecated.
182
- return custom;
139
+ now = nowRealWhenCalled;
140
+ }
141
+ var getTextAndTextRefreshDelayGetterFunctions = function getTextAndTextRefreshDelayGetterFunctions(_ref2) {
142
+ var now = _ref2.now;
143
+ // how much time has passed (in seconds)
144
+ var secondsPassed = (now - timestamp) / 1000; // in seconds
145
+
146
+ var future = options.future || secondsPassed < 0;
147
+ var nowLabel = getNowLabel(labels, getLocaleData(_this.locale).now, getLocaleData(_this.locale)["long"], future);
148
+
149
+ // (deprecated)
150
+ //
151
+ // `custom` A function of `{ elapsed, time, date, now, locale }`.
152
+ //
153
+ // If this function returns a value, then the `.format()` call will return that value.
154
+ // Otherwise the relative date/time is formatted as usual.
155
+ // This feature is currently not used anywhere and is here
156
+ // just for providing the ultimate customization point
157
+ // in case anyone would ever need that. Prefer using
158
+ // `steps[step].format(value, locale)` instead.
159
+ //
160
+ if (style.custom) {
161
+ var text = style.custom({
162
+ now: now,
163
+ date: new Date(timestamp),
164
+ time: timestamp,
165
+ elapsed: secondsPassed,
166
+ locale: _this.locale
167
+ });
168
+ if (text !== undefined) {
169
+ // Won't return `timeToNextUpdate` here
170
+ // because `custom()` seems deprecated.
171
+ return {
172
+ getText: function getText() {
173
+ return text;
174
+ },
175
+ getTextRefreshDelay: function getTextRefreshDelay() {
176
+ throw new Error('`getTimeToNextUpdate: true` feature is not supported by legacy "styles" that have a `custom` function');
177
+ }
178
+ };
179
+ }
183
180
  }
184
- } // Get the list of available time interval units.
185
-
186
-
187
- var units = getTimeIntervalMeasurementUnits( // Controlling `style.steps` through `style.units` seems to be deprecated:
188
- // create a new custom `style` instead.
189
- style.units, labels, nowLabel); // // If no available time unit is suitable, just output an empty string.
190
- // if (units.length === 0) {
191
- // console.error(`None of the "${units.join(', ')}" time units have been found in "${labelsType}" labels for "${this.locale}" locale.`)
192
- // return ''
193
- // }
194
-
195
- var round = options.round || style.round; // Choose the appropriate time measurement unit
196
- // and get the corresponding rounded time amount.
197
-
198
- var _getStep = getStep( // "gradation" is a legacy name for "steps".
199
- // For historical reasons, "approximate" steps are used by default.
200
- // In the next major version, there'll be no default for `steps`.
201
- style.gradation || style.steps || defaultStyle.steps, secondsPassed, {
202
- now: now,
203
- units: units,
204
- round: round,
205
- future: future,
206
- getNextStep: true
207
- }),
181
+
182
+ // Get the list of available time interval units.
183
+ var units = getTimeIntervalMeasurementUnits(
184
+ // Controlling `style.steps` through `style.units` seems to be deprecated:
185
+ // create a new custom `style` instead.
186
+ style.units, labels, nowLabel);
187
+
188
+ // Choose the appropriate time measurement unit
189
+ // and get the corresponding rounded time amount.
190
+ var _getStep = getStep(
191
+ // "gradation" is a legacy name for "steps".
192
+ // For historical reasons, "approximate" steps are used by default.
193
+ // In the next major version, there'll be no default for `steps`.
194
+ style.gradation || style.steps || defaultStyle.steps, secondsPassed, {
195
+ now: now,
196
+ units: units,
197
+ round: round,
198
+ future: future,
199
+ getNextStep: true
200
+ }),
208
201
  _getStep2 = _slicedToArray(_getStep, 3),
209
202
  prevStep = _getStep2[0],
210
203
  step = _getStep2[1],
211
204
  nextStep = _getStep2[2];
205
+ var getText = function getText() {
206
+ return _this.formatDateForStep(timestamp, step, secondsPassed, {
207
+ labels: labels,
208
+ labelsType: labelsType,
209
+ nowLabel: nowLabel,
210
+ now: now,
211
+ future: future,
212
+ round: round
213
+ }) || '';
214
+ };
215
+
216
+ // Returns the time (in milliseconds) after which the formatted date label should be refreshed.
217
+ //
218
+ // It will return `undefined` for a custom style
219
+ // that doesn't meet the minimum requirements for this feature.
220
+ // See the README for more details.
221
+ //
222
+ var getTextRefreshDelay = function getTextRefreshDelay() {
223
+ var timeToNextUpdate = getTimeToNextUpdate(timestamp, step, {
224
+ nextStep: nextStep,
225
+ prevStep: prevStep,
226
+ now: now,
227
+ future: future,
228
+ round: round
229
+ });
212
230
 
213
- var formattedDate = this.formatDateForStep(timestamp, step, secondsPassed, {
214
- labels: labels,
215
- labelsType: labelsType,
216
- nowLabel: nowLabel,
217
- now: now,
218
- future: future,
219
- round: round
220
- }) || '';
221
-
231
+ // `timeToNextUpdate` could be `undefined` for a custom style
232
+ // that doesn't meet the minimum requirements for this feature.
233
+ // See the README for more details.
234
+ if (typeof timeToNextUpdate === 'number') {
235
+ // `setTimeout()` function has a bug when it fires immediately
236
+ // when the delay is longer than about `24.85` days.
237
+ // https://stackoverflow.com/questions/3468607/why-does-settimeout-break-for-large-millisecond-delay-values
238
+ //
239
+ // To not burden the end user of this library with manually working around that bug,
240
+ // this library automatically caps the returned delay to a maximum value that
241
+ // still works with `setTimeout()` and doesn't break it.
242
+ //
243
+ // The end user of this library could still opt out of this auto-workaround feature
244
+ // by passing a `getTimeToNextUpdateUncapped: true` option.
245
+ //
246
+ if (options.getTimeToNextUpdateUncapped) {
247
+ return timeToNextUpdate;
248
+ }
249
+ return getSafeTimeoutDelay(timeToNextUpdate);
250
+ }
251
+ };
252
+ return {
253
+ getText: getText,
254
+ getTextRefreshDelay: getTextRefreshDelay
255
+ };
256
+ };
257
+ var _getTextAndTextRefres = getTextAndTextRefreshDelayGetterFunctions({
258
+ now: now
259
+ }),
260
+ getText = _getTextAndTextRefres.getText,
261
+ getTextRefreshDelay = _getTextAndTextRefres.getTextRefreshDelay;
222
262
  if (options.getTimeToNextUpdate) {
223
- var timeToNextUpdate = getTimeToNextUpdate(timestamp, step, {
224
- nextStep: nextStep,
225
- prevStep: prevStep,
226
- now: now,
227
- future: future,
228
- round: round
229
- });
230
- return [formattedDate, timeToNextUpdate];
263
+ return [getText(), getTextRefreshDelay()];
231
264
  }
232
-
233
- return formattedDate;
265
+ if (options.refresh) {
266
+ // `getTextRefreshDelay()` will return `undefined` for a custom style
267
+ // that doesn't meet the minimum requirements for this feature.
268
+ // See the README for more details.
269
+ //
270
+ // This is a "sensible default" interval for refreshing time labels
271
+ // that use such custom style.
272
+ //
273
+ var defaultRefreshInterval = 60 * 1000;
274
+
275
+ // If `refresh` function was passed, schedule it to be called when the time comes,
276
+ // after which schedule the next refresh.
277
+ var refreshTimer;
278
+ var scheduleRefresh = function scheduleRefresh() {
279
+ var delay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultRefreshInterval;
280
+ refreshTimer = setTimeoutSafe(function () {
281
+ var _getTextAndTextRefres2 = getTextAndTextRefreshDelayGetterFunctions({
282
+ now: now + (Date.now() - nowRealWhenCalled)
283
+ }),
284
+ getText = _getTextAndTextRefres2.getText,
285
+ getTextRefreshDelay = _getTextAndTextRefres2.getTextRefreshDelay;
286
+ options.refresh(getText());
287
+ scheduleRefresh(getTextRefreshDelay());
288
+ }, delay);
289
+ };
290
+ scheduleRefresh(getTextRefreshDelay());
291
+ var stopRefreshing = function stopRefreshing() {
292
+ clearTimeout(refreshTimer);
293
+ };
294
+ return [getText(), stopRefreshing];
295
+ }
296
+ return getText();
234
297
  }
235
298
  }, {
236
299
  key: "formatDateForStep",
237
- value: function formatDateForStep(timestamp, step, secondsPassed, _ref2) {
238
- var _this = this;
239
-
240
- var labels = _ref2.labels,
241
- labelsType = _ref2.labelsType,
242
- nowLabel = _ref2.nowLabel,
243
- now = _ref2.now,
244
- future = _ref2.future,
245
- round = _ref2.round;
246
-
300
+ value: function formatDateForStep(timestamp, step, secondsPassed, _ref3) {
301
+ var _this2 = this;
302
+ var labels = _ref3.labels,
303
+ labelsType = _ref3.labelsType,
304
+ nowLabel = _ref3.nowLabel,
305
+ now = _ref3.now,
306
+ future = _ref3.future,
307
+ round = _ref3.round;
247
308
  // If no step matches, then output an empty string.
248
309
  if (!step) {
249
310
  return;
250
311
  }
251
-
252
312
  if (step.format) {
253
313
  return step.format(timestamp, this.locale, {
254
- formatAs: function formatAs(unit, value) {
314
+ formatAs: function formatAs(unit, amount) {
255
315
  // Mimicks `Intl.RelativeTimeFormat.format()`.
256
- return _this.formatValue(value, unit, {
316
+ return _this2.formatValue(amount, unit, {
257
317
  labels: labels,
258
318
  future: future
259
319
  });
@@ -261,23 +321,24 @@ var TimeAgo = /*#__PURE__*/function () {
261
321
  now: now,
262
322
  future: future
263
323
  });
264
- } // "unit" is now called "formatAs".
265
-
324
+ }
266
325
 
326
+ // "unit" is now called "formatAs".
267
327
  var unit = step.unit || step.formatAs;
268
-
269
328
  if (!unit) {
270
329
  throw new Error("[javascript-time-ago] Each step must define either `formatAs` or `format()`. Step: ".concat(JSON.stringify(step)));
271
- } // `Intl.RelativeTimeFormat` doesn't operate in "now" units.
272
- // Therefore, threat "now" as a special case.
273
-
330
+ }
274
331
 
332
+ // `Intl.RelativeTimeFormat` doesn't operate in "now" units.
333
+ // Therefore, threat "now" as a special case.
275
334
  if (unit === 'now') {
276
335
  return nowLabel;
277
- } // Amount in units.
336
+ }
278
337
 
338
+ // Amount in units.
339
+ var amount = Math.abs(secondsPassed) / getStepDenominator(step);
279
340
 
280
- var amount = Math.abs(secondsPassed) / getStepDenominator(step); // Apply granularity to the time amount
341
+ // Apply granularity to the time amount
281
342
  // (and fallback to the previous step
282
343
  // if the first level of granularity
283
344
  // isn't met by this amount)
@@ -288,19 +349,18 @@ var TimeAgo = /*#__PURE__*/function () {
288
349
  // Perhaps this feature will be removed because there seem to be no use cases
289
350
  // of it in the real world.
290
351
  //
291
-
292
352
  if (step.granularity) {
293
353
  // Recalculate the amount of seconds passed based on granularity
294
354
  amount = getRoundFunction(round)(amount / step.granularity) * step.granularity;
295
355
  }
356
+ var valueForFormatting = -1 * Math.sign(secondsPassed) * getRoundFunction(round)(amount);
296
357
 
297
- var valueForFormatting = -1 * Math.sign(secondsPassed) * getRoundFunction(round)(amount); // By default, this library formats a `0` in "past" mode,
358
+ // By default, this library formats a `0` in "past" mode,
298
359
  // unless `future: true` option is passed.
299
360
  // This is different to `relative-time-format`'s behavior
300
361
  // which formats a `0` in "future" mode by default, unless it's a `-0`.
301
362
  // So, convert `0` to `-0` if `future: true` option wasn't passed.
302
363
  // `=== 0` matches both `0` and `-0`.
303
-
304
364
  if (valueForFormatting === 0) {
305
365
  if (future) {
306
366
  valueForFormatting = 0;
@@ -308,14 +368,12 @@ var TimeAgo = /*#__PURE__*/function () {
308
368
  valueForFormatting = -0;
309
369
  }
310
370
  }
311
-
312
371
  switch (labelsType) {
313
372
  case 'long':
314
373
  case 'short':
315
374
  case 'narrow':
316
375
  // Format the amount using `Intl.RelativeTimeFormat`.
317
376
  return this.getFormatter(labelsType).format(valueForFormatting, unit);
318
-
319
377
  default:
320
378
  // Format the amount.
321
379
  // (mimicks `Intl.RelativeTimeFormat` behavior for other time label styles)
@@ -325,6 +383,7 @@ var TimeAgo = /*#__PURE__*/function () {
325
383
  });
326
384
  }
327
385
  }
386
+
328
387
  /**
329
388
  * Mimicks what `Intl.RelativeTimeFormat` does for additional locale styles.
330
389
  * @param {number} value
@@ -333,16 +392,16 @@ var TimeAgo = /*#__PURE__*/function () {
333
392
  * @param {boolean} [options.future] — Tells how to format value `0`: as "future" (`true`) or "past" (`false`). Is `false` by default, but should have been `true` actually.
334
393
  * @return {string}
335
394
  */
336
-
337
395
  }, {
338
396
  key: "formatValue",
339
- value: function formatValue(value, unit, _ref3) {
340
- var labels = _ref3.labels,
341
- future = _ref3.future;
397
+ value: function formatValue(value, unit, _ref4) {
398
+ var labels = _ref4.labels,
399
+ future = _ref4.future;
342
400
  return this.getFormattingRule(labels, unit, value, {
343
401
  future: future
344
402
  }).replace('{0}', this.formatNumber(Math.abs(value)));
345
403
  }
404
+
346
405
  /**
347
406
  * Returns formatting rule for `value` in `units` (either in past or in future).
348
407
  * @param {object} formattingRules — Relative time labels for different units.
@@ -354,57 +413,54 @@ var TimeAgo = /*#__PURE__*/function () {
354
413
  * // Returns "{0} days ago"
355
414
  * getFormattingRule(en.long, "day", -2, 'en')
356
415
  */
357
-
358
416
  }, {
359
417
  key: "getFormattingRule",
360
- value: function getFormattingRule(formattingRules, unit, value, _ref4) {
361
- var future = _ref4.future;
418
+ value: function getFormattingRule(formattingRules, unit, value, _ref5) {
419
+ var future = _ref5.future;
362
420
  // Passing the language is required in order to
363
421
  // be able to correctly classify the `value` as a number.
364
422
  var locale = this.locale;
365
- formattingRules = formattingRules[unit]; // Check for a special "compacted" rules case:
423
+ formattingRules = formattingRules[unit];
424
+ // Check for a special "compacted" rules case:
366
425
  // if formatting rules are the same for "past" and "future",
367
426
  // and also for all possible `value`s, then those rules are
368
427
  // stored as a single string.
369
-
370
428
  if (typeof formattingRules === 'string') {
371
429
  return formattingRules;
372
- } // Choose either "past" or "future" based on time `value` sign.
430
+ }
431
+ // Choose either "past" or "future" based on time `value` sign.
373
432
  // If "past" is same as "future" then they're stored as "other".
374
433
  // If there's only "other" then it's being collapsed.
375
-
376
-
377
434
  var pastOrFuture = value === 0 ? future ? 'future' : 'past' : value < 0 ? 'past' : 'future';
378
- var quantifierRules = formattingRules[pastOrFuture] || formattingRules; // Bundle size optimization technique.
379
-
435
+ var quantifierRules = formattingRules[pastOrFuture] || formattingRules;
436
+ // Bundle size optimization technique.
380
437
  if (typeof quantifierRules === 'string') {
381
438
  return quantifierRules;
382
- } // Quantify `value`.
383
-
384
-
385
- var quantifier = this.getPluralRules().select(Math.abs(value)); // "other" rule is supposed to always be present.
439
+ }
440
+ // Quantify `value`.
441
+ var quantifier = this.getPluralRules().select(Math.abs(value));
442
+ // "other" rule is supposed to always be present.
386
443
  // If only "other" rule is present then "rules" is not an object and is a string.
387
-
388
444
  return quantifierRules[quantifier] || quantifierRules.other;
389
445
  }
446
+
390
447
  /**
391
448
  * Formats a number into a string.
392
449
  * Uses `Intl.NumberFormat` when available.
393
450
  * @param {number} number
394
451
  * @return {string}
395
452
  */
396
-
397
453
  }, {
398
454
  key: "formatNumber",
399
455
  value: function formatNumber(number) {
400
456
  return this.numberFormat ? this.numberFormat.format(number) : String(number);
401
457
  }
458
+
402
459
  /**
403
460
  * Returns an `Intl.RelativeTimeFormat` for a given `labelsType`.
404
461
  * @param {string} labelsType
405
462
  * @return {object} `Intl.RelativeTimeFormat` instance
406
463
  */
407
-
408
464
  }, {
409
465
  key: "getFormatter",
410
466
  value: function getFormatter(labelsType) {
@@ -414,11 +470,11 @@ var TimeAgo = /*#__PURE__*/function () {
414
470
  style: labelsType
415
471
  }));
416
472
  }
473
+
417
474
  /**
418
475
  * Returns an `Intl.PluralRules` instance.
419
476
  * @return {object} `Intl.PluralRules` instance
420
477
  */
421
-
422
478
  }, {
423
479
  key: "getPluralRules",
424
480
  value: function getPluralRules() {
@@ -426,6 +482,7 @@ var TimeAgo = /*#__PURE__*/function () {
426
482
  // a lengthy operation so the instances are cached and reused.
427
483
  return this.pluralRulesCache.get(this.locale) || this.pluralRulesCache.put(this.locale, new this.IntlPluralRules(this.locale));
428
484
  }
485
+
429
486
  /**
430
487
  * Gets localized labels for this type of labels.
431
488
  *
@@ -435,37 +492,34 @@ var TimeAgo = /*#__PURE__*/function () {
435
492
  *
436
493
  * @returns {Object} Returns an object of shape { labelsType, labels }
437
494
  */
438
-
439
495
  }, {
440
496
  key: "getLabels",
441
497
  value: function getLabels() {
442
498
  var labelsType = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
443
-
444
499
  // Convert `labels` to an array.
445
500
  if (typeof labelsType === 'string') {
446
501
  labelsType = [labelsType];
447
- } // Supports legacy "tiny" and "mini-time" label styles.
448
-
502
+ }
449
503
 
504
+ // Supports legacy "tiny" and "mini-time" label styles.
450
505
  labelsType = labelsType.map(function (labelsType) {
451
506
  switch (labelsType) {
452
507
  case 'tiny':
453
508
  case 'mini-time':
454
509
  return 'mini';
455
-
456
510
  default:
457
511
  return labelsType;
458
512
  }
459
- }); // "long" labels type is the default one.
460
- // (it's always present for all languages)
513
+ });
461
514
 
462
- labelsType = labelsType.concat('long'); // Find a suitable labels type.
515
+ // "long" labels type is the default one.
516
+ // (it's always present for all languages)
517
+ labelsType = labelsType.concat('long');
463
518
 
519
+ // Find a suitable labels type.
464
520
  var localeData = getLocaleData(this.locale);
465
-
466
521
  for (var _iterator = _createForOfIteratorHelperLoose(labelsType), _step; !(_step = _iterator()).done;) {
467
522
  var _labelsType = _step.value;
468
-
469
523
  if (localeData[_labelsType]) {
470
524
  return {
471
525
  labelsType: _labelsType,
@@ -475,162 +529,170 @@ var TimeAgo = /*#__PURE__*/function () {
475
529
  }
476
530
  }
477
531
  }]);
478
-
479
532
  return TimeAgo;
480
533
  }();
481
534
  /**
482
535
  * Default locale global variable.
483
536
  */
484
-
485
-
486
537
  export { TimeAgo as default };
487
538
  var defaultLocale = 'en';
539
+
488
540
  /**
489
541
  * Gets default locale.
490
542
  * @return {string} locale
491
543
  */
492
-
493
544
  TimeAgo.getDefaultLocale = function () {
494
545
  return defaultLocale;
495
546
  };
547
+
496
548
  /**
497
549
  * Sets default locale.
498
550
  * @param {string} locale
499
551
  */
500
-
501
-
502
552
  TimeAgo.setDefaultLocale = function (locale) {
503
- return defaultLocale = locale;
553
+ defaultLocale = locale;
504
554
  };
555
+
505
556
  /**
506
557
  * Adds locale data for a specific locale and marks the locale as default.
507
558
  * @param {Object} localeData
508
559
  */
509
-
510
-
511
560
  TimeAgo.addDefaultLocale = function (localeData) {
561
+ // Warn the user if they've previously already added a default locale (a different one).
512
562
  if (defaultLocaleHasBeenSpecified) {
513
- return console.error('[javascript-time-ago] `TimeAgo.addDefaultLocale()` can only be called once. To add other locales, use `TimeAgo.addLocale()`.');
563
+ if (TimeAgo.getDefaultLocale() !== localeData.locale) {
564
+ console.warn("[javascript-time-ago] You're adding \"".concat(localeData.locale, "\" as the default locale but you have already added \"").concat(TimeAgo.getDefaultLocale(), "\" as the default locale. \"").concat(localeData.locale, "\" is the default locale now."));
565
+ }
514
566
  }
515
-
516
567
  defaultLocaleHasBeenSpecified = true;
517
- TimeAgo.setDefaultLocale(localeData.locale);
568
+
569
+ // `addDefaultLocale()` is just a shortcut to `addLocale()` + `setDefaultLocale()`.
518
570
  TimeAgo.addLocale(localeData);
571
+ TimeAgo.setDefaultLocale(localeData.locale);
519
572
  };
573
+ var defaultLocaleHasBeenSpecified = false;
520
574
 
521
- var defaultLocaleHasBeenSpecified;
522
575
  /**
523
576
  * Adds locale data for a specific locale.
524
577
  * @param {Object} localeData
525
578
  */
526
-
527
579
  TimeAgo.addLocale = function (localeData) {
528
580
  addLocaleData(localeData);
529
581
  RelativeTimeFormatPolyfill.addLocale(localeData);
530
582
  };
583
+
531
584
  /**
532
585
  * (legacy alias)
533
586
  * Adds locale data for a specific locale.
534
587
  * @param {Object} localeData
535
588
  * @deprecated
536
589
  */
537
-
538
-
539
590
  TimeAgo.locale = TimeAgo.addLocale;
591
+
540
592
  /**
541
593
  * Adds custom labels to locale data.
542
594
  * @param {string} locale
543
595
  * @param {string} name
544
596
  * @param {object} labels
545
597
  */
546
-
547
598
  TimeAgo.addLabels = function (locale, name, labels) {
548
599
  var localeData = getLocaleData(locale);
549
-
550
600
  if (!localeData) {
551
601
  addLocaleData({
552
602
  locale: locale
553
603
  });
554
- localeData = getLocaleData(locale); // throw new Error(`[javascript-time-ago] No data for locale "${locale}"`)
604
+ localeData = getLocaleData(locale);
605
+ // throw new Error(`[javascript-time-ago] No data for locale "${locale}"`)
555
606
  }
556
-
557
607
  localeData[name] = labels;
558
- }; // Normalizes `.format()` `time` argument.
559
-
608
+ };
560
609
 
610
+ // Normalizes `.format()` `time` argument.
561
611
  function getTimestamp(input) {
562
612
  if (input.constructor === Date || isMockedDate(input)) {
563
613
  return input.getTime();
564
614
  }
565
-
566
615
  if (typeof input === 'number') {
567
616
  return input;
568
- } // For some weird reason istanbul doesn't see this `throw` covered.
617
+ }
569
618
 
619
+ // For some weird reason istanbul doesn't see this `throw` covered.
570
620
  /* istanbul ignore next */
571
-
572
-
573
621
  throw new Error("Unsupported relative time formatter input: ".concat(_typeof(input), ", ").concat(input));
574
- } // During testing via some testing libraries `Date`s aren't actually `Date`s.
575
- // https://github.com/catamphetamine/javascript-time-ago/issues/22
576
-
622
+ }
577
623
 
624
+ // During testing via some testing libraries `Date`s aren't actually `Date`s.
625
+ // https://github.com/catamphetamine/javascript-time-ago/issues/22
578
626
  function isMockedDate(object) {
579
627
  return _typeof(object) === 'object' && typeof object.getTime === 'function';
580
- } // Get available time interval measurement units.
581
-
628
+ }
582
629
 
630
+ // Get available time interval measurement units.
583
631
  function getTimeIntervalMeasurementUnits(allowedUnits, labels, nowLabel) {
584
632
  // Get all time interval measurement units that're available
585
633
  // in locale data for a given time labels style.
586
- var units = Object.keys(labels); // `now` unit is handled separately and is shipped in its own `now.json` file.
634
+ var units = Object.keys(labels);
635
+
636
+ // `now` unit is handled separately and is shipped in its own `now.json` file.
587
637
  // `now.json` isn't present for all locales, so it could be substituted with
588
638
  // ".second.current".
589
639
  // Add `now` unit if it's available in locale data.
590
-
591
640
  if (nowLabel) {
592
641
  units.push('now');
593
- } // If only a specific set of available time measurement units can be used
594
- // then only those units are allowed (if they're present in locale data).
595
-
642
+ }
596
643
 
644
+ // If only a specific set of available time measurement units can be used
645
+ // then only those units are allowed (if they're present in locale data).
597
646
  if (allowedUnits) {
598
647
  units = allowedUnits.filter(function (unit) {
599
648
  return unit === 'now' || units.indexOf(unit) >= 0;
600
649
  });
601
650
  }
602
-
603
651
  return units;
604
652
  }
605
-
606
653
  function getNowLabel(labels, nowLabels, longLabels, future) {
607
- var nowLabel = labels.now || nowLabels && nowLabels.now; // Specific "now" message form extended locale data (if present).
608
-
654
+ var nowLabel = labels.now || nowLabels && nowLabels.now;
655
+ // Specific "now" message form extended locale data (if present).
609
656
  if (nowLabel) {
610
657
  // Bundle size optimization technique.
611
658
  if (typeof nowLabel === 'string') {
612
659
  return nowLabel;
613
- } // Not handling `value === 0` as `localeData.now.current` here
660
+ }
661
+ // Not handling `value === 0` as `localeData.now.current` here
614
662
  // because it wouldn't make sense: "now" is a moment,
615
663
  // so one can't possibly differentiate between a
616
664
  // "previous" moment, a "current" moment and a "next moment".
617
665
  // It can only be differentiated between "past" and "future".
618
-
619
-
620
666
  if (future) {
621
667
  return nowLabel.future;
622
668
  } else {
623
669
  return nowLabel.past;
624
670
  }
625
- } // Use ".second.current" as "now" message.
626
-
627
-
671
+ }
672
+ // Use ".second.current" as "now" message.
628
673
  if (longLabels && longLabels.second && longLabels.second.current) {
629
674
  return longLabels.second.current;
630
675
  }
631
676
  }
632
-
633
677
  function isStyle(variable) {
634
678
  return typeof variable === 'string' || isStyleObject(variable);
635
679
  }
680
+
681
+ // `setTimeout()` function has a bug when it fires immediately
682
+ // when the delay is longer than about `24.85` days.
683
+ // https://stackoverflow.com/questions/3468607/why-does-settimeout-break-for-large-millisecond-delay-values
684
+ //
685
+ // Since `renderLabel()` function uses `setTimeout()` for recursion,
686
+ // that would mean infinite recursion.
687
+ //
688
+ // `setTimeoutSafe()` function works around that bug
689
+ // by capping the delay at the maximum allowed value.
690
+ //
691
+ function setTimeoutSafe(func, delay) {
692
+ return setTimeout(func, getSafeTimeoutDelay(delay));
693
+ }
694
+ function getSafeTimeoutDelay(delay) {
695
+ return Math.min(delay, SET_TIMEOUT_MAX_SAFE_DELAY);
696
+ }
697
+ var SET_TIMEOUT_MAX_SAFE_DELAY = 2147483647;
636
698
  //# sourceMappingURL=TimeAgo.js.map