UNPKG

pluggy-js

Version:

Client-side JavaScript toolkit for Pluggy's API.

20 lines (19 loc) 799 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseIsoDate = exports.isIsoDateString = void 0; /** * RegExp to check if a string is an ISO 8601 string date. * source: https://stackoverflow.com/questions/14488745/javascript-json-date-deserialization#comment69468928_23691273 */ const DATE_ISO_8601_REGEX = /^\d{4}-(0[1-9]|1[0-2])-([12]\d|0[1-9]|3[01])([T\s](([01]\d|2[0-3]):[0-5]\d|24:00)(:[0-5]\d([.,]\d+)?)?([zZ]|([+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?$/; function isIsoDateString(value) { if (typeof value !== 'string') { return false; } return DATE_ISO_8601_REGEX.test(value); } exports.isIsoDateString = isIsoDateString; function parseIsoDate(isoDateString) { return new Date(isoDateString); } exports.parseIsoDate = parseIsoDate;