It’s simple: Targeted Module Imports
Link up:
Modern JavaScript Date Utility Library_date-fns provides the most comprehensive yet simple and consistent toolset for manipulating JavaScript dates in a…_date-fns.org
Moment.js | Docs_define(['moment'], console.log(moment().format('LLLL')); }); define(['moment', 'moment/locale/de']…_momentjs.com
The Javascript Date object has problems, here is some reading on the subject:
Emphasizing the problems is the growing number of JS Date wrapper libraries aimed at solving problems and simplifying manipulation of dates in your code. The clear winner up to this point(and my personal go-to) has been Moment.js. Moment is great and offers almost all of the features that I am looking for.
Recently, I began work on a new NodeJs project at work, and webpack bundle size is of high importance to us at the moment. The micro-service that I have been working on in-particular requires some specific Date validation and manipulation that I have previously gone to Moment.js for. But then, I discovered that Moment.js does not have the ability to import specific modules, it’s all or nothing. So, I googled for alternatives and found this:
So I checked it out, I decided to import and let it have a chance. I imported what ended up being 4 specific functions to get the job done. Those 4 functions cost me almost nothing.
I am a week in and still using it. Curious to know if anybody else out there is using date-fns. As I am writing this I decided to go find out and yeah, peeps are using it. To the tune on 2MIL+ npm downloads in the last month at the time of this writing:
date-fns_Modern JavaScript date utility library_www.npmjs.com
What are your thoughts on date-fns in NodeJs projects? Is there something better? Let me know your thoughts and questions and give me a follow on twitter. Keep after it.