npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-timeago

v5.1.3

Published

A timeago filter for Vue.

Downloads

31,625

Readme

vue-timeago NPM version NPM downloads Build Status

A timeago component Vue.js

Install

yarn add vue-timeago
# or
npm i vue-timeago

CDN: UNPKG | jsDelivr (available as window.VueTimeago)

Usage

For usages on version 4, please check out this branch.

import VueTimeago from 'vue-timeago'

Vue.use(VueTimeago, {
  name: 'Timeago', // Component name, `Timeago` by default
  locale: 'en', // Default locale
  // We use `date-fns` under the hood
  // So you can use all locales from it
  locales: {
    'zh-CN': require('date-fns/locale/zh_cn'),
    ja: require('date-fns/locale/ja')
  }
})

Then in your lovely component:

<!-- simple usage -->
<!-- time is a dateString that can be parsed by Date.parse() -->
<timeago :datetime="time"></timeago>

<!-- Auto-update time every 60 seconds -->
<timeago :datetime="time" :auto-update="60"></timeago>

<!-- custom locale -->
<!-- use a different locale instead of the global config -->
<timeago :datetime="time" locale="zh-CN"></timeago>

Plugin options

Vue.use(VueTimeago, pluginOptions)

locales

  • Type: { [localeName: string]: any }

An object of locales.

locale

  • Type: string

The default locale name.

converter

  • Type: (date, locale, converterOptions) => string

A converter that formats regular dates in xxx ago or in xxx style.

Check out our default converter which uses date-fns/distance_in_words_to_now under the hood.

converterOptions

  • Type: Object

Provide an object which will be available as argument converterOptions in the converter we mentioned above.

Our default converter supports most options that date-fns/distance_in_words_to_now library supports, namely:

  • includeSeconds: (default: false) distances less than a minute are more detailed
  • addSuffix: (default: true) result specifies if the second date is earlier or later than the first

props

datetime

  • Type: Date string number
  • Required: true

The datetime to be formatted .

autoUpdate

  • Type: number boolean
  • Default: false

The period to update the component, in seconds.

You can omit this prop or set it to 0 or false to disable auto-update.

When true it will be equivalent to 60.

locale

Just like the locale option in the plugin options, but this could override the global one.

converter

Just like the converter option in the plugin options, but this could override the global one.

converterOptions

Just like the converterOptions option in the plugin options, but this could override the global one.

Recipes

Update Locale Globally

Vue.use(VueTimeago, {
  locale: 'en',
  locales: {
    'zh-CN': require('date-fns/locale/zh_cn')
  }
})

In your components you can use this.$timeago.locale to access the global locale, in this case it's en, the <timeago> component will get updated when you set it to another valid locale, e.g. this.$timeago.locale = 'zh-CN'.

What about the good old vue-timeago v3?

The older version (700 bytes gzipped) is much smaller than the current version (2.8kB gzipped) that uses date-fns.

But the current version gives more precise result (and hopefully handles more edge cases), and we don't need to maintain a big list of locale messages because date-fns already did it for us.

Development

# for dev
yarn example

# build in cjs es umd format
yarn build

License

MIT © EGOIST