Vuejs-Vue moment lib: vue-moment-lib - A simple Vue.js 2.0 MomentJS library (filters & globals) using the same momentjs API.

vue-moment-lib

Jest Vue semantic-release Npm badge Build Status Greenkeeper badge

A Vue.js 2.0 MomentJS library

Make momentjs available in your template and Vue instance. Since it just try to map raw js function, api is mostly same as momentjs.com. Making it easier to use in your Vue.js projects.

It added moment parse api as filters, component and vue instance moment functions mapping.

Installation

npm install --save moment vue-moment-lib

vue-moment-lib can be used as a module in CommonJS environments.

When in non-modular environment, vue-moment-lib will register all the components to vue by itself.

ES6

//
// Register the whole module with vue
//
import VueMomentLib from "vue-moment-lib";

// Install this library
Vue.use(VueMomentLib);

CommonJS

//
// Register the whole module with vue
//
var Vue = require("vue");
var VueMomentLib = require("vue-moment-lib").default;

// Install this library
Vue.use(VueMomentLib);

Browser

<script src="path/to/vue/vue.min.js"></script>
<script src="path/to/moment/moment.min.js"></script>
<script src="path/to/vue-moment-lib/dist/vue-moment-lib.umd.min.js"></script>
<!-- Filter and moment are registered globally -->

After that, you can use the duration and moment filters in your templates, api is slightly different as the first argument is passed through pipe:

<!-- first argument of moment filter is a parameter for parsing to UTC, it is set by default to false so it is optional when you use default parsing -->

<!-- Local format -->
<span>{{ Date.now() | moment().format("YYYY") }}</span>

<!-- time alias, isLocal + custom parsing + custom format -->
<span>{{ "11-14-2018" | time("MM-DD-YYYY").format("YYYY") }}</span>

<!--  Unix timestamp to utc -->
<span>{{ 1318781876 | unix().utc() }}</span>

<!-- Full date -->
<span>{{ Date.now() | utc().format("LLLL") }}</span>

<!-- -780 -->
<span>{{ "2013-01-01T00:00:00-13:00" | zone().utcOffset() }}</span>

<!-- a few seconds -->
<span>{{ 500 | duration().humanize() }}</span>

<!-- is not a duration -->
<span>{{ new Date() | isDuration }}</span>

And also, use the component instance functions in your templates to really use the same apis as momentjs:

<!-- Local format -->
<span>{{ $moment(Date.now()).format("YYYY") }}</span>

<!-- time alias, isLocal + custom parsing + custom format -->
<span>{{ $time("11-14-2018", "MM-DD-YYYY").format("YYYY") }}</span>

<!--  Unix timestamp to utc -->
<span>{{ $unix(1318781876).utc() }}</span>

<!-- Full date -->
<span>{{ $utc(Date.now()).format("LLLL") }}</span>

<!-- -780 -->
<span>{{ $zone("2013-01-01T00:00:00-13:00").utcOffset() }}</span>

<!-- a few seconds -->
<span>{{ $duration(500).humanize() }}</span>

<!-- is not a duration -->
<span>{{ $isDuration(new Date()) }}</span>

or

// in your components
computed: {
  thisYear () {
    // return this.$moment(Date.now()).format()
    return this.$time(Date.now()).format("YYYY") // moment (alias)
  },
  unixUtc () {
    return this.$unix(1318781876).utc(); // moment.unix
  },
  utc () {
    return this.$utc(Date.now()).format("LLLL"); // moment.utc
  },
  parseZone () {
    return this.$zone("2013-01-01T00:00:00-13:00").utcOffset(); // moment.parseZone
  },
  humanize () {
    return this.$duration(500).humanize(); // moment.duration
  },
  isDuration () {
    return this.$isDuration(new Date()); // moment.isDuration
  }
}

// it is also registered as a global function in the Vue instance
// so you can do in vuex store or everywhere else to retrieve the same moment instance you initialized
import Vue from 'vue'

const thisYear = Vue.time(Date.now()).format("YYYY"); // alias to moment
const unixUtc = Vue.unix(1318781876).utc();
const utc = Vue.utc(Date.now()).format("LLLL");
const parseZone = Vue.zone("2013-01-01T00:00:00-13:00").utcOffset();
const humanize = Vue.duration(500).humanize();
const isDuration = Vue.isDuration(new Date());

Custom moment instances

import yourMoment from "moment";
import VueMomentLib from "vue-moment-lib";

//
// customize your moment instance here (locales, config, etc)
//

// Install this library with custom moment instance
Vue.use(VueMomentLib, { moment: yourMoment });

Changelog

See the GitHub release history.

Contributing

See CONTRIBUTING.md.

Comments

  • Update @semantic-release/git to the latest version ?
    Update @semantic-release/git to the latest version ?

    Oct 17, 2018

    The devDependency @semantic-release/git was updated from 7.0.4 to 7.0.5.

    This version is not covered by your current version range.

    If you don’t accept this pull request, your project will work just like it did before. However, you might be missing out on a bunch of new features, fixes and/or performance improvements from the dependency update.


    Release Notes for v7.0.5

    7.0.5 (2018-10-08)

    Bug Fixes

    • use default value for null options (e1aac3d)
    Commits

    The new version differs by 3 commits.

    • e1aac3d fix: use default value for null options
    • 15208d8 docs: harmonize docs with other plugins
    • 39abf04 chore(package): update commitizen to version 3.0.0

    See the full diff

    FAQ and help

    There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


    Your Greenkeeper bot :palm_tree:

    greenkeeper 
    Reply
  • Update @semantic-release/changelog to the latest version ?
    Update @semantic-release/changelog to the latest version ?

    Oct 17, 2018

    The devDependency @semantic-release/changelog was updated from 3.0.0 to 3.0.1.

    This version is not covered by your current version range.

    If you don’t accept this pull request, your project will work just like it did before. However, you might be missing out on a bunch of new features, fixes and/or performance improvements from the dependency update.


    Release Notes for v3.0.1

    3.0.1 (2018-10-08)

    Bug Fixes

    • use default value for null options (92608a3)
    Commits

    The new version differs by 5 commits.

    • 92608a3 fix: use default value for null options
    • 1b291d8 docs: harmonize docs with other plugins
    • a1266a1 chore(package): update commitizen to version 3.0.0
    • 1c39499 chore(package): update xo to version 0.23.0
    • 63df33f chore(package): update xo to version 0.22.0

    See the full diff

    FAQ and help

    There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


    Your Greenkeeper bot :palm_tree:

    greenkeeper 
    Reply
  • Update @vue/test-utils to the latest version ?
    Update @vue/test-utils to the latest version ?

    Nov 26, 2018

    The devDependency @vue/test-utils was updated from 1.0.0-beta.25 to 1.0.0-beta.26.

    This version is not covered by your current version range.

    If you don’t accept this pull request, your project will work just like it did before. However, you might be missing out on a bunch of new features, fixes and/or performance improvements from the dependency update.


    Find out more about this release.

    FAQ and help

    There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


    Your Greenkeeper bot :palm_tree:

    greenkeeper 
    Reply
  • Update vue-template-compiler to the latest version ?
    Update vue-template-compiler to the latest version ?

    Dec 7, 2018

    The devDependency vue-template-compiler was updated from 2.5.16 to 2.5.18.

    This version is not covered by your current version range.

    If you don’t accept this pull request, your project will work just like it did before. However, you might be missing out on a bunch of new features, fixes and/or performance improvements from the dependency update.


    Find out more about this release.

    FAQ and help

    There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


    Your Greenkeeper bot :palm_tree:

    greenkeeper 
    Reply
  • Update vue to the latest version ?
    Update vue to the latest version ?

    Dec 7, 2018

    The dependency vue was updated from 2.5.16 to 2.5.18.

    This version is not covered by your current version range.

    If you don’t accept this pull request, your project will work just like it did before. However, you might be missing out on a bunch of new features, fixes and/or performance improvements from the dependency update.


    Release Notes for v2.5.18

    Includes everything in 2.5.18-beta.0

    Bug Fixes

    Commits

    The new version differs by 164 commits.

    • dadc918 build: release 2.5.18
    • eb81ec2 build: build 2.5.18
    • dfaf9e2 fix(types): type support for advanced async components (#8438)
    • 8a2dbf5 fix(transition-group): fix activeInstance regression
    • 0ed0aad fix: fix keyName checking for space and delete in IE11 (#9150)
    • f077ed1 fix(ssr): fix ssr template publicPath generation
    • 93850f4 chore: fix sponsor link
    • 1b4a8a0 fix(compiler): fix codegen for v-for component inside template
    • 448ba65 fix(types): correct scopedSlot types (#9131)
    • 0d7fb73 chore: update sponsors/backers [ci skip]
    • e8031b4 build: release v2.5.18-beta.0
    • fe194dd build: build v2.5.18-beta.0
    • 3078352 fix(ssr): resolve server directives the same as on client (#9129)
    • aca17b4 ci: add regression test for popular libraries in Vue.js ecosystem (#8608)
    • e4b1b57 fix(ssr): adjust call stack size defer threshold

    There are 164 commits in total.

    See the full diff

    FAQ and help

    There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


    Your Greenkeeper bot :palm_tree:

    greenkeeper 
    Reply
  • Create a typings file?
    Create a typings file?

    Jun 26, 2019

    I'd love to have typescript compatibility out of the box.

    Reply
  • Update rollup to the latest version ?
    Update rollup to the latest version ?

    Jun 20, 2018

    Version 0.61.0 of rollup was just published.

    Dependency [rollup](https://github.com/rollup/rollup)
    Current Version 0.60.7
    Type devDependency

    The version 0.61.0 is not covered by your current version range.

    If you don’t accept this pull request, your project will work just like it did before. However, you might be missing out on a bunch of new features, fixes and/or performance improvements from the dependency update.

    It might be worth looking into these changes and trying to get this project onto the latest version of rollup.

    If you have a solid test suite and good coverage, a passing build is a strong indicator that you can take advantage of these changes directly by merging the proposed change into your project. If the build fails or you don’t have such unconditional trust in your tests, this branch is a great starting point for you to work on the update.


    Commits

    The new version differs by 24 commits.

    • 8112edc 0.61.0
    • 2361e3d Fix memory leak, remove solo from test and fix tests by adding proper default
    • 9fc1294 Add release date
    • 43d01fd Update changelog
    • d4aed73 Allow to disable __esModule (#2287)
    • 9de98ce Update changelog
    • 605bdfc add vscode debugger settings (#2276)
    • 2ce4a28 Merge branch 'double-declarations'
    • 8cacd62 Separate collection and reassignment of initializers for double declarations
    • 39cc149 Skip default property test on node 4
    • dd35b6e Track reassignments of array elements
    • 7911882 Track reassignments of pattern defaults
    • 6bedd8c * No longer reassign variable initializers during initialization phase
    • 41d6fe8 Merge branch 'transform-dependencies'
    • 1b18909 feature: transform dependencies (#1203), watcher fixes #2280, #2281

    There are 24 commits in total.

    See the full diff

    FAQ and help

    There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


    Your Greenkeeper bot :palm_tree:

    greenkeeper 
    Reply
  • An in-range update of semantic-release is breaking the build ?
    An in-range update of semantic-release is breaking the build ?

    Aug 10, 2018

    Version 15.9.7 of semantic-release was just published.

    Branch Build failing ?
    Dependency semantic-release
    Current Version 15.9.6
    Type devDependency

    This version is covered by your current version range and after updating it in your project the build failed.

    semantic-release is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

    Status Details
    • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

    Release Notes v15.9.7

    15.9.7 (2018-08-10)

    Reverts

    • "fix: do not convert ssh repositoryUrl to https" (93377eb)
    Commits

    The new version differs by 1 commits.

    • 93377eb revert: "fix: do not convert ssh repositoryUrl to https"

    See the full diff

    FAQ and help

    There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


    Your Greenkeeper Bot :palm_tree:

    greenkeeper 
    Reply
  • Update semantic-release to the latest version ?
    Update semantic-release to the latest version ?

    Aug 26, 2018

    Version 15.9.11 of semantic-release was just published.

    Dependency semantic-release
    Current Version 15.9.9
    Type devDependency

    The version 15.9.11 is not covered by your current version range.

    If you don’t accept this pull request, your project will work just like it did before. However, you might be missing out on a bunch of new features, fixes and/or performance improvements from the dependency update.

    It might be worth looking into these changes and trying to get this project onto the latest version of semantic-release.

    If you have a solid test suite and good coverage, a passing build is a strong indicator that you can take advantage of these changes directly by merging the proposed change into your project. If the build fails or you don’t have such unconditional trust in your tests, this branch is a great starting point for you to work on the update.


    Release Notes v15.9.11

    15.9.11 (2018-08-26)

    Bug Fixes

    • package: update execa to version 1.0.0 (1aed97e)
    Commits

    The new version differs by 2 commits.

    • 1aed97e fix(package): update execa to version 1.0.0
    • edd8bc2 fix(package): update execa to version 0.11.0

    See the full diff

    FAQ and help

    There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


    Your Greenkeeper bot :palm_tree:

    greenkeeper 
    Reply
  • Update vue-loader to the latest version ?
    Update vue-loader to the latest version ?

    Apr 25, 2018

    Version 15.0.1 of vue-loader was just published.

    Dependency vue-loader
    Current Version 14.2.2
    Type devDependency

    The version 15.0.1 is not covered by your current version range.

    If you don’t accept this pull request, your project will work just like it did before. However, you might be missing out on a bunch of new features, fixes and/or performance improvements from the dependency update.

    It might be worth looking into these changes and trying to get this project onto the latest version of vue-loader.

    If you have a solid test suite and good coverage, a passing build is a strong indicator that you can take advantage of these changes directly by merging the proposed change into your project. If the build fails or you don’t have such unconditional trust in your tests, this branch is a great starting point for you to work on the update.


    FAQ and help

    There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


    Your Greenkeeper bot :palm_tree:

    greenkeeper 
    Reply
  • Update rollup-plugin-vue to the latest version ?
    Update rollup-plugin-vue to the latest version ?

    May 2, 2018

    Version 4.0.1 of rollup-plugin-vue was just published.

    Dependency rollup-plugin-vue
    Current Version 3.0.0
    Type devDependency

    The version 4.0.1 is not covered by your current version range.

    If you don’t accept this pull request, your project will work just like it did before. However, you might be missing out on a bunch of new features, fixes and/or performance improvements from the dependency update.

    It might be worth looking into these changes and trying to get this project onto the latest version of rollup-plugin-vue.

    If you have a solid test suite and good coverage, a passing build is a strong indicator that you can take advantage of these changes directly by merging the proposed change into your project. If the build fails or you don’t have such unconditional trust in your tests, this branch is a great starting point for you to work on the update.


    Commits

    The new version differs by 12 commits ahead by 12, behind by 6.

    • 3d1d210 chore: release version 4.0.1
    • 2fddee1 feat: Convert script & styles to import statements (#184)
    • 8409424 feat: Use @vue/component-compiler (#182)
    • 31a8c57 Upgrade PostCSS to 6.0.* (#176)
    • f918a7f fix: edit example conf.js (#161)
    • 9e1b315 chore: Use cross-env in npm scripts; closes vuejs/rollup-plugin-vue#167 (#168)
    • 0c207dc 3.0.0
    • 7c6c56a fix: move vue-template-compiler to peer dependencies
    • 684de42 fix: use prepare instead of prepublish
    • abd8b06 2.5.4
    • 41f823a 2.5.3
    • 302ad64 Revert "fix: move vue-template-compiler to dev & peer dependencies"

    See the full diff

    FAQ and help

    There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


    Your Greenkeeper bot :palm_tree:

    greenkeeper 
    Reply
  • Update rollup to the latest version ?
    Update rollup to the latest version ?

    Apr 16, 2018

    Version 0.58.0 of rollup was just published.

    Dependency rollup
    Current Version 0.57.1
    Type devDependency

    The version 0.58.0 is not covered by your current version range.

    If you don’t accept this pull request, your project will work just like it did before. However, you might be missing out on a bunch of new features, fixes and/or performance improvements from the dependency update.

    It might be worth looking into these changes and trying to get this project onto the latest version of rollup.

    If you have a solid test suite and good coverage, a passing build is a strong indicator that you can take advantage of these changes directly by merging the proposed change into your project. If the build fails or you don’t have such unconditional trust in your tests, this branch is a great starting point for you to work on the update.


    Commits

    The new version differs by 112 commits.

    • 5f0bed8 0.58.0
    • 06f2069 Fix lint error
    • bff9955 Merge branch 'preserve-hidden-classes'
    • f942d6e Revert most of the source-map update as there the new version contains
    • 30928f9 Update source-map dependency
    • abf8218 Add proxy layer to prevent direct module or graph access from the ast.
    • b75ac43 Use a "dirty" flag when including variables instead of handling return
    • 2f494c4 Make sure initialise is all that is necessary to reset a node so that in
    • 3e1c6fc Make sure Program nodes are really only included if they have an effect
    • 93f75b6 Streamline some remaining forEach and some loops
    • 67e4080 Only start another tree-shaking pass if a variable was included;
    • 52fb2d7 Make Program a fully functional ast node that will even receive an
    • a903b28 Take the module from the parent to avoid a constructor argument
    • 4978d7c Clean up variables
    • 339f5ab Initialise variables that are not initialised during construction

    There are 112 commits in total.

    See the full diff

    FAQ and help

    There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


    Your Greenkeeper bot :palm_tree:

    greenkeeper 
    Reply