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

2.0.7 • Public • Published

@zerodep/guard-date

version language types license

CodeFactor Known Vulnerabilities

A run-time guard to require a value to be a Date; it will throw a ZeroDepError if the guard fails.

Full documentation is available at the zerodep.app page.

Examples

All @zerodep packages support both ESM and CJS.

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

Successful Cases

guardDate(new Date()); // void

Unsuccessful Cases

guardDate([]); // throws ZeroDepError: Value is not a date
guardDate(['a', 'b', 'c']); // throws ZeroDepError: Value is not a date
guardDate(1000n); // throws ZeroDepError: Value is not a date
guardDate(true); // throws ZeroDepError: Value is not a date
guardDate(''); // throws ZeroDepError: Value is not a date
guardDate(new Error('message')); // throws ZeroDepError: Value is not a date
guardDate(3.14); // throws ZeroDepError: Value is not a date
guardDate(() => 'function'); // throws ZeroDepError: Value is not a date
guardDate(42); // throws ZeroDepError: Value is not a date
guardDate(
  new Map([
    ['a', 1],
    ['b', 2],
  ])
); // throws ZeroDepError: Value is not a date
guardDate(null); // throws ZeroDepError: Value is not a date
guardDate({ an: 'object' }); // throws ZeroDepError: Value is not a date
guardDate(new Promise(() => {})); // throws ZeroDepError: Value is not a date
guardDate(/[regex]+/gi); // throws ZeroDepError: Value is not a date
guardDate(new Set([1, 2, 3])); // throws ZeroDepError: Value is not a date
guardDate('a string'); // throws ZeroDepError: Value is not a date
guardDate(Symbol()); // throws ZeroDepError: Value is not a date
guardDate(new Int32Array(2)); // throws ZeroDepError: Value is not a date
guardDate(undefined); // throws ZeroDepError: Value is not a date

Readme

Keywords

Package Sidebar

Install

npm i @zerodep/guard-date

Homepage

zerodep.app

Weekly Downloads

1

Version

2.0.7

License

MIT

Unpacked Size

7.55 kB

Total Files

7

Last publish

Collaborators

  • cdepage