Date Prettify
A silly small date formatter with recursive abilities to format deep objects without mutating them
Changelog
You can check out the changelog here: https://github.com/dhershman1/dateprettify/blob/master/changelog.md
How To
npm i -S dateprettify
Using Standard Module System
; const clean cleanArray deepClean = ;
Using Common JS
var prettyDate = ;prettyDatemethod;
Using in the browser
<script src="path/to/dateprettify/dist/dateprettify.umd.js"></scipts>
dateprettify.method();
Usage
Important Formats now Follow date-fns formatting which can be seen here https://date-fns.org/v1.29.0/docs/format
Importing dateprettify brings in an object which is then used either as a chain, or can be destructured
The main function now accepts a param that can be your desired format
; const clean cleanArray deepClean = ;// The default format if one is not passed in is MM-DD-YYYY date = ;// date output: Dec 11th, 2009date = ;// date output: ['Dec 11th, 2009']date = ;// date output: {item: {date: 'Dec 11th, 2009'}} // An override format is also passible to each methoddate = ;// output: 12 11, 09
Methods
clean(date, oFormat)
Clean single date
Argumments
date
-String|Date Object
: the date you want cleanedoFormat
-String
: This will override the format set by the factory functionOptional
Usage
; const clean = ; ;// Output: 07-24-2010
cleanArray(dateArr, oFormat)
Clean an array of dates
Argumments
dateArr
-Array
: An array of date strings or objectsoFormat
-String
: This will override the format set by the factory functionOptional
Usage
; const cleanArray = ;const cleanDate = ;// Output: ['12.31.16', '1.30.17']
deepClean(obj, keys, oFormat)
Recursively clean an object handles single dates, arrays of dates, and more date objects inside your main object
Argumments
obj
-Object
: Your object to search throughkeys
-Array
: Array of strings with key names you wantdeepClean
to look foroFormat
-String
: This will override the format set by the factory functionOptional
Usage
; const deepClean = ;dateObj = date1: '12/11/09' dateArrOfObjs: date2: '2010/7/24' dateArr: '01/15/16' '12/25/14' dateObj: dateObj2: testerDate: '10/05/2016' ;cleanObj = ;// Output:/*{ date1: '12-11-2009', dateArrOfObjs: [{ date2: '07-24-2010' }], dateArr: [01-15-2016, 12-25-2014], dateObj: { dateObj2: { testerDate: '10-05-2016' } }} */