@zerodep/to-date
TypeScript icon, indicating that this package has built-in type declarations

2.0.7 • Public • Published

@zerodep/to-date

version language types license

CodeFactor Known Vulnerabilities

A utility to convert a string, number, BigInt or Date to a Date. Invalid values will cause a ZeroDepError to be thrown.

Full documentation is available at the zerodep.app page.

Examples

All @zerodep packages support both ESM and CJS.

import { toDate } from '@zerodep/to-date';
// or
const { toDate } = require('@zerodep/to-date');

Use Cases

// with a string
toDate('2022-02-24'); // Date() object equivalent to 2022-04-22T17:00:00.000Z
toDate('12/25/2021'); // Date() object equivalent to 2023-12-25T17:00:00.000Z
toDate('09-Aug-2016'); // Date() object equivalent to 2019-08-09T17:00:00.000Z
toDate('11/12/13'); // Date() object equivalent to 2013-11-12T17:00:00.000Z

// with a number or big int
toDate(1645722000); // Date() object equivalent to 2022-04-22T17:00:00.000Z
toDate(1640451600000); // Date() object equivalent to 2023-12-25T17:00:00.000Z
toDate(1384275600n); // Date() object equivalent to 2013-11-12T17:00:00.000Z

// invalid values
toDate({ not: 'a string' }); // throws ZeroDepError: Value is not a string

Readme

Keywords

Package Sidebar

Install

npm i @zerodep/to-date

Homepage

zerodep.app

Weekly Downloads

0

Version

2.0.7

License

MIT

Unpacked Size

17 kB

Total Files

7

Last publish

Collaborators

  • cdepage