Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/hypersoftllc/qc-to_date

A simple JavaScript utility to convert various value to a Date.
https://github.com/hypersoftllc/qc-to_date

javascript-utility

Last synced: 28 days ago
JSON representation

A simple JavaScript utility to convert various value to a Date.

Awesome Lists containing this project

README

        

# qc-to_date

[![Build Status][travis-svg]][travis-url]
[![Coverage Status][coverage-image]][coverage-url]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]

[![npm badge][npm-badge-png]][package-url]

A simple JavaScript utility to convert various values to a Date.

## Installation

```sh
npm install --save qc-to_date
```

## Example Usage

```js
import { toDate, toDateOrNull } from 'qc-to_date';

toDate(946684800000); // Date on 2000-01-01T00:00:00.000 UTC
toDate(new Date()); // The Date input

// Returns the Date created from the number returned from `toDate`.
toDate({ toDate() { return 946684800000; } });

// Returns the Date returned from `toDate`.
toDate({ toDate() { return new Date(); } });

toDate(); // The not-date-like input
toDate(, undefined); // The not-date-like input
toDate(, null); // `null`
toDate(, 0); // `0`
toDate(, new Date()); // The new Date
toDate(, { def: {...} }); // The `{...}` object
toDateOrNull(); // `null`
toDateOrNull(); // The Date
```

[coverage-image]: https://coveralls.io/repos/github/hypersoftllc/qc-to_date/badge.svg?branch=master
[coverage-url]: https://coveralls.io/github/hypersoftllc/qc-to_date?branch=master
[downloads-image]: http://img.shields.io/npm/dm/qc-to_date.svg
[downloads-url]: http://npm-stat.com/charts.html?package=qc-to_date
[license-image]: http://img.shields.io/npm/l/qc-to_date.svg
[license-url]: LICENSE
[package-url]: https://npmjs.org/package/qc-to_date
[npm-badge-png]: https://nodei.co/npm/qc-to_date.png?downloads=true&stars=true
[travis-svg]: https://travis-ci.org/hypersoftllc/qc-to_date.svg?branch=master
[travis-url]: https://travis-ci.org/hypersoftllc/qc-to_date