calendar-date-regex

1.0.2 • Public • Published

calendar-date-regex

NPM version Bower version Build Status Coverage Status devDependency Status

Regular expression for matching ISO 8601 calendar dates

'2015-01-25 0101 20150126 11112233 2015-13-13'.match(calendarDateRegex());
//=> ['2015-01-25' '20150126']

Installation

Package managers

npm

npm install calendar-date-regex

bower

bower install calendar-date-regex

Duo

const calendarDateRegex = require('shinnn/calendar-date-regex');

Standalone

Download the script file directly.

API

calendarDateRegex(options)

options: Object
Return: RegExp

It returns a regular expression object that matches calendar dates (YYYY-MM-DD and YYYYMMDD).

calendarDateRegex().exec('  16140526  ').slice();
//=> ['16140526', '1614', '05', '26', undefined, undefined, undefined]
 
calendarDateRegex().exec('  1614-05-26  ').slice();
//=> ['1614-05-26', undefined, undefined, undefined, '1614', '05', '26']

options.basic

Type: Boolean
Default: true

false prevents the regex from matching the basic format (YYYYMMDD).

calendarDateRegex({basic: false}).test('20130413'); //=> false

options.extended

Type: Boolean
Default: true

false prevents the regex from matching the extended format (YYYY-MM-DD).

calendarDateRegex({extended: false}).test('2013-04-13'); //=> false

options.exact

Type: Boolean
Default: false

true makes the regex matches only an exact calendar date string.

calendarDateRegex().test('foo 11900331'); //=> true
calendarDateRegex({exact: true}).test('foo 11900331'); //=> false
calendarDateRegex({basic: false, exact: true}).test('11900331'); //=> false

calendarDateRegex.noDay(options)

options: Object (only supports exact option)
Return: RegExp

It returns a regular expression object that matches calendar dates with reduced precision (YYYY-MM).

calendarDateRegex.noDay().test('2015-01'); //=> true
calendarDateRegex.noDay().test('201501'); //=> false

License

Copyright (c) 2015 Shinnosuke Watanabe

Licensed under the MIT License.

Package Sidebar

Install

npm i calendar-date-regex

Weekly Downloads

1

Version

1.0.2

License

MIT

Last publish

Collaborators

  • shinnn