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

v2.3.2

Published

vue-timeago3 is a tiny component for Vue.js 3, to show the time passed since a specific date. You simply pass a date and get somewhat like 10 seconds ago, 3 weeks ago, ... printed by the component

Downloads

10,291

Readme

⏳ vue-timeago3

NPM version NPM downloads code-coverage Build Status Vue version date-fns version size

A time ago component for Vue.js 3 based on vue-timeago for Vue 2 by egoist.

Table of Contents

About

vue-timeago3 is a tiny component for Vue.js 3, to show the time passed since a specific date. You simply pass a date and get somewhat like 10 seconds ago, 3 weeks ago, ... printed by the component

Example

| distance to now | result | | --------------- | ------------------------ | | 0 - 5 secs | less than 5 seconds ago | | 5 - 10 secs | less than 10 seconds ago | | 10 - 20 secs | less than 20 seconds ago | | 20 - 40 secs | half a minute ago | | 40 - 60 secs | less than a minute ago |

See date-fns/formatDistanceToNow for more details.

Usage

Visit the docs for more details!

Installation

Currently the plugin is available via NPM and Yarn. To install it use one of the two package managers.

// NPM
$ npm install vue-timeago3

// Yarn
$ yarn add vue-timeago3

Register Plugin

To register the plugin simply import and register it using the new global vue3 api. As an alternative the plugin could be imported in specific components only.

// src/main.ts
import { createApp } from 'vue'
import timeago from 'vue-timeago3'

const app = createApp(App)
...
app.use(timeago) // register timeago
...
app.mount('#app')

Plugin Options

During the registration of the component you can specify a set of options, which will mutate the plugin globally. If you don't want to define global settings, skip this section and use props instead. To use options, simply pass them during the registration as an object:

// src/main.ts
import { createApp } from 'vue'
import timeago from 'vue-timeago3'

const app = createApp(App)
...
// define options
const timeagoOptions = {
  converterOptions: {
      includeSeconds: false,
  }
}

app.use(timeago,  timeagoOptions) // register timeago with options
...
app.mount('#app')

As of version 1.0.0 the following options are available:

| option | type | description | |-----------------------------|----------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | name | string | Register the component with a custom name. Default is: timeago | | locale | Locale (see date-fns/Locale) | The locale specifies the language which is used to render the date. All available date-fns locales are supported by default. | | converter | (date, defaultConvertOptions \| strictConverterOptions) => string | A converter that formats regular dates in x Seconds ago, or in xxx style. Check out the default converter which uses date-fns formatDistanceToNow | | defaultConverterOptions | Object | Pass some extra settings to the default converter mentioned above. It supports the main options of date-fns, namingly: includeSeconds - boolean - distances less than a minute are more detailed addSuffix - boolean - results specifies if now is earlier or later than the date passed useStrict - false - if true you need to use the strictConverterOptions (see below) | | strictConverterOptions | Object | Pass some extra settings to the default converter mentioned above. It supports the main options of date-fns strict converter, namingly: useStrict - true - needs to be true, otherwise the defaultConverterOptions have to be used (see above) addSuffix - boolean - results specifies if now is earlier or later than the date passed unit - second, minute, hour, day, month, year if specified, will force a unitroundingMethod - floor, ceil, round which way to round partial units (default=round) |

Component

Once the plugin is registered you can straight up use it in your app.

Basic usage:

<template>
  <timeago :datetime="date"/>
</template>

<script>
...
data() {
  return {
    date: '2021-09-01'
  }
}
...
</script

Props

Instead of configurating the plugin during the registration, you can also configuate the component via props. | property | type | required | default | description | |----------------------|---------------------------------------------|--------------------|---------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | datetime | string \| Date \| number | :heavy_check_mark: | | The datetime used to calculate the "time ago" | | autoUpdate | number \| boolean | :x: | false | The period of time to update the component, in seconds. This can be omitted by setting it to 0 or false. The default value for true is 60(seconds). Instead of passing true you can also pass a custom time. | | locale | Locale (see date-fns/Locale) | :x: | en | The locale specifies the language which is used to render the date. All available date-fns locales are supported by default. | | converter | date, defaultConverterOptions \| strictConverterOptions) => string | :x: | | See plugin options above | | defaultConverterOptions | Object | :x: | | See plugin options above | | strictConverterOptions | Object | :x: | | See plugin options above |