@elunic/is-iso-date
TypeScript icon, indicating that this package has built-in type declarations

2.0.2 • Public • Published

@elunic/is-iso-date

Build Status

Written in TypeScript!

Table of Contents

Installation

$ npm install @elunic/is-iso-date

Functionality

import { isoDateRegExp, isISODate, InvalidISODateError, assertISODate } from '@elunic/is-iso-date';

'2020-02-20T10:00:00Z'.match(isoDateRegExp); // OK
isISODate('2020-02-20T10:00:00Z'); // true

try {
  assertISODate('2020');
} catch (err) {
  err instanceof InvalidISODateError; // true
}

// With Joi:
Joi.string().custom(assertISODate);

// NOTE: Do not use together with Joi's .isoDate(). That will always
// produce an ISO string, but one where the timezone has been transformed.

class-validator decorator

This module provides the @IsStrictISO8601() decorator for use with the class-validator module.

Note that you will have to provide the class-validator in peerDependencies.

import { IsStrictISO8601 } from '@elunic/is-iso-date/class-validator';

export class TodoEntity {
  @IsStrictISO8601()
  dueDate: string;
}

License

MIT License

Copyright (c) 2020 elunic AG/William Hefter wh@elunic.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Package Sidebar

Install

npm i @elunic/is-iso-date

Weekly Downloads

1,104

Version

2.0.2

License

MIT

Unpacked Size

9.47 kB

Total Files

13

Last publish

Collaborators

  • elunic