helper-year

0.1.0 • Public • Published

helper-year NPM version

Template helper for adding the current year. Good for adding dates for licenses, copyrights, last modified date, comment dates, etc. Works with handlebars, lo-dash or any template engine that has support for helper functions.

Install with npm

npm i helper-year --save

Examples

{%= year() %}
//=> 2014
{%= year("YYYY") %}
//=> 2014
{%= year("YY") %}
//=> 14

Run tests

npm test

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('year', require('helper-year'));

assemble

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

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

verb

Register the helper for use with verb:

var verb = require('verb');
verb.helper('year', require('helper-year'));
 
verb.task('default', function() {
  verb.src('.verb*.md')
    .pipe(verb.dest('./'));
});

handlebars

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

Lo-Dash or underscore

// as a mixin
_.mixin({year: require('helper-year')});
_.template('<%= _.year() %>', {});
//=> 2014
 
// passed on the context
_.template('<%= year() %>', {year: require('helper-year')});
//=> 2014
 
// as an import
var settings = {imports: {year: require('helper-year')}};
_.template('<%= year() %>', {}, settings);
//=> 2014

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 01, 2014.

Package Sidebar

Install

npm i helper-year

Weekly Downloads

4

Version

0.1.0

License

MIT

Last publish

Collaborators

  • jonschlinkert