valid-moment

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

Usage no npm install needed!

<script type="module">
  import validMoment from 'https://cdn.skypack.dev/valid-moment';
</script>

README

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.