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