valid-moment
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

valid-moment

Convert standard date string to Date, based on moment.js; and invalidate bad formatting.

https://stackoverflow.com/questions/7445328/check-if-a-string-is-a-date-value

Examples

Valid date strings include,

  • ISO 8601 date strings (from JavaScript, Python or Java)
  • RFC 2822 date strings
  • Locale string

Invalid date string include,

  • Numbers and number strings

Plans

  • Be non-library specific, so that can use no library (Date object only), or with inmoment or luxon.

Usage

import { toDate, toMoment } from "valid-moment";
console.log(toDate(DATE_STRING))  // Returns 'null' if invalid
console.log(toMoment(DATE_STRING))  // Returns 'null' if invalid

Installation

npm i valid-moment

Tests

For current testing results, see /tests/tests.json. The tests are done at GMT+0700.

Package Sidebar

Install

npm i valid-moment

Weekly Downloads

2

Version

1.0.0

License

MIT

Unpacked Size

16.7 kB

Total Files

15

Last publish

Collaborators

  • patarapolw