Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

satpam

Package Overview
Dependencies
Maintainers
1
Versions
114
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

satpam

Simple and Effective Object Validator

  • 0.0.8
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1K
decreased by-15.4%
Maintainers
1
Weekly downloads
 
Created
Source

satpam


Satpam is a wrapper for some nodejs validator libraries, I made Satpam so it's easy to create custom validator with parameters and custom validation messages.

Build Status

Quick Usage

var satpam = require('satpam');
var rules = {
  name        : ['required']
  officeEmail : ['email'],
  phone       : ['required', 'numeric']
};


var input = {
  name: 'Sendy',
  title: 'Lord',
  officeEmail: 'invalid email',
  phone: 'hi there123'
};

var result = satpam.validate(rules, input);

if (result.success === true) {
  // valid
} else {
  // invalid
  result.messages.officeEmail.email === 'OfficeEmail must be email';
  result.messages.phone.number === 'Phone must be numeric';

  // or get all messages in array form
  result.messages.messageArray[0] = 'OfficeEmail must be email';
  result.messages.messageArray[1] = 'Phone must be numeric';
}

Available Rules

  • alpha
  • alphanumeric
  • begin-with
  • date
  • email
  • image
  • max-length
  • max-value
  • min-length
  • min-value
  • non-blank
  • numeric
  • required
  • string
  • url

Custom rules

validator.addCustomValidation('must-be-ironman', function(val) {
  return val === 'ironman';
});

validator.setValidationMessage('must-be-ironman', 'Not ironman D:');

// with parameters
validator.addCustomValidation('range:$1:$2', function(val, ruleObj) {
  return val >= ruleObj.params[0] && val <= ruleObj.params[1];
});

// if validation fails it will set message to:
// "PropertyName must between 0 and 30"
validator.setValidationMessage('range:$1:$2', '<%= propertyName %> must between <%= ruleParams[0] %> and <%= ruleParams[1] %>');

TODOs

  • Add more basic validation rules
  • Validate file types

More examples -> Here

Keywords

FAQs

Package last updated on 28 Oct 2015

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc