From eff8bb5af69e637006df514ec2cd70871dad623e Mon Sep 17 00:00:00 2001 From: FSolM Date: Mon, 24 Feb 2020 17:19:23 -0600 Subject: [PATCH] cdate Updated to 0.5.5 --- lib/cdate.js | 14 +++------ lib/helpers/days.js | 48 ++++++++++++---------------- lib/helpers/formatter.js | 10 +++--- lib/helpers/months.js | 68 ++++++++++++++++++---------------------- package.json | 3 +- 5 files changed, 62 insertions(+), 81 deletions(-) diff --git a/lib/cdate.js b/lib/cdate.js index 2163ee1..e4266bd 100644 --- a/lib/cdate.js +++ b/lib/cdate.js @@ -10,14 +10,10 @@ export default (format = 'mm/dd/yy', options = { compact: true, fullDate: false } format.toLowerCase(); const d = new Date().toString().split(' '); - try { - let date = formatter(d, format, options.compact); - if (options.fullDate) { - return `${options.compact ? d[0] : getDays(d[0])}, ${date}`; - } else { - return date; - } - } catch { - return undefined; + let date = formatter(d, format, options); + if (options.fullDate) { + return `${options.compact ? d[0] : getDays(d[0], true)}, ${date}`; + } else { + return date; } } diff --git a/lib/helpers/days.js b/lib/helpers/days.js index 38c74d0..4ce7719 100644 --- a/lib/helpers/days.js +++ b/lib/helpers/days.js @@ -2,32 +2,24 @@ const longDays = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']; -export default (monthString, style = 'short') => { - style = style.toLowerCase(); - if (style === 'short') { - return monthString; - } else if (stryle === 'long') { - switch (monthString) { - case 'Mon': - return longDays[0]; - case 'Tue': - return longDays[1]; - case 'Wed': - return longDays[2]; - case 'Thu': - return longDays[3]; - case 'Fri': - return longDays[4]; - case 'Sat': - return longDays[5]; - case 'Sun': - return longDays[6]; - default: - console.error("Couldn't convert Days to string"); - return new Error(); - }; - } else { - console.error('The style you specified is unknown'); - return new Error() - } +export default (monthString) => { + switch (monthString) { + case 'Mon': + return longDays[0]; + case 'Tue': + return longDays[1]; + case 'Wed': + return longDays[2]; + case 'Thu': + return longDays[3]; + case 'Fri': + return longDays[4]; + case 'Sat': + return longDays[5]; + case 'Sun': + return longDays[6]; + default: + console.error("Couldn't convert Days to string"); + return undefined; + }; }; diff --git a/lib/helpers/formatter.js b/lib/helpers/formatter.js index 37f0103..155ecfe 100644 --- a/lib/helpers/formatter.js +++ b/lib/helpers/formatter.js @@ -5,15 +5,15 @@ import getMonths from './months'; export default (d, format, compact) => { switch (format) { case 'mm/dd/yy': - return `${compact ? d[1] : getMonths(d[1])} ${d[2]} ${compact ? d[3].substring(0, 2) : d[3]}`; + return `${compact ? d[1] : getMonths(d[1])} ${d[2]} ${d[3]}`; case 'dd/mm/yy': - return `${d[2]} ${compact ? d[1] : getMonths(d[1])} ${compact ? d[3].substring(0, 2) : d[3]}`; + return `${d[2]} ${compact ? d[1] : getMonths(d[1])} ${d[3]}`; case 'yy/mm/dd': - return `${compact ? d[3].substring(0, 2) : d[3]} ${d[2]} ${compact ? d[1] : getMonths(d[1])}`; + return `${d[3]} ${d[2]} ${compact ? d[1] : getMonths(d[1])}`; case 'yy/dd/mm': - return `${compact ? d[3].substring(0, 2) : d[3]} ${compact ? d[1] : getMonths(d[1])} ${d[2]}`; + return `${d[3]} ${compact ? d[1] : getMonths(d[1])} ${d[2]}`; default: console.error('Seems like the date format is wrong'); - return new Error(); + return undefined; } } diff --git a/lib/helpers/months.js b/lib/helpers/months.js index d166e78..406781b 100644 --- a/lib/helpers/months.js +++ b/lib/helpers/months.js @@ -2,42 +2,34 @@ const longMonths = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; -export default (monthString, style = 'short') => { - style = style.toLowerCase(); - if (style === 'short') { - return monthString; - } else if (style === 'long') { - switch (monthString) { - case 'Jan': - return longMonths[0]; - case 'Feb': - return longMonths[1]; - case 'Mar': - return longMonths[2]; - case 'Apr': - return longMonths[3]; - case 'May': - return longMonths[4]; - case 'Jun': - return longMonths[5]; - case 'Jul': - return longMonths[6]; - case 'Agu': - return longMonths[7]; - case 'Sep': - return longMonths[8]; - case 'Oct': - return longMonths[9]; - case 'Nov': - return longMonths[10]; - case 'Dic': - return longMonths[11]; - default: - console.error("Couldn't convert Months to string"); - return new Error(); - }; - } else { - console.error('The style you specified is unknown'); - return new Error() - } +export default (monthString) => { + switch (monthString) { + case 'Jan': + return longMonths[0]; + case 'Feb': + return longMonths[1]; + case 'Mar': + return longMonths[2]; + case 'Apr': + return longMonths[3]; + case 'May': + return longMonths[4]; + case 'Jun': + return longMonths[5]; + case 'Jul': + return longMonths[6]; + case 'Agu': + return longMonths[7]; + case 'Sep': + return longMonths[8]; + case 'Oct': + return longMonths[9]; + case 'Nov': + return longMonths[10]; + case 'Dic': + return longMonths[11]; + default: + console.error("Couldn't convert Months to string"); + return undefined; + }; }; diff --git a/package.json b/package.json index 7a49ed1..a310ad6 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,9 @@ { "name": "cdate-formatting", - "version": "0.5.0", + "version": "0.5.5", "description": "A simple Node package library for quick JS Date formatting", "main": "index.js", + "type": "module", "repository": { "type": "git", "url": "git+https://github.com/FSolM/cdate-formatting.git"