1.0.8 • Published 4 years ago

class-validator-js-joda v1.0.8

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

class-validator-js-joda

This library provides some handy decorators that you can use if you are using class-validator and class-transformer together with the awesome js-joda datetime library.

Decorators

LocalDateProperty

import { LocalDate } from 'js-joda';
import { LocalDateProperty } from 'class-validator-js-joda';
import { plainToClass } from "class-transformer";
import { validateOrReject } from "class-validator";

class UserSignupRequest {
    @LocalDateProperty()
    readonly dateOfBirth: LocalDate;
}

const request = plainToClass(UserSignupRequest, {
    dateOfBirth: '1995-10-10'
});

try {
    await validateOrReject(input);

    //request is valid; lets process it.
} catch (errors) {
    console.log("Caught promise rejection (validation failed). Errors: ", errors)
}

LocalTimeProperty

import { LocalTime } from 'js-joda';
import { LocalTimeProperty } from 'class-validator-js-joda';

class Attendance {
    @LocalTimeProperty()
    readonly checkInTime: LocalTime;
}

LocalDateTimeProperty

import { LocalDateTime } from 'js-joda';
import { LocalDateTimeProperty } from 'class-validator-js-joda';

class PublishPostRequest {
    @LocalDateTimeProperty()
    readonly scheduledPublishTime: LocalDateTime;
}

MinLocalDate

  • Attaches decorator for validating whether the value is a local date that's after the specified local date.
import { LocalDate } from 'js-joda';
import { MinLocalDate } from 'class-validator-js-joda';

class SomeClass {
    @MinLocalDate(() => LocalDate.now())
    readonly dateField: LocalDate;
}

class SomeOtherClass {
    @MinLocalDate(LocalDate.now())
    readonly dateField: LocalDate;
}

TODO

  • Unit Tests
  • Better documentation
1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago