pretty-easy-dates
What is pretty-easy-dates?
pretty-easy-dates is a simple NodeJS module for getting the desired date and time/timestamp values in a hash (JavaScript object notation like format).
Install
This is a NodeJS module available through the npm registry. Installation is done using the npm install command:
$ npm install pretty-easy-dates --save
--save flag is used to save the module as a project dependancy in your package.json file.
Usage
After installing the module (localy in your project directory), in order to use it in your file you first need to require it.
let prettyDate = ;
or if you use TypeScript
;
The module returns a function for you to call and supply it with a parameter that represents the desired date (as a String or instance of Date class data type) you'd like to be transformed in a JavaScript hash (or an instance of Error class if the invalid Date value was passed).
Important :
- if a parameter passed is a string, it needs to be a valid representantion of a date; something in the line of :
- '3.29.17',
- '03.29.2017',
- 'Mar 29 2017',
- 'March 29 2017',
- 'Wed Mar 29 2017',
- 'Wed Mar 29 2017 15:33:51 GMT+0200 (CEST)'
- you can use one of the following symbols, as a MM DD YYYY separator:
- . (dot),
- , (comma),
- (blank space),
- / (slash),
- - (dash),
- _ (underscore)
- month and date values can be passed as either one or two digit notation, whereas year value must be a four digit notation.
Examples
Convert Date to JavaScript hash
; // from instance of Date class; // from String representation of date
The module returns the hash with the following properties
Consider the following
The module will return an instance of an Error class, if argument passed is not a valid date value, instead of throwing an error and terminating the Node process thus making it more dynamic and usable in production.
Having this in mind, I advise you to consider including a utility library to check the output data type, such as pretty-easy-data-types.
/** Only import the checks you will be using,* instead of including the whole library*/const isError // check for instance of Error class} = ;const prettyDate = ; // You can pass any value/data type to a function// without causing your process to breakconst isThisValidDate = ; /** After converting the date to its' corresponding hash* you should perform the check on the value returned to see* if the conversion was successful.** If the value returned is of type Object the conversion was successful* and in this example we're going to extract the date and time from it* else it is an instance of an Error class and we're just going to get it's message*/const dateAndTime = ! ? isThisValidDatenow : isThisValidDatemessage;
Releases
The module follows the Semantic Versioning standard to communicate what kinds of changes are introduced in the new releases.
Versioning
Patch releases : n.n.X -> Bug fixes, documentation updates, code cleanups, new test cases, optimization stuff and other minor changes that you should probably not be aware of;
Minor releases : n.X.n -> New feature(s) which don't break the existing ones. These ofter refer to minor TypeScript API changes (mainly due to declarations; JavaScript code will not be affected by these changes), code refactoring, some under the sheet changes that you should not worry about too much;
Major releases : X.n.n -> Changes that could possibly introduce the backwards compatibility issues. These are however very rare and could be relevant to you only in the case of an endpoint API change and the way you communicate with the module.
Changelogs
03/30 - v1.0.1
- Documentation updates
03/30 - v1.0.0
- Initial release
Want to contribute?
Great! Anyone can help make this project better - check out the github repository!
Found a bug?
Please open a an issue.
License
Copyright (c) 2017 Ognjen Jevremović
Licensed under the MIT License.