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

flood-gate

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flood-gate

A typescript object validation library using decorators

latest
Source
npmnpm
Version
2.1.0
Version published
Weekly downloads
4
Maintainers
1
Weekly downloads
 
Created
Source

Floodgate validator

Floodgate validator is a Typescript validaton library based on decorators.

Features

  • Does not change class/object behaviour
  • Extensible (docs on how to add validators coming soon)
  • Plays nice with Typescript

Installations

    npm install floodgate --save

Run tests

  • Clone this repo
  • Go to root of project
  • run
        npm install -g mocha && mocha
    

Usage

    
    import { Schema, Str, Nr, SchemaStore, Arr, Child , SchemaMode, Email, Child } from "floodgate";
    
    @Schema({ mode: SchemaMode.STRICT })
    class Person{
        
        @Str({ minLength: 3, maxLength: 4 })
        name: string;
        
        @Nr({ min: 1 , allowDecimals: false})
        age: number;
        
        @Email()
        email: string;
        
        @Child({ type: Pet })
        favoritePet: Pet;
        
        
        @Arr({ child: Pet })
        otherPets: Pet[];
        
        
        @Arr({ child: Str({ minLength: 3, trim: true }) })
        tags: string[];
        
    }
    
    @Schema({ mode: SchemaMode.STRICT })
    class Pet{
        
        @Str({ minLength: 3, maxLength: 4 })
        name: string;
        
        @Nr({ min: 1 , allowDecimals: false})
        age: number;
        
    }
    
    // Behaves like a normal class
    let person = new Person();
    
    // Modify....
    
    // Validate
    
    SchemaStore.validate(person,(err,person) => {
       // Err contains a ValidationError or is null
       // Person is the validated schema, which may have been modified depending on your configuration
    });
    

Schema modes

  • SchemaMode.STRICT only allows specified properties on an object. Not more not less.
  • SchemaMode.LOOSE only checks specified properties. Leaves other properties as they are.
  • SchemaMode.SHORTEN only checks specified properties. Removes all unknown properties silently.

Validators

  • @Nr(options) ensures a value is a number
  • @Bool(options) ensures a value is a boolean
  • @Str(options) ensures a value is a string
  • @Email(options) ensures a value is an email address
  • @Arr({ child: Type ... }) ensures a value is an array of given type
  • @Child({ type: Type ... }) ensures a value is an object based on another schema
  • More to come soon

Keywords

tree

FAQs

Package last updated on 28 Aug 2016

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