is-date-str
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

is-date-str

Check if a string is date value

Install

$ npm install is-date-str

Usage

import isDateStr from 'is-date-str';

isDateStr('2023-07-19 12:34:56');
//=> true

isDateStr('unicorn');
//=> false

API

isDateStr(str, options?)

options

Type: object

regexArr

Type: Array<RegExp>
Default: []

Time regex in array list.

import isDateStr from 'is-date-str';

isDateStr('July 19, 2023');
//=> false

const regexArr = [
	/^(\d{4})-(\d{2})-(\d{2})[T ](\d{2}):(\d{2})(?::(\d{2}))?(\.\d+)?(Z|[+-]\d{2}:\d{2})?$/,
	/^(\d{4})-(\d{2})-(\d{2})$/,
	/^(\d{4})\/(\d{2})\/(\d{2})$/,
	/^(\d{2}):(\d{2})(?::(\d{2}))?$/,
	/^(\d{4})(\d{2})(\d{2})$/
]
isDateStr('20221201', {regexArr});
//=> true

Package Sidebar

Install

npm i is-date-str

Weekly Downloads

0

Version

1.0.0

License

ISC

Unpacked Size

2.29 kB

Total Files

4

Last publish

Collaborators

  • qiutian00