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