JSPM

helper-timeago

0.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 5
  • Score
    100M100P100Q37094F
  • License

Date helper for displaying elapsed time in a human-readable format. Can be used as a JavaScript utility or template helper with handlebars, lo-dash or any template engine that supports helper functions.

Package Exports

  • helper-timeago

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (helper-timeago) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

helper-timeago NPM version

Date helper for displaying elapsed time in a human-readable format. Can be used as a JavaScript utility or template helper with handlebars, lo-dash or any template engine that supports helper functions.

Install with npm

npm i helper-timeago --save

Usage

var timeago = require('helper-timeago');
timeago(new Date('2/10/1994'))
//=> '20 years ago'

With Lo-Dash or Underscore:

<%= timeago("index.js") %>

With Handlebars:

{{timeago "index.js"}}

With Verb (lo-dash, with special delimiters to avoid delimiter collision in markdown docs):

{%= timeago('index.js') %}

Run tests

npm test

See the tests for actual usage examples.

Register the helper

This should work with any engine, here are a few examples

template

Register the helper for use with any template engine

template.helper('timeago', require('helper-timeago'));

assemble

To register the helper for use with assemble v0.6.x:

assemble.helper('timeago', require('helper-timeago'));

verb

Register the helper for use with verb:

var verb = require('verb');
verb.helper('timeago', require('helper-timeago'));

verb.task('default', function() {
  verb.src('.verb*.md')
    .pipe(verb.dest('./'));
});

handlebars

var handlebars = require('handlebars');
handlebars.registerHelper('timeago', require('helper-timeago'));

Lo-Dash or underscore

// as a mixin
_.mixin({timeago: timeagoHelper});
_.template('<%= _.timeago("fixtures/*.js") %>', {});

// passed on the context
_.template('<%= timeago("fixtures/*.js") %>', {timeago: timeagoHelper});

// as an import
var settings = {imports: {timeago: timeagoHelper}};
_.template('<%= timeago("fixtures/*.js") %>', {}, settings);

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue. To request or contribute a helper to the github.com/helpers org, please read this contributing guide to get started.

Author

Jon Schlinkert

License

Copyright (c) 2014 Jon Schlinkert
Released under the MIT license


This file was generated by verb on December 07, 2014. To update, run npm i -g verb && verb.