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