@urcloud/timeago
TypeScript icon, indicating that this package has built-in type declarations

1.1.5 • Public • Published

timeago

timeago like douban & zhihu for social community.

Install

npm i @urcloud/timeago -S

Usage

import timeago from '@urcloud/timeago'
timeago.register('customType', [
  {
    label: 'IN_5_MIN',
    parse: (diffSeconds: number, date: Date, locale: string) => {
      const locales = {
        zh_CN: '刚刚',
        en_US: 'now',
      }
      return locales[locale]
    },
  },
  {
    label: 'IN_1_HOUR',
    parse: (diffSeconds: number, date: Date, locale: string) => {
      const locales = {
        zh_CN: '%s分钟前',
        en_US: '%sm ago',
      }
      let value = Math.floor(diffSeconds / 60)
      return locales[locale].replace(/%s/gi, value)
    },
  },
])
timeago(new Date())
timeago(1544666010224)
timeago('2018-12-12', 'customType')

Dependencies (0)

    Dev Dependencies (5)

    Package Sidebar

    Install

    npm i @urcloud/timeago

    Weekly Downloads

    0

    Version

    1.1.5

    License

    MIT

    Unpacked Size

    36.8 kB

    Total Files

    19

    Last publish

    Collaborators

    • zenonux