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-timeago2

v1.0.2

Published

A timeago filter for Vue using date-fns.

Downloads

5

Readme

vue-timeago2 NPM version NPM downloads

A timeago component Vue.js

Install

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

Usage

import VueTimeago2 from "vue-timeago2";

Vue.use(VueTimeago2, {
  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/index"),
    es: require("date-fns/locale/es/index")
  }
});

Then in your lovely component:

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

<!-- Convert type -->
<!-- You can use both converters by default: default or strict -->
<timeago :datetime="time" typeConvert="strict"></timeago>
//return '6 months'

<!-- 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, in xxx or xxx days style.

We have two converters that format time: toNow and Strict. usando date-fns 2.8.1

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 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
  • roundingMethod (default: rounded) only for strict type conversion

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.

typeConvert

  • default: Return the distance between the given dates in words.
  • strict: Return the distance between the given dates in words, using strict units. This is like formatDistance, but does not use helpers like 'almost', 'over', 'less than' and the like.`

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/index")
  }
});

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'.

License

MIT © Wimil