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

fluentvalidation-ts

v3.2.0

Published

A TypeScript-first library for building strongly-typed validation rules

Downloads

16,862

Readme

fluentvalidation-ts

Strong, simple, extensible validation.

Visit https://fluentvalidation-ts.alexpotter.dev to get started.

Coverage NPM Version License Last Commit Open Issues

Dependencies GZIP Size

Overview

Front-end validation is a must-have for any project that involves forms, but the requirements vary hugely. You might have a simple sign-up form with a few text fields, or a complex configuration page with collections and deeply nested fields.

There are plenty of libraries out there which help you to solve the problem of front-end validation, but all the ones I've tried have felt lacking in one aspect or another - whether that's TypeScript support, their capacity to handle complex requirements, or the ability to define your own reusable validation logic.

So I wrote fluentvalidation-ts, a tiny library that is:

  • Designed for TypeScript
  • Simple yet powerful
  • Fully extensible

Whatever your validation needs, fluentvalidation-ts can handle them.

Docs

Full documentation, including a tutorial and a number of useful guides, is available at the official fluentvalidation-ts website.

Requirements

This library has been written in, and for, TypeScript. You can still use fluentvalidation-ts without TypeScript, but the primary benefit of having strongly-typed validation rules is lost.

If using TypeScript (strongly recommended), you must be on TypeScript version 2.9 or later.

Installation

Using Yarn:

yarn add fluentvalidation-ts

Using NPM:

npm i --save fluentvalidation-ts

Note: fluentvalidation-ts has been written with first-class support for TypeScript, so there's no need to install types!

Example Usage

import { Validator } from 'fluentvalidation-ts';

type Person = {
  name: string;
  age: number;
};

class PersonValidator extends Validator<Person> {
  constructor() {
    super();

    this.ruleFor('name') // This is type-safe! (Argument is of type 'name' | 'age')
      .notEmpty()
      .withMessage('Please enter your name');

    this.ruleFor('age')
      .greaterThanOrEqualTo(0)
      .withMessage('Age cannot be negative');
  }
}

const validator = new PersonValidator();

validator.validate({ name: '', age: 25 });
// { name: 'Please enter your name' }

validator.validate({ name: 'Alex', age: -1 });
// { age: 'Age cannot be negative' }

validator.validate({ name: '', age: -1 });
// { name: 'Please enter your name', age: 'Age cannot be negative' }

Test Coverage

fluentvalidation-ts has 100% test coverage via unit tests written with Jest.

Note: Some branches are incorrectly reported as uncovered due to the following issue: https://github.com/gotwarlost/istanbul/issues/690.

Issues

Please report issues via GitHub.

License

fluentvalidation-ts is provided under the terms of an Apache-2.0 license.

Development

To run the project locally simply clone the repo and run yarn install then yarn start in the root of the project. You can run the tests with yarn test.

About the Author

Alex Potter is a full-stack Software Developer who is currently part of the team at Ghyston, an award-winning software development company based in Bristol.

Check out his blog at alexpotter.dev, or get in touch @ajp_dev on Twitter.