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