New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

validator-fluent

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

validator-fluent

Validates and sanitizes user input using a strongly typed fluent API (TypeScript).

latest
Source
npmnpm
Version
0.4.2
Version published
Weekly downloads
248
-3.5%
Maintainers
1
Weekly downloads
 
Created
Source

validator.js — fluent edition 🎉

NPM Version NPM Downloads TypeScript Donate Discord

Validation library based on validator.js (✭17k) that provides a strongly typed (TypeScript) fluent API for user input validation and sanitization.

Getting Started

$ npm install validator validator-fluent
import { validate, ValidationError } from "validator-fluent";
const input = {
  givenName: "John",
  familyName: "Doe",
  email: "john@example.com",
  phone: "(555) 555-55-55",
  age: "18",
};

// Do not validate empty fields (validation only)
const dryRun = true;

const [data, errors] = validate(input, (value) => ({
  given_name: value("givenName")
    .notEmpty({ if: !dryRun })
    .isLength({ min: 3, max: 25 }),

  family_name: value("familyName")
    .notEmpty({ if: !dryRun })
    .isLength({ min: 1, max: 25 }),

  email: value("email").notEmpty().isEmail(),

  phone: value("phone").isMobilePhone({ locale: "en-US" }),

  age: value("age").toNumber(),
}));

if (Object.keys(errors).length > 0)) {
  throw new ValidationError(errors);
}

if (!dryRun) {
  await db.table("customer").insert(data);
}

For the full list of available validation rules please refer to:

https://github.com/validatorjs/validator.js#validators

  • GraphQL API Starter Kit — project template, pre-configured with TypeScript, GraphQL.js, React, and Relay.

How to Contribute

Please create a PR or send me a message on Discord.

License

Copyright © 2021-present Kriasoft. This source code is licensed under the MIT license found in the LICENSE file.

Made with ♥ by Konstantin Tarkus (@koistya, blog) and contributors.

Keywords

validator

FAQs

Package last updated on 24 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts