Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/node_modules

npm-debug.log
package-lock.json
14 changes: 13 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ $ npm install vue-moment
Vue.use(require('vue-moment'));
```

...or add it to your component as a local filter:

```js
import {moment} from 'vue-moment'

export default {
filters: {
moment
}
}
```

## Usage

Simply set `moment` as the filtering function and you're good to go. At least one argument is expected, which the filter assumes to be a `format` string if the argument doesn't match any of the other filtering methods.
Expand Down Expand Up @@ -236,7 +248,7 @@ console.log(Vue.moment().locale()) //es

## this.$moment

`vue-moment` attaches the momentjs instance to your Vue app as `this.$moment`.
`vue-moment` attaches the momentjs instance to your Vue app as `this.$moment`.

This allows you to call [the static methods momentjs provides](https://momentjs.com/docs/#/i18n/listing-months-weekdays/).

Expand Down
31 changes: 31 additions & 0 deletions tests/vue-moment.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,27 @@ const vmd = new Vue({
},
}).$mount();

const vml = new Vue({
template: `<div>
<span>{{ now | moment-local(...args) }}</span>
<span>{{ period | duration-local(...args) | duration-local(...formatter) }}</span>
</div>`,
data() {
return {
now,
args: [
'YYYY-MM-DD',
],
formatter: ['humanize', true],
period,
};
},
filters: {
'moment-local': VueMoment.moment,
'duration-local': VueMoment.duration
},
}).$mount();

describe('VueMoment', () => {
describe('installing plugin', () => {
it('loads prototype', () => {
Expand Down Expand Up @@ -290,4 +311,14 @@ describe('VueMoment', () => {
});
});
});

describe('local plugin', () => {
it('supports moment', () => {
expect(vml.$el.textContent).toContain(now.format('YYYY-MM-DD'));
});

it('supports duration', () => {
expect(vmd.$el.textContent).toContain('in a day');
});
})
});
Loading