Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vue-moment

Package Overview
Dependencies
Maintainers
2
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue-moment - npm Package Compare versions

Comparing version 3.2.0 to 4.0.0-0

.editorconfig

15

package.json
{
"name": "vue-moment",
"version": "3.2.0",
"version": "4.0.0-0",
"description": "Handy Moment.js filters for your Vue.js project",
"main": "vue-moment.js",
"scripts": {
"test": "jest"
"test": "jest",
"eslint": "eslint *.js"
},

@@ -36,11 +37,21 @@ "repository": {

"babel-core": "^6.26.0",
"babel-eslint": "^8.0.3",
"babel-jest": "^21.2.0",
"babel-loader": "^7.1.2",
"babel-preset-env": "^1.6.1",
"eslint": "^4.12.1",
"eslint-config-airbnb": "^16.1.0",
"eslint-loader": "^1.9.0",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-jsx-a11y": "^6.0.2",
"eslint-plugin-react": "^7.5.1",
"jest": "^21.2.1",
"jest-cli": "^21.2.1",
"jest-serializer-vue": "^0.2.0",
"jest-vue": "^0.8.1",
"moment-timezone": "^0.5.14",
"pre-commit": "^1.2.2",
"vue": "^2.5.2"
},
"pre-commit": "eslint",
"jest": {

@@ -47,0 +58,0 @@ "moduleFileExtensions": [

# vue-moment
[![npm version](https://badge.fury.io/js/vue-moment.svg)](https://badge.fury.io/js/vue-moment) [![Build Status](https://travis-ci.org/brockpetrie/vue-moment.svg?branch=master)](https://travis-ci.org/brockpetrie/vue-moment)
[![npm version](https://badge.fury.io/js/vue-moment.svg)](https://badge.fury.io/js/vue-moment)
[![Build Status](https://travis-ci.org/brockpetrie/vue-moment.svg?branch=master)](https://travis-ci.org/brockpetrie/vue-moment)
[![Monthly Downloads](https://img.shields.io/npm/dm/vue-moment.svg)](https://www.npmjs.com/package/vue-moment)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
Handy [Moment.js](http://www.momentjs.com) filters for your [Vue.js](http://vuejs.org/) project.

@@ -34,3 +35,3 @@

Moment.js expects your input to be either: a valid ISO 8601 formatted string (see <http://momentjs.com/docs/#/parsing/string/>), a valid `Date` object, a Unix timestamp (in seconds, passed as a Number; if you'd like to pass milliseconds, send as a date object using `new Date(milliseconds)`), or a date string with an accompanying format pattern (i.e. when you know the format of the date input). For the latter, `vue-moment` allows you to pass your date and format pattern(s) as an array, like such:
Moment.js expects your input to be either: a valid ISO 8601 formatted string (see <http://momentjs.com/docs/#/parsing/string/>), a valid `Date` object, a Unix timestamp (in seconds or milliseconds, passed as a Number), or a date string with an accompanying format pattern (i.e. when you know the format of the date input). For the latter, `vue-moment` allows you to pass your date and format pattern(s) as an array, like such:

@@ -67,3 +68,3 @@ ```html

Display a moment in relative time, either from now or from a specified date.
Display a Moment in relative time, either from now or from a specified date.

@@ -99,3 +100,3 @@ **Default** (calculates from current time)

Formats a date with different strings depending on how close to a certain date (today by default) the date is.
Formats a date with different strings depending on how close to a certain date (today by default) the date is. You can also pass a reference date and options.

@@ -116,2 +117,9 @@ **Default** (calculates from current time)

**With options**
```html
<span>{{ new Date() | moment('add', '6 days', 'calendar', null, { nextWeek: '[Happens in a week]' }) }}</span>
<!-- "Happens in a week" -->
```
For more information about `moment#calendar`, check out <http://momentjs.com/docs/#/displaying/calendar-time/>.

@@ -122,3 +130,3 @@

Mutates the original moment by adding time.
Mutates the original Moment by adding time.

@@ -179,2 +187,40 @@ ```html

## Durations
`vue-moment` also provides a `duration` filter that leverages Moment's ability to parse, manipulate and display durations of time. Durations should be passed as either: a String of a valid ISO 8601 formatted duration, a Number of milliseconds, an Array containing a number and unit of measurement (for passing a number other than milliseconds), or an Object of values (for when multiple different units of measurement are needed).
```html
<span>{{ 3600000 | duration('humanize') }}</span>
<!-- "an hour" -->
<span>{{ 'PT1800S' | duration('humanize') }}</span>
<!-- "30 minutes" -->
<span>{{ [35, 'days'] | duration('humanize', true) }}</span>
<!-- "in a month" -->
```
This filter is purely a pass-through proxy to `moment.duration` methods, so pretty much all the functions outlined in their [docs](https://momentjs.com/docs/#/durations/) are callable.
```html
<span>{{ [-1, 'minutes'] | duration('humanize', true) }}</span>
<!-- "a minute ago" -->
<span>{{ { days: 10, months: 1 } | duration('asDays') }}</span>
<!-- "40" -->
<span>{{ 'P3D' | duration('as', 'hours') }}</span>
<!-- "72" -->
```
For manipulating a duration by either subtraction or addition, first use the relevant filter option, then chain your duration display filter.
```html
<span>{{ [1, 'minutes'] | duration('subtract', 120000) | duration('humanize', true) }}</span>
<!-- "a minute ago" -->
<span>{{ [-10, 'minutes'] | duration('add', 'PT11M') | duration('humanize', true) }}</span>
<!-- "in a minute" -->
<span>{{ [2, 'years'] | duration('add', 1, 'year') | duration('humanize') }}</span>
<!-- "3 years" -->
```
`duration` is for contextless lengths of time; for comparing 2 dates, use the `diff` method rather than hacking around with Moment durations. For more information about `moment#duration`, check out <https://momentjs.com/docs/#/durations/>.
## Configuration

@@ -181,0 +227,0 @@

426

tests/vue-moment.spec.js

@@ -1,185 +0,293 @@

import Vue from 'vue/dist/vue'
import VueMoment from '../vue-moment'
import moment from 'moment-timezone'
import moment from 'moment-timezone';
import Vue from 'vue/dist/vue';
import VueMoment from '../vue-moment';
Vue.use(VueMoment, {
moment,
})
moment,
});
let now = moment()
const tomorrow = moment().add(1, 'day')
const now = moment();
const tomorrow = moment().add(1, 'day');
const period = 'P1D';
const vm = new Vue({
template: '<div>{{ now | moment(...args) }}</div>',
data() {
return {
now,
args: [
'YYYY-MM-DD',
],
}
},
template: '<div>{{ now | moment(...args) }}</div>',
data() {
return {
now,
args: [
'YYYY-MM-DD',
],
};
},
}).$mount();
const vmd = new Vue({
template: '<div>{{ period | duration(...args) | duration(...formatter) }}</div>',
data() {
return {
period,
args: [],
formatter: ['humanize', true],
};
},
}).$mount();
describe('VueMoment', () => {
describe('installing plugin', () => {
it('loads prototype', () => {
expect(typeof vm.$moment).toEqual('function')
})
describe('installing plugin', () => {
it('loads prototype', () => {
expect(typeof vm.$moment).toEqual('function');
});
it('prototype works', () => {
expect(vm.$moment(now).format('YYYY-MM-DD')).toEqual(now.format('YYYY-MM-DD'))
})
it('prototype works', () => {
expect(vm.$moment(now).format('YYYY-MM-DD')).toEqual(now.format('YYYY-MM-DD'));
});
it('sets locale', () => {
vm.$moment.locale('fr')
expect(vm.$moment.locale()).toEqual('fr')
})
})
it('sets locale', () => {
vm.$moment.locale('fr');
expect(vm.$moment.locale()).toEqual('fr');
vm.$moment.locale('en');
});
});
describe('using filter', () => {
it('formats date', () => {
expect(vm.$el.textContent).toContain(now.format('YYYY-MM-DD'))
})
describe('using filter', () => {
it('formats date', () => {
expect(vm.$el.textContent).toContain(now.format('YYYY-MM-DD'));
});
describe('relative dates', () => {
it('simple', (done) => {
vm.args = ['from']
vm.$nextTick(() => {
expect(vm.$el.textContent).toContain('a few seconds ago')
done()
})
})
describe('relative dates', () => {
describe('from', () => {
it('simple', (done) => {
vm.args = ['from'];
vm.$nextTick(() => {
expect(vm.$el.textContent).toContain('a few seconds ago');
done();
});
});
it('change reference', (done) => {
vm.args = ['from', tomorrow]
vm.$nextTick(() => {
expect(vm.$el.textContent).toContain('a day ago')
done()
})
})
it('change reference', (done) => {
vm.args = ['from', tomorrow];
vm.$nextTick(() => {
expect(vm.$el.textContent).toContain('a day ago');
done();
});
});
it('remove prefix', (done) => {
vm.args = ['from', tomorrow, true]
vm.$nextTick(() => {
expect(vm.$el.textContent).toContain('a day')
done()
})
})
})
it('remove prefix', (done) => {
vm.args = ['from', tomorrow, true];
vm.$nextTick(() => {
expect(vm.$el.textContent).toContain('a day');
done();
});
});
});
describe('calendar', () => {
it('simple', (done) => {
vm.args = ['calendar']
vm.$nextTick(() => {
expect(vm.$el.textContent).toContain(now.calendar())
done()
})
})
})
describe('calendar', () => {
it('simple', (done) => {
vm.args = ['calendar'];
vm.$nextTick(() => {
expect(vm.$el.textContent).toContain(now.calendar());
done();
});
});
describe('maths', () => {
it('add', (done) => {
vm.args = ['add', '1 day']
vm.$nextTick(() => {
expect(vm.$el.textContent).toContain(now.clone().add(1, 'days').toISOString())
done()
})
})
it('with options', (done) => {
vm.args = ['calendar', tomorrow, { lastDay: '[Yesterday]' }];
vm.$nextTick(() => {
expect(vm.$el.textContent).toContain('Yesterday');
done();
});
});
});
it('subtract', (done) => {
vm.args = ['subtract', '1 day']
vm.$nextTick(() => {
expect(vm.$el.textContent).toContain(now.clone().subtract(1, 'days').toISOString())
done()
})
})
describe('diff', () => {
it('simple', (done) => {
vm.args = ['diff', tomorrow, 'hours'];
vm.$nextTick(() => {
expect(vm.$el.textContent).toContain('24');
done();
});
});
});
});
it('timezone', (done) => {
vm.args = ['timezone', 'America/Los_Angeles', '']
vm.$nextTick(() => {
expect(vm.$el.textContent).toContain(now.clone().tz('America/Los_Angeles').format())
done()
})
})
})
describe('mutations', () => {
it('add', (done) => {
vm.args = ['add', '1 day'];
vm.$nextTick(() => {
expect(vm.$el.textContent).toContain(now.clone().add(1, 'days').toISOString());
done();
});
});
describe('chaining', () => {
it('simple', (done) => {
vm.args = ['add', '1 day', 'YYYY-MM-DD']
vm.$nextTick(() => {
expect(vm.$el.textContent).toContain(now.clone().add(1, 'days').format('YYYY-MM-DD'))
done()
})
})
})
})
it('subtract', (done) => {
vm.args = ['subtract', '1 day'];
vm.$nextTick(() => {
expect(vm.$el.textContent).toContain(now.clone().subtract(1, 'days').toISOString());
done();
});
});
describe('handle inputs', () => {
beforeEach(() => {
global.console.warn = jest.fn()
})
it('utc', (done) => {
vm.args = ['utc'];
vm.$nextTick(() => {
expect(vm.$el.textContent).toContain(now.clone().utc().toISOString());
done();
});
});
afterAll(() => {
vm.now = moment()
})
it('timezone', (done) => {
vm.args = ['timezone', 'America/Los_Angeles'];
vm.$nextTick(() => {
expect(vm.$el.textContent).toContain(now.clone().tz('America/Los_Angeles').toISOString());
done();
});
});
});
it('handles string', (done) => {
vm.now = '2017-01-01'
vm.args = ['YYYY-MM-DD']
vm.$nextTick(() => {
expect(console.warn).not.toBeCalled()
expect(vm.$el.textContent).toContain('2017-01-01')
done()
})
})
it('handles object', (done) => {
vm.now = {y: 2017, m: 1, d: 1}
vm.args = ['YYYY-MM-DD']
vm.$nextTick(() => {
expect(console.warn).not.toBeCalled()
expect(vm.$el.textContent).toContain('2017-01-01')
done()
})
})
describe('chaining', () => {
it('simple', (done) => {
vm.args = ['add', '2 days', 'subtract', '1 day', 'YYYY-MM-DD'];
vm.$nextTick(() => {
expect(vm.$el.textContent).toContain(now.clone().add(1, 'days').format('YYYY-MM-DD'));
done();
});
});
});
it('handles Date object', (done) => {
vm.now = new Date(2017, 0, 1);
vm.args = ['YYYY-MM-DD']
vm.$nextTick(() => {
expect(console.warn).not.toBeCalled()
expect(vm.$el.textContent).toContain('2017-01-01')
done()
})
})
describe('durations', () => {
afterEach(() => {
vmd.period = period;
vmd.args = [];
vmd.formatter = ['humanize', true];
});
it('handles Moment object', (done) => {
vm.now = moment('2017-01-01')
vm.args = ['YYYY-MM-DD']
vm.$nextTick(() => {
expect(console.warn).not.toBeCalled()
expect(vm.$el.textContent).toContain('2017-01-01')
done()
})
})
it('simple humanize', (done) => {
vmd.$nextTick(() => {
expect(vmd.$el.textContent).toContain('in a day');
done();
});
});
it('handles undefined', (done) => {
vm.now = undefined
vm.$nextTick(() => {
expect(console.warn).toBeCalled()
done()
})
})
it('handles invalid string', (done) => {
vm.now = 'foo'
vm.$nextTick(() => {
expect(console.warn).toBeCalled()
done()
})
})
})
})
it('add', (done) => {
vmd.args = ['add', 'P1D'];
vmd.$nextTick(() => {
expect(vmd.$el.textContent).toContain('in 2 days');
done();
});
});
it('subtract', (done) => {
vmd.args = ['subtract', 'P2D'];
vmd.$nextTick(() => {
expect(vmd.$el.textContent).toContain('a day ago');
done();
});
});
it('to string', (done) => {
vmd.period = [5, 'days'];
vmd.formatter = ['toISOString'];
vmd.$nextTick(() => {
expect(vmd.$el.textContent).toContain('P5D');
done();
});
});
it('getter', (done) => {
vmd.formatter = ['asHours'];
vmd.$nextTick(() => {
expect(vmd.$el.textContent).toContain('24');
done();
});
});
});
});
describe('handle inputs', () => {
beforeEach(() => {
global.console.warn = jest.fn();
});
afterAll(() => {
vm.now = moment();
});
it('handles string', (done) => {
vm.now = '2017-01-01';
vm.args = ['YYYY-MM-DD'];
vm.$nextTick(() => {
expect(console.warn).not.toBeCalled();
expect(vm.$el.textContent).toContain('2017-01-01');
done();
});
});
it('handles numeric: seconds', (done) => {
vm.now = 1484438400;
vm.args = ['YYYY-MM'];
vm.$nextTick(() => {
expect(console.warn).not.toBeCalled();
expect(vm.$el.textContent).toContain('2017-01');
done();
});
});
it('handles numeric: milliseconds', (done) => {
vm.now = 1484438400000;
vm.args = ['YYYY-MM'];
vm.$nextTick(() => {
expect(console.warn).not.toBeCalled();
expect(vm.$el.textContent).toContain('2017-01');
done();
});
});
it('handles object', (done) => {
vm.now = { y: 2017, m: 1, d: 1 };
vm.args = ['YYYY-MM-DD'];
vm.$nextTick(() => {
expect(console.warn).not.toBeCalled();
expect(vm.$el.textContent).toContain('2017-01-01');
done();
});
});
it('handles Date object', (done) => {
vm.now = new Date(2017, 0, 1);
vm.args = ['YYYY-MM-DD'];
vm.$nextTick(() => {
expect(console.warn).not.toBeCalled();
expect(vm.$el.textContent).toContain('2017-01-01');
done();
});
});
it('handles Moment object', (done) => {
vm.now = moment('2017-01-01');
vm.args = ['YYYY-MM-DD'];
vm.$nextTick(() => {
expect(console.warn).not.toBeCalled();
expect(vm.$el.textContent).toContain('2017-01-01');
done();
});
});
it('handles undefined', (done) => {
vm.now = undefined;
vm.$nextTick(() => {
expect(console.warn).toBeCalled();
done();
});
});
it('handles invalid string', (done) => {
vm.now = 'foo';
vm.$nextTick(() => {
expect(console.warn).toBeCalled();
expect(vm.$el.textContent).toContain('foo');
done();
});
});
});
});

@@ -0,168 +1,236 @@

let moment = require('moment');
module.exports = {
install: function (Vue, options) {
var moment = options && options.moment ? options.moment : require('moment');
Object.defineProperties(Vue.prototype, {
$moment: {
get: function() {
return moment;
},
},
});
install(Vue, options) {
Object.defineProperties(Vue.prototype, {
$moment: {
get() {
return moment;
},
},
});
Vue.moment = moment
if (options && options.moment) {
moment = options.moment;
}
Vue.filter('moment', function() {
var args = Array.prototype.slice.call(arguments),
input = args.shift(),
date;
Vue.moment = moment;
if (Array.isArray(input) && typeof input[0] === 'string') {
// If input is array, assume we're being passed a format pattern to parse against.
// Format pattern will accept an array of potential formats to parse against.
// Date string should be at [0], format pattern(s) should be at [1]
date = moment(string = input[0], formats = input[1], true);
} else if (typeof input === 'number') {
// If input is an integer, assume it's a Unix timestamp.
date = moment.unix(input);
} else {
// Otherwise, throw the input at moment and see what happens...
date = moment(input);
}
Vue.filter('moment', (...args) => {
args = Array.prototype.slice.call(args);
const input = args.shift();
let date;
if (!input || !date.isValid()) {
// Log a warning if moment couldn't reconcile the input. Better than throwing an error?
console.warn('Could not build a valid `moment` object from input.');
return input;
}
if (Array.isArray(input) && typeof input[0] === 'string') {
// If input is array, assume we're being passed a format pattern to parse against.
// Format pattern will accept an array of potential formats to parse against.
// Date string should be at [0], format pattern(s) should be at [1]
date = moment(input[0], input[1], true);
} else if (typeof input === 'number') {
if (input.toString().length < 12) {
// If input is an integer with fewer than 12 digits, assume Unix seconds...
date = moment.unix(input);
} else {
// ..otherwise, assume milliseconds.
date = moment(input);
}
} else {
// Otherwise, throw the input at moment and see what happens...
date = moment(input);
}
function parse() {
var args = Array.prototype.slice.call(arguments),
method = args.shift();
if (!input || !date.isValid()) {
// Log a warning if moment couldn't reconcile the input. Better than throwing an error?
console.warn('Could not build a valid `moment` object from input.');
return input;
}
switch (method) {
case 'add':
function parse(...args) {
args = Array.prototype.slice.call(args);
const method = args.shift();
// Mutates the original moment by adding time.
// http://momentjs.com/docs/#/manipulating/add/
switch (method) {
case 'add': {
/*
* Mutates the original moment by adding time.
* http://momentjs.com/docs/#/manipulating/add/
*/
var addends = args.shift()
.split(',')
.map(Function.prototype.call, String.prototype.trim);
var obj = {};
for (var n = 0; n < addends.length; n++) {
var addend = addends[n].split(' ');
obj[addend[1]] = addend[0];
}
date = date.add(obj);
break;
const addends = args.shift()
.split(',')
.map(Function.prototype.call, String.prototype.trim);
const obj = {};
case 'subtract':
for (let n = 0; n < addends.length; n++) {
const addend = addends[n].split(' ');
obj[addend[1]] = addend[0];
}
date.add(obj);
break;
}
// Mutates the original moment by subtracting time.
// http://momentjs.com/docs/#/manipulating/subtract/
case 'subtract': {
/*
* Mutates the original moment by subtracting time.
* http://momentjs.com/docs/#/manipulating/subtract/
*/
var subtrahends = args.shift()
.split(',')
.map(Function.prototype.call, String.prototype.trim);
obj = {};
for (var n = 0; n < subtrahends.length; n++) {
var subtrahend = subtrahends[n].split(' ');
obj[subtrahend[1]] = subtrahend[0];
}
date = date.subtract(obj);
break;
const subtrahends = args.shift()
.split(',')
.map(Function.prototype.call, String.prototype.trim);
const obj = {};
case 'from':
for (let n = 0; n < subtrahends.length; n++) {
const subtrahend = subtrahends[n].split(' ');
obj[subtrahend[1]] = subtrahend[0];
}
date.subtract(obj);
break;
}
// Display a moment in relative time, either from now or from a specified date.
// http://momentjs.com/docs/#/displaying/fromnow/
case 'from': {
/*
* Display a moment in relative time, either from now or from a specified date.
* http://momentjs.com/docs/#/displaying/fromnow/
*/
var from = 'now';
if (args[0] == 'now') args.shift();
let from = 'now';
let removeSuffix = false;
if (moment(args[0]).isValid()) {
// If valid, assume it is a date we want the output computed against.
from = moment(args.shift());
}
if (args[0] === 'now') args.shift();
// If valid, assume it is a date we want the output computed against.
if (moment(args[0]).isValid()) from = moment(args.shift());
var removeSuffix = false;
if (args[0] === true) {
args.shift();
var removeSuffix = true;
}
if (args[0] === true) {
args.shift();
removeSuffix = true;
}
if (from != 'now') {
date = date.from(from, removeSuffix);
break;
}
if (from !== 'now') {
date = date.from(from, removeSuffix);
} else {
date = date.fromNow(removeSuffix);
}
break;
}
date = date.fromNow(removeSuffix);
break;
case 'diff':
case 'diff': {
/*
* Mutates the original moment by doing a difference with another date.
* http://momentjs.com/docs/#/displaying/difference/
*/
// Mutates the original moment by doing a difference with another date.
// http://momentjs.com/docs/#/displaying/difference/
let referenceTime = moment();
let units = '';
let float = false;
var dateDiff = 'now';
if (args[0] == 'now') args.shift();
if (moment(args[0]).isValid()) {
// If valid, assume it is a date we want the output computed against.
referenceTime = moment(args.shift());
} else if (args[0] === null || args[0] === 'now') {
// If null or 'now', remove argument and proceed with default referenceTime.
args.shift();
}
if (moment(args[0]).isValid()) {
dateDiff = moment(args.shift());
}
if (args[0]) units = args.shift();
var units = '';
if (args[0]) {
var units = args.shift();
}
if (args[0] === true) float = args.shift();
var floatingValue = false;
if (args[0] === true) {
args.shift();
var floatingValue = true;
}
date = date.diff(referenceTime, units, float);
break;
}
date = date.diff(dateDiff, units, floatingValue)
break;
case 'calendar': {
/*
* Formats a date with different strings depending on how close
* to a certain date (today by default) the date is.
* http://momentjs.com/docs/#/displaying/calendar-time/
*/
case 'calendar':
let referenceTime = moment();
let formats = {};
// Formats a date with different strings depending on how close to a certain date (today by default) the date is.
// http://momentjs.com/docs/#/displaying/calendar-time/
if (moment(args[0]).isValid()) {
// If valid, assume it is a date we want the output computed against.
referenceTime = moment(args.shift());
} else if (args[0] === null || args[0] === 'now') {
// If null or 'now', remove argument and proceed with default referenceTime.
args.shift();
}
var referenceTime = moment();
if (typeof args[0] === 'object') formats = args.shift();
if (moment(args[0]).isValid()) {
// If valid, assume it is a date we want the output computed against.
referenceTime = moment(args.shift());
}
date = date.calendar(referenceTime, formats);
break;
}
date = date.calendar(referenceTime);
break;
case 'utc': {
/*
* Mutates the original moment by converting to UTC
* https://momentjs.com/docs/#/manipulating/utc/
*/
date.utc();
break;
}
case 'timezone':
// Mutates the original moment by converting to a new timezone.
// https://momentjs.com/timezone/docs/#/using-timezones/converting-to-zone/
date = date.tz(args.shift());
break;
case 'timezone': {
/*
* Mutates the original moment by converting to a new timezone.
* https://momentjs.com/timezone/docs/#/using-timezones/converting-to-zone/
*/
date.tz(args.shift());
break;
}
default:
// Format
// Formats a date by taking a string of tokens and replacing them with their corresponding values.
// http://momentjs.com/docs/#/displaying/format/
default: {
/*
* Formats a date by taking a string of tokens and replacing
* them with their corresponding values.
* http://momentjs.com/docs/#/displaying/format/
*/
var format = method;
date = date.format(format);
}
const format = method;
date = date.format(format);
}
}
if (args.length) parse.apply(parse, args);
}
if (args.length) parse.apply(parse, args);
}
parse.apply(parse, args);
parse.apply(parse, args);
return date;
});
return date;
});
},
Vue.filter('duration', (...args) => {
/*
* Basic pass-through filter for leveraging moment.js's ability
* to manipulate and display durations.
* https://momentjs.com/docs/#/durations/
*/
args = Array.prototype.slice.call(args);
const input = args.shift();
const method = args.shift();
function createDuration(time) {
if (!Array.isArray(time)) time = [time];
const result = moment.duration(...time);
if (!result.isValid()) console.warn('Could not build a valid `duration` object from input.');
return result;
}
let duration = createDuration(input);
if (method === 'add' || method === 'subtract') {
// Generates a duration object and either adds or subtracts it
// from our original duration.
const durationChange = createDuration(args);
duration[method](durationChange);
} else if (duration && duration[method]) {
// This gives a full proxy to moment.duration functions.
duration = duration[method](...args);
}
return duration;
});
},
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc