npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pretty-easy-date-check

v1.2.4

Published

Check if a supplied value is a valid Date (instanceof Date or a valid string representation of a date that can be turned into one by instantiating Date class).

Downloads

86

Readme

pretty-easy-date-check

 

NPM Version Build Status - Travis CI Build Status - Appveyor Tests Dependancies

What is pretty-easy-date-check?

pretty-easy-date-check is a simple NodeJS module for performing check against a supplied value to determine if it is a valid date (instance of Date class or a valid string representation of a date that can be used as a valid argument to instantiate the Date class!).

If you just want to check if the value is an instance of a Date class, consider using a utility library such as pretty-easy-data-types.

 

Install

This is a NodeJS module available through the npm registry. Installation is done using the npm install command:

$ npm install pretty-easy-date-check --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 isValidDate = require('pretty-easy-date-check');

 

or if you use TypeScript

import { default as isValidDate } from 'pretty-easy-date-check';

 

The module returns a function for you to call and supply it with parameter that you'd like to check if it is a valid Date or a string representation of a valid date (see the examples of valid dates, down below). The function returns a Boolean.

 

Examples

Valid dates

isValidDate(new Date());               //  true
isValidDate('3.10.17');                //  true
isValidDate('03.10.2017.');            //  true
isValidDate('3,10,17');                //  true
isValidDate('03,10,2017');             //  true
isValidDate('3/10/17');                //  true
isValidDate('03/10/2017');             //  true
isValidDate('3-10-17');                //  true
isValidDate('03-10-2017');             //  true
isValidDate('Fri Mar 10 17');          //  true
isValidDate('Fri Mar 10 2017');        //  true
isValidDate(new Date().toString());    //  true

//  Pretty much, everything else should result in a false value

 

Important :

The module will return a boolean true if the value passed is :

  • an instance of Date constructor class or
  • valid string representation of date

For more flexible Date data type checks, such as the ones for checking if the value is only an instance of a Date class and not a valid date string, consider including a utility library such as pretty-easy-data-types.

/*
*   Only import the checks you will be using,
*   instead of including the whole library
*/
const { 
    isDate,         //  check for instances of Date class
    isError         //  check for instances of Error class
} = require('pretty-easy-data-types');
const canBeDate  = require('pretty-easy-date-check');

/*
*   Check if the value is the instance of a Date class (and not a string representing a date)
*   and if so, in this example we're just going to use that instance of Date object
*   else we're checking if the value is a valid string representation of a date
*   and if so, we're going to instantiate a Date class with it 
*   else we're just going to construct a new instance of Error class
*/
const sampleDate = 'not date';
const date = isDate(sampleDate) ? 
    sampleDate : 
    (canBeDate(sampleDate) ? new Date(sampleDate) : new Error('Invalid date!'));

//  It is not an instance of Date; it's an Error
if(isError(date)) console.log(date.message);

//  It is a valid instance of Date class
else console.log(`Valid date supplied`);

 

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.2.3

  • Tiny improvement, for module consistancy

03/30 - v1.2.3

  • TypeScript intelisense and declaration improvements
  • Documentation updates

03/29 - v1.2.2

  • Documentation updates

03/29 - v1.2.1

  • Bugfix
  • Documentation updates

03/28 - v1.2.0

  • Various improvements
  • New test cases
  • TypeScript API changes (due to definition updates)
  • Documentation updates to reflect the changes

03/20 - v1.1.3

  • Support for Node < 1.8 abbandoned
  • Modular approach to unit tests
  • New test cases
  • Documentation updates to reflect the changes

03/16 - v1.1.2

  • Documenation updates

03/15 - v1.1.1

  • Documentation updates

03/15 - v1.1.0

  • Dependancy updates

03/14 - v1.0.5

  • Minor improvement

03/13 - v1.0.4

  • Typescript declaration conflicts

03/13 - v1.0.3

  • Additional test cases provided

03/13 - v1.0.2

  • Minor improvement

03/12 - v1.0.1

  • Bugfix (falsy values related)

03/10 - 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.