Giter Site home page Giter Site logo

vue-timeago's Introduction

vue-timeago NPM version NPM downloads Build Status

A timeago component Vue.js

Install

$ npm install --save vue-timeago

It's also available on NPMCDN: https://unpkg.com/vue-timeago/

Usage

import VueTimeago from 'vue-timeago'

Vue.use(VueTimeago, {
  name: 'timeago', // component name, `timeago` by default
  locale: 'en-US',
  locales: {
    // you will need json-loader in webpack 1
    'en-US': require('vue-timeago/locales/en-US.json')
  }
})

Then in your lovely component:

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

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

<!-- max time, time before this will not be converted  -->
<!-- instead you can use a custom formatTime function to format -->
<!-- 86400 * 365 = a year -->
<timeago :since="time" :max-time="86400 * 365" :format="formatTime"></timeago>

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

A very basic demo: https://egoistian.com/vue-timeago

i18n support

For all supported languages, see /locales, it's easy to add a new language support, feel free to submit a Pull Request to help us support more languages!

API

props

since

Type: string (dateString)
Required: true

String value representing a date. The string should be in a format recognized by the Date.parse() method. see more at MDN

max-time

Type: number
Default: 86400 * 365 (a year)

The max time in seconds, time before this will not be converted.

format

Type: function Default: see below

The function we use to format the time before max-time, default function:

// `time` is returned by `new Date(since).getTime()`
function formatTime(time) {
  const d = new Date(time)
  return d.toLocaleString()
}

auto-update

Type: number

The period to update the component, in seconds.

You can set it to 0 to disable auto-update.

locale

Type: string

Specific a locale for relavant component only.

Development

# for dev
$ npm run example

# for publishing
$ npm run build

License

MIT © EGOIST

Sponsor

vue-timeago's People

Contributors

egoist avatar cretueusebiu avatar claudioeyzaguirre avatar hultberg avatar terwanerik avatar gabmic avatar hertzg avatar hendrysadrak avatar riquenunes avatar jezmck avatar johnsardine avatar karlpokus avatar darklow avatar ghimax avatar mel-florance avatar imcvampire avatar blaysku avatar rezahaidari avatar f2face avatar ohida avatar tgezginis avatar vesakk avatar vitorbaraujo avatar wernerm avatar aardloper avatar hotrush avatar lockys avatar lishengzxc avatar npmcdn-to-unpkg-bot avatar sunabozu avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.