moment-transform
A plugin for Moment.js that allows date transformation from a pattern.
Usage
First, download the plugin by:
- cloning this repository,
- use
npm
orbower
, - checking the
dist/
folder.
Include it in your website/app (after moment if you don't use require
).
Then:
var tomorrow = ;var midnightTonight = ;var breakfirstTimeToday = ; // Optional pattern argumenttomorrow = ;// Multiple patterns, take the first that fitsmidnightTonight = ; // Optional strict argumenttomorrow = ; // this worksvar invalid = ; // this will return an invalid date.invalid; // falsebreakfirstTimeToday = ; // with default patterns
Options
transform()
takes up to three arguments:
value
: value to be checked against the pattern,patterns
(optional): a string or an array of strings. Checkformat()
documentation for syntax. Default value is['YYYY-MM-DD HH:mm:ss.SSS', 'YYYY-MM-DD HH:mm:ss', 'YYYY-MM-DD', 'HH:mm:ss.SSS', 'HH:mm:ss']
.strict
(optional): non-alphabetic characters in patterns are not mandatory when not strict. Default isfalse
.
Contributing
Fork the repository and do a npm install
.
You can check your code is correct by doing a grunt test
.
When you're done, do a grunt build
.