helper-date
Advanced tools
Comparing version 1.0.0 to 1.0.1
32
index.js
@@ -8,2 +8,13 @@ 'use strict'; | ||
module.exports = function dateHelper(str, pattern, options) { | ||
if (utils.isOptions(pattern)) { | ||
options = pattern; | ||
pattern = null; | ||
} | ||
if (utils.isOptions(str)) { | ||
options = str; | ||
pattern = null; | ||
str = null; | ||
} | ||
// if no args are passed, return a formatted date | ||
@@ -15,8 +26,7 @@ if (str == null && pattern == null) { | ||
options = options || {}; | ||
var defaults = {lang: 'en', date: new Date()}; | ||
var opts = Object.assign({}, this, defaults, options, options.hash); | ||
var defaults = {lang: 'en', date: new Date(str)}; | ||
var opts = utils.context(this, defaults, options); | ||
// set the language to use | ||
moment.locale(opts.lang); | ||
moment.locale(opts.lang || opts.language); | ||
@@ -35,13 +45,13 @@ if (opts.datejs === false) { | ||
// If handlebars, expose moment methods as hash properties | ||
if (opts.hash) { | ||
if (opts.context) { | ||
opts.hash = Object.assign({}, opts.hash, opts.context); | ||
if (options && options.hash) { | ||
if (options.context) { | ||
options.hash = Object.assign({}, options.hash, options.context); | ||
} | ||
var res = moment(str); | ||
for (var key in opts.hash) { | ||
if (res[key]) { | ||
return res[key](opts.hash[key]); | ||
for (var key in options.hash) { | ||
if (typeof res[key] === 'function') { | ||
return res[key](options.hash[key]); | ||
} else { | ||
console.log('moment.js does not support "' + key + '"'); | ||
console.error('moment.js does not support "' + key + '"'); | ||
} | ||
@@ -48,0 +58,0 @@ } |
{ | ||
"name": "helper-date", | ||
"description": "Format dates with date.js and moment.js. Uses date.js to parse human readable date phrases, and moment to format the rendered output. Should work with any Handlebars, Lo-Dash, underscore, or any template engine that allows helper functions to be registered. Also compatible with verb, assemble and Template.", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"homepage": "https://github.com/helpers/helper-date", | ||
"author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"contributors": [ | ||
"Brad Taylor (https://www.linkedin.com/in/bradtaylorsf)", | ||
"Jon Schlinkert (http://twitter.com/jonschlinkert)" | ||
], | ||
"repository": "helpers/helper-date", | ||
@@ -24,3 +28,3 @@ "bugs": { | ||
"date.js": "^0.3.1", | ||
"handlebars-utils": "^1.0.1", | ||
"handlebars-utils": "^1.0.4", | ||
"moment": "^2.18.1" | ||
@@ -30,5 +34,5 @@ }, | ||
"gulp-format-md": "^1.0.0", | ||
"mocha": "^3.4.2", | ||
"handlebars": "^4.0.10", | ||
"lodash": "^4.17.4" | ||
"lodash": "^4.17.4", | ||
"mocha": "^3.5.0" | ||
}, | ||
@@ -82,2 +86,5 @@ "keywords": [ | ||
}, | ||
"lint": { | ||
"reflinks": true | ||
}, | ||
"reflinks": [ | ||
@@ -89,8 +96,5 @@ "assemble", | ||
"underscore", | ||
"verb-generate-readme" | ||
], | ||
"lint": { | ||
"reflinks": true | ||
} | ||
"verb" | ||
] | ||
} | ||
} |
@@ -5,2 +5,4 @@ # helper-date [![NPM version](https://img.shields.io/npm/v/helper-date.svg?style=flat)](https://www.npmjs.com/package/helper-date) [![NPM monthly downloads](https://img.shields.io/npm/dm/helper-date.svg?style=flat)](https://npmjs.org/package/helper-date) [![NPM total downloads](https://img.shields.io/npm/dt/helper-date.svg?style=flat)](https://npmjs.org/package/helper-date) [![Linux Build Status](https://img.shields.io/travis/helpers/helper-date.svg?style=flat&label=Travis)](https://travis-ci.org/helpers/helper-date) | ||
Follow this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), for updates on this project and others. | ||
## Install | ||
@@ -101,2 +103,4 @@ | ||
You might also be interested in these projects: | ||
* [handlebars-helper-moment](https://www.npmjs.com/package/handlebars-helper-moment): A helper to master time! Combining the powers of Assemble, Handlebars.js and Moment.js. This helper… [more](https://github.com/assemble/handlebars-helper-moment) | [homepage](https://github.com/assemble/handlebars-helper-moment "A helper to master time! Combining the powers of Assemble, Handlebars.js and Moment.js. This helper leverages Moment.js to provide ultimate control over manipulating time and dates in your templates.") | ||
@@ -113,2 +117,9 @@ * [handlebars-helpers](https://www.npmjs.com/package/handlebars-helpers): More than 130 Handlebars helpers in ~20 categories. Helpers can be used with Assemble, Generate… [more](https://github.com/helpers/handlebars-helpers) | [homepage](https://github.com/helpers/handlebars-helpers "More than 130 Handlebars helpers in ~20 categories. Helpers can be used with Assemble, Generate, Verb, Ghost, gulp-handlebars, grunt-handlebars, consolidate, or any node.js/Handlebars project.") | ||
### Contributors | ||
| **Commits** | **Contributor** | | ||
| --- | --- | | ||
| 20 | [jonschlinkert](https://github.com/jonschlinkert) | | ||
| 1 | [bradtaylorsf](https://github.com/bradtaylorsf) | | ||
### Building docs | ||
@@ -146,2 +157,2 @@ | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on July 04, 2017._ | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on September 04, 2017._ |
11170
55
154
Updatedhandlebars-utils@^1.0.4