npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

es-validation

v0.1.0

Published

ECMAScript decorators for validation, inspired by JSR-303, JSR-349 and JSR-380.

Downloads

1

Readme

es-validation

AppVeyor CircleCI Travis CI AppVeyor tests Codecov Code Climate Code Climate

Dependencies Development dependencies Known Vulnerabilities Greenkeeper

A set of constraint validation decorators inspired by JSR-303, JSR-349 and JSR-380.

The library makes it possible to:

  • define constraints on properties
  • define constraints on parameters
  • define constraints on returned values

Getting Started

The library can be installed using npm:

npm install es-validation --save

Or using yarn:

yarn add es-validation

Decorators

A number of decorators are available, and can be used on properties, parameters or functions. In the later case, the constraint is placed on the method's returned values.

String elements are converted to Boolean, Number or Date, depending on what type the constraint normally applies to. When relevant, Object elements are converted as well through toString().

| Name | Boolean | Number | String | Date | Map/Array | Description | |:-------------------|:-------------------|:-------------------|:-------------------|:-------------------|:-------------------|:-----------------------------------------------------------------------| | @AssertFalse | :heavy_check_mark: | - | :heavy_check_mark: | - | - | Must be false. | | @AssertTrue | :heavy_check_mark: | - | :heavy_check_mark: | - | - | Must be true. | | @NotNull | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | Must not be null. | | @Null | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | Must be null. | | @NotBlank | - | - | :heavy_check_mark: | - | - | Must not be null and contain at least one non-space character. | | @NotEmpty | - | - | :heavy_check_mark: | - | :heavy_check_mark: | Must not be empty (string length, array/map size). | | @Size() | - | - | :heavy_check_mark: | - | :heavy_check_mark: | Must be within a size range (string length, array/map size). | | @Pattern() | - | - | :heavy_check_mark: | - | - | Must match a regular expression. | | @Max() | - | :heavy_check_mark: | :heavy_check_mark: | - | - | Must be a number that is lower than or equal to a maximum. | | @Min() | - | :heavy_check_mark: | :heavy_check_mark: | - | - | Must be a number that is higher than or equal to a minimum. | | @PositiveOrZero | - | :heavy_check_mark: | :heavy_check_mark: | - | - | Must be a number that is higher than or equal to 0. | | @Positive | - | :heavy_check_mark: | :heavy_check_mark: | - | - | Must be a number that is higher than 0. | | @NegativeOrZero | - | :heavy_check_mark: | :heavy_check_mark: | - | - | Must be a number that is lower than or equal to 0. | | @Negative | - | :heavy_check_mark: | :heavy_check_mark: | - | - | Must be a number that is lower than 0. | | @Digits() | - | :heavy_check_mark: | :heavy_check_mark: | - | - | Must be a number with a set maximum of integral and fractional digits. | | @FutureOrPresent | - | - | :heavy_check_mark: | :heavy_check_mark: | - | Must be a date set in the future or now. | | @Future | - | - | :heavy_check_mark: | :heavy_check_mark: | - | Must be a date set in the future. | | @PastOrPresent | - | - | :heavy_check_mark: | :heavy_check_mark: | - | Must be a date set in the past or now. | | @Past | - | - | :heavy_check_mark: | :heavy_check_mark: | - | Must be a date set in the past. | | @Email | - | - | :heavy_check_mark: | - | - | Must be a valid email address. | | @Valid | - | - | - | - | :heavy_check_mark: | Properties must be validated (also applies to Object). |

Validation

The module only provides an interface for validation, but no actual implementation. The implementation must be defined within a separate module.

The following known implementations are available:

Validator Factory

The ValidatorFactory interface is the entry-point for user code to obtain validator instances, mainly through the getValidator() method.

Validator

The Validator interface is used to perform constraint validation. The following methods are available:

| Method | Description | |:------------------------|:-----------------------------------------| | validate() | Validate an object's properties. | | validateProperty() | Validate a specific object property. | | validateValue() | Validate a value. | | validateParameters() | Validate a function call's parameters. | | validateReturnValue() | Validate a function call's return value. |

A Validator instance is obtained through a ValidatorFactory.

Date Provider

The DateProvider interface is used to retrieve the current time, which is necessary for various decorators (@Past, @Future, etc.). It contains a single method:

| Method | Description | |:------------|:----------------------| | getDate() | Get the current time. |

There is generally no interaction with this interface from user code, unless new custom decorators dealing with time are defined. In this scenario, the DateProvider instance can be obtained through ConstraintValidationContext's getDateProvider() method.

Development

The module can be built using the following command:

npm run build

It is also possible to keep unit tests executing as a background task:

npm run test