felixriddle.checkpoint
TypeScript icon, indicating that this package has built-in type declarations

2.0.5 • Public • Published

Checkpoint

Data validation package and other miscellaneous things.

Introduction

Last update: 2.0.0 This is an introduction to checkpoint

Create a validator

import Validator from "validator";

// Create a validator and multiple scopes
let val = new Validator()
    .createScope("email", "email", "felix@email.com")
    .isNotFalsy()
    .isEmail()
    .lengthRange(5, 64)
    .isStr()
    // Use scope
    .useScope("email", "friend_email", "joe@email.com")
    // Create new scope
    // These ones pass
    .createScope("username", "username", "my_cool_username_65")
    .isNotFalsy()
    .lengthRange(5, 64)
    .isStr()
    // Phone scope
    .createScope("phone", "phone_number", 6756829123)
    .isNotFalsy()
    .isNum()
    // Use phone scope again
    // And fail both tests
    .useScope("phone", "alt_phone", "");

Perform validation and check if passed

// Perform validations
let result = val.validate();

// The result should have an array of 'ValidationResult' objects
if(result.length > 0) {
    console.log(`Not all validations passed`);
}

Print every result message

// Perform validations
let result = val.validate();

// Print result messages
for(let res in result) {
    console.log(`Field: ${}`, res.field);
    console.log(`Message: ${}\n`, res.message);
}

Todo

  • [ ] Form fetch all parses what is clearly a number or float
  • [x] Data validation
  • [ ] Object validation
  • [x] Scopes

Readme

Keywords

Package Sidebar

Install

npm i felixriddle.checkpoint

Weekly Downloads

15

Version

2.0.5

License

ISC

Unpacked Size

169 kB

Total Files

9

Last publish

Collaborators

  • fedekiller999