@abcnews/fuzzy-dates
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -7,3 +7,4 @@ 'use strict'; | ||
var MONTHS = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'nov', 'dec']; | ||
var MONTHS = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec']; | ||
var FULL_MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; | ||
@@ -185,2 +186,26 @@ /** | ||
module.exports = { parse: parse, compare: compare }; | ||
/** | ||
* Output a date (optionally fuzzy) as something like February 10, 2017 or Mid February, 2017 | ||
* @param {Date} date | ||
* @return {string} | ||
*/ | ||
function formatDate(date) { | ||
var tokens = []; | ||
// Early, Mid, or Late | ||
if (typeof date.fuzzy === 'string') { | ||
tokens.push(date.fuzzy.charAt(0).toUpperCase() + date.fuzzy.slice(1)); | ||
} | ||
// Month | ||
tokens.push(FULL_MONTHS[date.getMonth()]); | ||
// Day number | ||
if (!date.fuzzy) { | ||
tokens.push(date.getDate()); | ||
} | ||
return tokens.join(' ') + ', ' + date.getFullYear(); | ||
} | ||
module.exports = { parse: parse, compare: compare, formatDate: formatDate }; |
{ | ||
"name": "@abcnews/fuzzy-dates", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "A fuzzy date parser/sorter", | ||
@@ -15,3 +15,6 @@ "main": "lib/index.js", | ||
}, | ||
"keywords": ["fuzzy", "dates"], | ||
"keywords": [ | ||
"fuzzy", | ||
"dates" | ||
], | ||
"author": "Nathan Hoad", | ||
@@ -18,0 +21,0 @@ "license": "ISC", |
@@ -65,4 +65,16 @@ # Fuzzy Dates | ||
You can also output a date in a nice and simple format | ||
```javascript | ||
const FuzzyDates = require('@abcnews/fuzzy-dates'); | ||
let date = FuzzyDates.parse('10 March 2015'); | ||
FuzzyDates.formatDate(date); // March 10, 2015 | ||
date = FuzzyDates.parse('2017, Late November'); | ||
FuzzyDates.formatDate(date); // Late November, 2017 | ||
``` | ||
## Authors | ||
- Nathan Hoad ([nathan@nathanhoad.net](mailto:nathan@nathanhoad.net)) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8650
175
79