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.
- package/CHANGELOG.md +10 -1
- package/README.md +410 -272
- package/bundle/javascript-time-ago.js +1 -1
- package/bundle/javascript-time-ago.js.map +1 -1
- package/bundle/javascript-time-ago.min.js +1 -1
- package/bundle/javascript-time-ago.min.js.map +1 -1
- package/commonjs/FullDateFormatter.js +72 -0
- package/commonjs/FullDateFormatter.js.map +1 -0
- package/commonjs/FullDateFormatter.test.js +26 -0
- package/commonjs/FullDateFormatter.test.js.map +1 -0
- package/commonjs/LocaleDataStore.js +2 -5
- package/commonjs/LocaleDataStore.js.map +1 -1
- package/commonjs/PropTypes.js +12 -12
- package/commonjs/PropTypes.js.map +1 -1
- package/commonjs/TimeAgo.js +300 -253
- package/commonjs/TimeAgo.js.map +1 -1
- package/commonjs/TimeAgo.test.js +214 -135
- package/commonjs/TimeAgo.test.js.map +1 -1
- package/commonjs/cache.js +7 -25
- package/commonjs/cache.js.map +1 -1
- package/commonjs/cache.test.js +1 -3
- package/commonjs/cache.test.js.map +1 -1
- package/commonjs/isStyleObject.js +9 -9
- package/commonjs/isStyleObject.js.map +1 -1
- package/commonjs/isStyleObject.test.js +1 -3
- package/commonjs/isStyleObject.test.js.map +1 -1
- package/commonjs/locale.js +6 -19
- package/commonjs/locale.js.map +1 -1
- package/commonjs/locale.test.js +2 -11
- package/commonjs/locale.test.js.map +1 -1
- package/commonjs/round.js +2 -5
- package/commonjs/round.js.map +1 -1
- package/commonjs/steps/approximate.js +1 -4
- package/commonjs/steps/approximate.js.map +1 -1
- package/commonjs/steps/approximate.test.js +1 -6
- package/commonjs/steps/approximate.test.js.map +1 -1
- package/commonjs/steps/getStep.js +36 -53
- package/commonjs/steps/getStep.js.map +1 -1
- package/commonjs/steps/getStep.test.js +7 -7
- package/commonjs/steps/getStep.test.js.map +1 -1
- package/commonjs/steps/getStepDenominator.js +2 -5
- package/commonjs/steps/getStepDenominator.js.map +1 -1
- package/commonjs/steps/getStepDenominator.test.js +1 -3
- package/commonjs/steps/getStepDenominator.test.js.map +1 -1
- package/commonjs/steps/getStepMinTime.js +31 -39
- package/commonjs/steps/getStepMinTime.js.map +1 -1
- package/commonjs/steps/getStepMinTime.test.js +1 -3
- package/commonjs/steps/getStepMinTime.test.js.map +1 -1
- package/commonjs/steps/getTimeToNextUpdate.js +27 -41
- package/commonjs/steps/getTimeToNextUpdate.js.map +1 -1
- package/commonjs/steps/getTimeToNextUpdate.test.js +29 -25
- package/commonjs/steps/getTimeToNextUpdate.test.js.map +1 -1
- package/commonjs/steps/getTimeToNextUpdateForUnit.js +3 -12
- package/commonjs/steps/getTimeToNextUpdateForUnit.js.map +1 -1
- package/commonjs/steps/getTimeToNextUpdateForUnit.test.js +1 -7
- package/commonjs/steps/getTimeToNextUpdateForUnit.test.js.map +1 -1
- package/commonjs/steps/helpers.js +1 -2
- package/commonjs/steps/helpers.js.map +1 -1
- package/commonjs/steps/helpers.test.js +0 -1
- package/commonjs/steps/helpers.test.js.map +1 -1
- package/commonjs/steps/index.js +1 -6
- package/commonjs/steps/index.js.map +1 -1
- package/commonjs/steps/renameLegacyProperties.js +6 -14
- package/commonjs/steps/renameLegacyProperties.js.map +1 -1
- package/commonjs/steps/renameLegacyProperties.test.js +1 -3
- package/commonjs/steps/renameLegacyProperties.test.js.map +1 -1
- package/commonjs/steps/round.js +1 -2
- package/commonjs/steps/round.js.map +1 -1
- package/commonjs/steps/round.test.js +1 -7
- package/commonjs/steps/round.test.js.map +1 -1
- package/commonjs/steps/units.js +10 -21
- package/commonjs/steps/units.js.map +1 -1
- package/commonjs/style/approximate.js +2 -6
- package/commonjs/style/approximate.js.map +1 -1
- package/commonjs/style/approximateTime.js +2 -6
- package/commonjs/style/approximateTime.js.map +1 -1
- package/commonjs/style/approximateTime.test.js +116 -75
- package/commonjs/style/approximateTime.test.js.map +1 -1
- package/commonjs/style/getStyleByName.js +3 -29
- package/commonjs/style/getStyleByName.js.map +1 -1
- package/commonjs/style/mini.js +9 -6
- package/commonjs/style/mini.js.map +1 -1
- package/commonjs/style/mini.test.js +15 -25
- package/commonjs/style/mini.test.js.map +1 -1
- package/commonjs/style/miniMinute.js +8 -13
- package/commonjs/style/miniMinute.js.map +1 -1
- package/commonjs/style/miniMinute.test.js +11 -17
- package/commonjs/style/miniMinute.test.js.map +1 -1
- package/commonjs/style/miniMinuteNow.js +8 -13
- package/commonjs/style/miniMinuteNow.js.map +1 -1
- package/commonjs/style/miniMinuteNow.test.js +11 -17
- package/commonjs/style/miniMinuteNow.test.js.map +1 -1
- package/commonjs/style/miniNow.js +8 -13
- package/commonjs/style/miniNow.js.map +1 -1
- package/commonjs/style/miniNow.test.js +11 -17
- package/commonjs/style/miniNow.test.js.map +1 -1
- package/commonjs/style/renameLegacyProperties.js +7 -13
- package/commonjs/style/renameLegacyProperties.js.map +1 -1
- package/commonjs/style/renameLegacyProperties.test.js +1 -4
- package/commonjs/style/renameLegacyProperties.test.js.map +1 -1
- package/commonjs/style/round.js +2 -6
- package/commonjs/style/round.js.map +1 -1
- package/commonjs/style/round.test.js +51 -67
- package/commonjs/style/round.test.js.map +1 -1
- package/commonjs/style/roundMinute.js +8 -13
- package/commonjs/style/roundMinute.js.map +1 -1
- package/commonjs/style/roundMinute.test.js +20 -27
- package/commonjs/style/roundMinute.test.js.map +1 -1
- package/commonjs/style/twitter.js +34 -39
- package/commonjs/style/twitter.js.map +1 -1
- package/commonjs/style/twitter.test.js +54 -57
- package/commonjs/style/twitter.test.js.map +1 -1
- package/commonjs/style/twitterFirstMinute.js +10 -15
- package/commonjs/style/twitterFirstMinute.js.map +1 -1
- package/commonjs/style/twitterFirstMinute.test.js +16 -23
- package/commonjs/style/twitterFirstMinute.test.js.map +1 -1
- package/commonjs/style/twitterMinute.js +8 -13
- package/commonjs/style/twitterMinute.js.map +1 -1
- package/commonjs/style/twitterMinute.test.js +20 -25
- package/commonjs/style/twitterMinute.test.js.map +1 -1
- package/commonjs/style/twitterMinuteNow.js +8 -13
- package/commonjs/style/twitterMinuteNow.js.map +1 -1
- package/commonjs/style/twitterMinuteNow.test.js +20 -25
- package/commonjs/style/twitterMinuteNow.test.js.map +1 -1
- package/commonjs/style/twitterNow.js +8 -13
- package/commonjs/style/twitterNow.js.map +1 -1
- package/commonjs/style/twitterNow.test.js +18 -24
- package/commonjs/style/twitterNow.test.js.map +1 -1
- package/full-date-formatter/index.cjs +4 -0
- package/full-date-formatter/index.cjs.js +9 -0
- package/full-date-formatter/index.d.ts +6 -0
- package/full-date-formatter/index.js +1 -0
- package/full-date-formatter/package.json +15 -0
- package/index.cjs +1 -1
- package/index.cjs.js +2 -2
- package/index.d.ts +14 -4
- package/index.js +3 -1
- package/load-all-locales/index.cjs +32 -0
- package/load-all-locales/index.cjs.js +32 -0
- package/load-all-locales/index.js +64 -0
- package/locale/ak/package.json +16 -0
- package/locale/ak.json +267 -0
- package/locale/ak.json.d.ts +4 -0
- package/locale/ak.json.js +267 -0
- package/locale/bal-Latn/package.json +16 -0
- package/locale/bal-Latn.json +240 -0
- package/locale/bal-Latn.json.d.ts +4 -0
- package/locale/bal-Latn.json.js +240 -0
- package/locale/be-tarask/package.json +16 -0
- package/locale/be-tarask.json +259 -0
- package/locale/be-tarask.json.d.ts +4 -0
- package/locale/be-tarask.json.js +259 -0
- package/locale/blo/package.json +16 -0
- package/locale/blo.json +159 -0
- package/locale/blo.json.d.ts +4 -0
- package/locale/blo.json.js +159 -0
- package/locale/bn.json +5 -2
- package/locale/bn.json.js +5 -2
- package/locale/bs.json +8 -2
- package/locale/bs.json.js +8 -2
- package/locale/ccp.json +2 -8
- package/locale/ccp.json.js +2 -8
- package/locale/csw/package.json +16 -0
- package/locale/csw.json +180 -0
- package/locale/csw.json.d.ts +4 -0
- package/locale/csw.json.js +180 -0
- package/locale/cy.json +6 -12
- package/locale/cy.json.js +6 -12
- package/locale/doi/package.json +16 -0
- package/locale/doi.json +159 -0
- package/locale/doi.json.d.ts +4 -0
- package/locale/doi.json.js +159 -0
- package/locale/en-AU.json +12 -12
- package/locale/en-AU.json.js +12 -12
- package/locale/en-CZ/package.json +16 -0
- package/locale/en-CZ.json +219 -0
- package/locale/en-CZ.json.d.ts +4 -0
- package/locale/en-CZ.json.js +219 -0
- package/locale/en-ES/package.json +16 -0
- package/locale/en-ES.json +219 -0
- package/locale/en-ES.json.d.ts +4 -0
- package/locale/en-ES.json.js +219 -0
- package/locale/en-FR/package.json +16 -0
- package/locale/en-FR.json +219 -0
- package/locale/en-FR.json.d.ts +4 -0
- package/locale/en-FR.json.js +219 -0
- package/locale/en-GS/package.json +16 -0
- package/locale/en-GS.json +219 -0
- package/locale/en-GS.json.d.ts +4 -0
- package/locale/en-GS.json.js +219 -0
- package/locale/en-HU/package.json +16 -0
- package/locale/en-HU.json +219 -0
- package/locale/en-HU.json.d.ts +4 -0
- package/locale/en-HU.json.js +219 -0
- package/locale/en-ID/package.json +16 -0
- package/locale/en-ID.json +219 -0
- package/locale/en-ID.json.d.ts +4 -0
- package/locale/en-ID.json.js +219 -0
- package/locale/en-IT/package.json +16 -0
- package/locale/en-IT.json +219 -0
- package/locale/en-IT.json.d.ts +4 -0
- package/locale/en-IT.json.js +219 -0
- package/locale/en-NO/package.json +16 -0
- package/locale/en-NO.json +219 -0
- package/locale/en-NO.json.d.ts +4 -0
- package/locale/en-NO.json.js +219 -0
- package/locale/en-PL/package.json +16 -0
- package/locale/en-PL.json +219 -0
- package/locale/en-PL.json.d.ts +4 -0
- package/locale/en-PL.json.js +219 -0
- package/locale/en-PT/package.json +16 -0
- package/locale/en-PT.json +219 -0
- package/locale/en-PT.json.d.ts +4 -0
- package/locale/en-PT.json.js +219 -0
- package/locale/en-RO/package.json +16 -0
- package/locale/en-RO.json +219 -0
- package/locale/en-RO.json.d.ts +4 -0
- package/locale/en-RO.json.js +219 -0
- package/locale/en-SK/package.json +16 -0
- package/locale/en-SK.json +219 -0
- package/locale/en-SK.json.d.ts +4 -0
- package/locale/en-SK.json.js +219 -0
- package/locale/es-MX.json +12 -9
- package/locale/es-MX.json.js +12 -9
- package/locale/es-SV.json +2 -2
- package/locale/es-SV.json.js +2 -2
- package/locale/eu.json +24 -24
- package/locale/eu.json.js +24 -24
- package/locale/ha.json +119 -65
- package/locale/ha.json.js +119 -65
- package/locale/he.json +0 -6
- package/locale/he.json.js +0 -6
- package/locale/hi-Latn.json +2 -2
- package/locale/hi-Latn.json.js +2 -2
- package/locale/ht/package.json +16 -0
- package/locale/ht.json +207 -0
- package/locale/ht.json.d.ts +4 -0
- package/locale/ht.json.js +207 -0
- package/locale/id.json +1 -1
- package/locale/id.json.js +1 -1
- package/locale/ie/package.json +16 -0
- package/locale/ie.json +159 -0
- package/locale/ie.json.d.ts +4 -0
- package/locale/ie.json.js +159 -0
- package/locale/ig.json +17 -17
- package/locale/ig.json.js +17 -17
- package/locale/ii/package.json +16 -0
- package/locale/ii.json +165 -0
- package/locale/ii.json.d.ts +4 -0
- package/locale/ii.json.js +165 -0
- package/locale/is.json +4 -1
- package/locale/is.json.js +4 -1
- package/locale/kaa/package.json +16 -0
- package/locale/kaa.json +159 -0
- package/locale/kaa.json.d.ts +4 -0
- package/locale/kaa.json.js +159 -0
- package/locale/kok-Latn/package.json +16 -0
- package/locale/kok-Latn.json +159 -0
- package/locale/kok-Latn.json.d.ts +4 -0
- package/locale/kok-Latn.json.js +159 -0
- package/locale/kok.json +8 -8
- package/locale/kok.json.js +8 -8
- package/locale/ks.json +9 -9
- package/locale/ks.json.js +9 -9
- package/locale/ku.json +55 -46
- package/locale/ku.json.js +55 -46
- package/locale/lld/package.json +16 -0
- package/locale/lld.json +291 -0
- package/locale/lld.json.d.ts +4 -0
- package/locale/lld.json.js +291 -0
- package/locale/mi.json +22 -22
- package/locale/mi.json.js +22 -22
- package/locale/ms-Arab/package.json +16 -0
- package/locale/ms-Arab.json +159 -0
- package/locale/ms-Arab.json.d.ts +4 -0
- package/locale/ms-Arab.json.js +159 -0
- package/locale/nb.json +2 -2
- package/locale/nb.json.js +2 -2
- package/locale/ne.json +1 -1
- package/locale/ne.json.js +1 -1
- package/locale/nn.json +4 -4
- package/locale/nn.json.js +4 -4
- package/locale/no.json +2 -2
- package/locale/no.json.js +2 -2
- package/locale/nqo/package.json +16 -0
- package/locale/nqo.json +159 -0
- package/locale/nqo.json.d.ts +4 -0
- package/locale/nqo.json.js +159 -0
- package/locale/om/package.json +16 -0
- package/locale/om.json +213 -0
- package/locale/om.json.d.ts +4 -0
- package/locale/om.json.js +213 -0
- package/locale/or.json +1 -1
- package/locale/or.json.js +1 -1
- package/locale/qu.json +46 -46
- package/locale/qu.json.js +46 -46
- package/locale/rhg/package.json +16 -0
- package/locale/rhg.json +159 -0
- package/locale/rhg.json.d.ts +4 -0
- package/locale/rhg.json.js +159 -0
- package/locale/sl.json +12 -12
- package/locale/sl.json.js +12 -12
- package/locale/sr-Cyrl-BA.json +2 -2
- package/locale/sr-Cyrl-BA.json.js +2 -2
- package/locale/sr-Latn-BA.json +2 -2
- package/locale/sr-Latn-BA.json.js +2 -2
- package/locale/sv.json +1 -1
- package/locale/sv.json.js +1 -1
- package/locale/syr/package.json +16 -0
- package/locale/syr.json +303 -0
- package/locale/syr.json.d.ts +4 -0
- package/locale/syr.json.js +303 -0
- package/locale/ti.json +6 -6
- package/locale/ti.json.js +6 -6
- package/locale/tn/package.json +16 -0
- package/locale/tn.json +159 -0
- package/locale/tn.json.d.ts +4 -0
- package/locale/tn.json.js +159 -0
- package/locale/to.json +26 -26
- package/locale/to.json.js +26 -26
- package/locale/uk.json +1 -1
- package/locale/uk.json.js +1 -1
- package/locale/ur-IN.json +9 -6
- package/locale/ur-IN.json.js +9 -6
- package/locale/vec/package.json +16 -0
- package/locale/vec.json +267 -0
- package/locale/vec.json.d.ts +4 -0
- package/locale/vec.json.js +267 -0
- package/locale/xnr/package.json +16 -0
- package/locale/xnr.json +159 -0
- package/locale/xnr.json.d.ts +4 -0
- package/locale/xnr.json.js +159 -0
- package/locale/yo-BJ.json +17 -17
- package/locale/yo-BJ.json.js +17 -17
- package/locale/yo.json +17 -17
- package/locale/yo.json.js +17 -17
- package/modules/FullDateFormatter.js +67 -0
- package/modules/FullDateFormatter.js.map +1 -0
- package/modules/FullDateFormatter.test.js +22 -0
- package/modules/FullDateFormatter.test.js.map +1 -0
- package/modules/LocaleDataStore.js +2 -3
- package/modules/LocaleDataStore.js.map +1 -1
- package/modules/PropTypes.js +11 -7
- package/modules/PropTypes.js.map +1 -1
- package/modules/TimeAgo.js +299 -237
- package/modules/TimeAgo.js.map +1 -1
- package/modules/TimeAgo.test.js +217 -119
- package/modules/TimeAgo.test.js.map +1 -1
- package/modules/cache.js +6 -22
- package/modules/cache.js.map +1 -1
- package/modules/cache.test.js.map +1 -1
- package/modules/isStyleObject.js +9 -7
- package/modules/isStyleObject.js.map +1 -1
- package/modules/isStyleObject.test.js.map +1 -1
- package/modules/locale.js +6 -16
- package/modules/locale.js.map +1 -1
- package/modules/locale.test.js +0 -4
- package/modules/locale.test.js.map +1 -1
- package/modules/round.js +2 -3
- package/modules/round.js.map +1 -1
- package/modules/steps/approximate.js +6 -2
- package/modules/steps/approximate.js.map +1 -1
- package/modules/steps/approximate.test.js +0 -2
- package/modules/steps/approximate.test.js.map +1 -1
- package/modules/steps/getStep.js +36 -48
- package/modules/steps/getStep.js.map +1 -1
- package/modules/steps/getStep.test.js +6 -2
- package/modules/steps/getStep.test.js.map +1 -1
- package/modules/steps/getStepDenominator.js +2 -3
- package/modules/steps/getStepDenominator.js.map +1 -1
- package/modules/steps/getStepDenominator.test.js.map +1 -1
- package/modules/steps/getStepMinTime.js +31 -36
- package/modules/steps/getStepMinTime.js.map +1 -1
- package/modules/steps/getStepMinTime.test.js.map +1 -1
- package/modules/steps/getTimeToNextUpdate.js +28 -32
- package/modules/steps/getTimeToNextUpdate.js.map +1 -1
- package/modules/steps/getTimeToNextUpdate.test.js +27 -18
- package/modules/steps/getTimeToNextUpdate.test.js.map +1 -1
- package/modules/steps/getTimeToNextUpdateForUnit.js +4 -10
- package/modules/steps/getTimeToNextUpdateForUnit.js.map +1 -1
- package/modules/steps/getTimeToNextUpdateForUnit.test.js +0 -4
- package/modules/steps/getTimeToNextUpdateForUnit.test.js.map +1 -1
- package/modules/steps/helpers.js +1 -1
- package/modules/steps/helpers.js.map +1 -1
- package/modules/steps/helpers.test.js.map +1 -1
- package/modules/steps/index.js +2 -1
- package/modules/steps/index.js.map +1 -1
- package/modules/steps/renameLegacyProperties.js +6 -13
- package/modules/steps/renameLegacyProperties.js.map +1 -1
- package/modules/steps/renameLegacyProperties.test.js.map +1 -1
- package/modules/steps/round.js.map +1 -1
- package/modules/steps/round.test.js +0 -3
- package/modules/steps/round.test.js.map +1 -1
- package/modules/steps/units.js +5 -9
- package/modules/steps/units.js.map +1 -1
- package/modules/style/approximate.js +5 -1
- package/modules/style/approximate.js.map +1 -1
- package/modules/style/approximateTime.js +6 -2
- package/modules/style/approximateTime.js.map +1 -1
- package/modules/style/approximateTime.test.js +115 -70
- package/modules/style/approximateTime.test.js.map +1 -1
- package/modules/style/getStyleByName.js +4 -17
- package/modules/style/getStyleByName.js.map +1 -1
- package/modules/style/mini.js +8 -4
- package/modules/style/mini.js.map +1 -1
- package/modules/style/mini.test.js +14 -20
- package/modules/style/mini.test.js.map +1 -1
- package/modules/style/miniMinute.js +6 -6
- package/modules/style/miniMinute.js.map +1 -1
- package/modules/style/miniMinute.test.js +10 -12
- package/modules/style/miniMinute.test.js.map +1 -1
- package/modules/style/miniMinuteNow.js +6 -6
- package/modules/style/miniMinuteNow.js.map +1 -1
- package/modules/style/miniMinuteNow.test.js +10 -12
- package/modules/style/miniMinuteNow.test.js.map +1 -1
- package/modules/style/miniNow.js +6 -6
- package/modules/style/miniNow.js.map +1 -1
- package/modules/style/miniNow.test.js +10 -12
- package/modules/style/miniNow.test.js.map +1 -1
- package/modules/style/renameLegacyProperties.js +8 -10
- package/modules/style/renameLegacyProperties.js.map +1 -1
- package/modules/style/renameLegacyProperties.test.js +0 -1
- package/modules/style/renameLegacyProperties.test.js.map +1 -1
- package/modules/style/round.js +3 -2
- package/modules/style/round.js.map +1 -1
- package/modules/style/round.test.js +50 -62
- package/modules/style/round.test.js.map +1 -1
- package/modules/style/roundMinute.js +8 -7
- package/modules/style/roundMinute.js.map +1 -1
- package/modules/style/roundMinute.test.js +19 -22
- package/modules/style/roundMinute.test.js.map +1 -1
- package/modules/style/twitter.js +36 -33
- package/modules/style/twitter.js.map +1 -1
- package/modules/style/twitter.test.js +53 -52
- package/modules/style/twitter.test.js.map +1 -1
- package/modules/style/twitterFirstMinute.js +8 -7
- package/modules/style/twitterFirstMinute.js.map +1 -1
- package/modules/style/twitterFirstMinute.test.js +15 -18
- package/modules/style/twitterFirstMinute.test.js.map +1 -1
- package/modules/style/twitterMinute.js +6 -6
- package/modules/style/twitterMinute.js.map +1 -1
- package/modules/style/twitterMinute.test.js +19 -20
- package/modules/style/twitterMinute.test.js.map +1 -1
- package/modules/style/twitterMinuteNow.js +6 -6
- package/modules/style/twitterMinuteNow.js.map +1 -1
- package/modules/style/twitterMinuteNow.test.js +19 -20
- package/modules/style/twitterMinuteNow.test.js.map +1 -1
- package/modules/style/twitterNow.js +6 -6
- package/modules/style/twitterNow.js.map +1 -1
- package/modules/style/twitterNow.test.js +17 -19
- package/modules/style/twitterNow.test.js.map +1 -1
- package/package.json +275 -13
package/commonjs/TimeAgo.js
CHANGED
|
@@ -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
|
|
31
|
-
|
|
32
|
-
function
|
|
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
|
|
41
|
-
|
|
42
|
-
function
|
|
43
|
-
|
|
44
|
-
function
|
|
45
|
-
|
|
46
|
-
function
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
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
|
-
}
|
|
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
|
-
}
|
|
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
|
-
}
|
|
99
|
-
|
|
68
|
+
}
|
|
100
69
|
|
|
101
|
-
|
|
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
|
-
|
|
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
|
-
|
|
153
|
-
|
|
125
|
+
labels = _this$getLabels.labels,
|
|
126
|
+
labelsType = _this$getLabels.labelsType;
|
|
154
127
|
|
|
155
|
-
|
|
156
|
-
//
|
|
157
|
-
|
|
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
|
-
}
|
|
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 =
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
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
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
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
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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,
|
|
258
|
-
var
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
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,
|
|
321
|
+
formatAs: function formatAs(unit, amount) {
|
|
275
322
|
// Mimicks `Intl.RelativeTimeFormat.format()`.
|
|
276
|
-
return
|
|
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
|
-
}
|
|
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
|
-
}
|
|
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
|
-
}
|
|
343
|
+
}
|
|
298
344
|
|
|
345
|
+
// Amount in units.
|
|
346
|
+
var amount = Math.abs(secondsPassed) / (0, _getStepDenominator["default"])(step);
|
|
299
347
|
|
|
300
|
-
|
|
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
|
-
|
|
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,
|
|
360
|
-
var labels =
|
|
361
|
-
|
|
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,
|
|
381
|
-
var 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];
|
|
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
|
-
}
|
|
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;
|
|
399
|
-
|
|
442
|
+
var quantifierRules = formattingRules[pastOrFuture] || formattingRules;
|
|
443
|
+
// Bundle size optimization technique.
|
|
400
444
|
if (typeof quantifierRules === 'string') {
|
|
401
445
|
return quantifierRules;
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
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
|
-
}
|
|
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
|
-
});
|
|
480
|
-
// (it's always present for all languages)
|
|
520
|
+
});
|
|
481
521
|
|
|
482
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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);
|
|
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
|
-
};
|
|
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
|
-
}
|
|
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
|
-
}
|
|
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
|
-
}
|
|
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);
|
|
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
|
-
}
|
|
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;
|
|
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
|
-
}
|
|
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
|
-
}
|
|
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
|