@page CanStacheMoment can-stache-moment
can-stache-moment
Moment.js helpers for CanJS Stache templates.
Installation
npm install can-stache-moment --save
(Recommended) Using CanJS's support for StealJS, you can import the helpers directly inside your templates:
Date Customer Invoice {{#items}} <!-- FORMATTING A DATE --> {{mFormatDate delivery_date 'MMM D, h:mm a'}} {{customer.company}} {{invoice_number}} {{/items}}
Usage
To help avoid collisions with other helpers, these helpers are all prefixed with 'm'.
There are two ways to use the included helpers.
Register all Helpers Globally
Register all helpers by simply importing the library with can-import.
import 'can-stache-moment';
Use individually in can-component
The other way is to import the module's function and use it in an individual module in your app:
// First, import the helper.;;;;; var MCViewModel = canMap; Component;
API
Formatting Dates with mFormatDate
\{{mFormatDate key 'String'}}
// Example
\{{mFormatDate delivery_date 'MMM D, h:mm a'}}
See the Format MomentJS docs.
Time From Now
\{{mTimeFromNow [boolean]}}
// Examples:
\{{mTimeFromNow}} --> a minute ago
// boolean is to remove the suffix.
\{{mTimeFromNow true}} --> a minute
See the Time from Now MomentJS docs.
Calendar Time
\{{mCalendar}} -->
See the Calendar Time docs for example output.
Changelog
3.0.0
Added compatibility with CanJS 3.01.0.0
importing the main file now registers all of the helpers globally.
Contributing
Pull requests are welcome. I will add more helpers as I need them.