vue-dayjs

Handy dayjs(2KB immutable date library alternative to Moment.js) filters and directives for Vue.js
59,265
Install
npm install vue-dayjs
Latest Version:1.0.2
License:MIT
Last Updated:May 10, 2018
Links: npm
Maintainer: linyupark

vue-dayjs

Handy Day.js filters and directives for Vue.js

Day.js is a minimalist (Fast 2kB) JavaScript library for modern browsers with a largely Moment.js-compatible API. If you use Moment.js, you already know how to use Day.js.

How to use

import Dayjs from 'vue-dayjs';

Vue.use(Dayjs, {
  // language set, default cn
  lang?: cn | en,
  /**
   * addon filters { key: filter name }
   * if set {} will only dayjs base filter can use.
   */
  filters?: {
    ago: 'ago',
    ...
  },
  /**
   * addon directives { key: directives name }
   * set {} to disable.
   */
  directives?: {
    countdown: 'countdown',
    ...
  }
});

new Vue({...});

Notice this plugin esm format only and it will take effect automatic.

Filtering Methods

Format

<span>{{ someDate | dayjs('YYYY-MM-DD') }}</span>

Add

<span>{{ someDate | dayjs('add', 1, 'day') }}</span>

Subtract

<span>{{ someDate | dayjs('subtract', 1, 'day') }}</span>

Unix Timestamp (milliseconds)

<span>{{ someDate | dayjs('valueOf') }}</span>

Unix Timestamp (seconds)

<span>{{ someDate | dayjs('unix') }}</span>

Days in Month

<span>{{ someDate | dayjs('daysInMonth') }}</span>

As JSON

<span>{{ someDate | dayjs('toJSON') }}</span>

As Array

<span>{{ someDate | dayjs('toArray') }}</span>

As Object

<span>{{ someDate | dayjs('toObject') }}</span>

Is Leap Year

<span>{{ someDate | dayjs('isLeapYear') }}</span>

Difference

<span>{{ someDate | dayjs('diff', anotherDate) }}</span>

Addon filter : xx ago

<span>{{ someDate | ago }}</span>

Addon directive : countdown

<v-countdown="{target: someDate, format: 'DD days HH:mm:ss'}" />

Method inject

Also can use dayjs in your logic layer.

created() {
  this.$dayjs().format('YYYY-MM-DD HH:mm:ss');
}

Related Packages

vue-moment-filter

Vue moment filter

2,974 1
dayjs-nuxt

Day.JS Module for Nuxt

1,986,864 126
node-esm-loader

A webpack-like loader for Node

48,094 8
vue-dayjs-plugin

A small wrapper for integrating dayjs to Vuejs

31,284 15
@dracul/dayjs-frontend

vue dayjs utils

3,079 4

Version History

Version Released License
1.0.2 MIT
1.0.1 MIT
1.0.0 MIT