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

fieldval

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fieldval

fieldval

  • 0.2.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

FieldVal-JS

The FieldVal-JS library allows you to easily validate objects and provide readable and structured error reports.

//Import FieldVal and FieldVal-BasicVal (some simple checks)
var FieldVal = require('fieldval');
var bval = require('fieldval-basicval');

//Have some data to validate
var data = {
    my_integer: "clearly not an integer"
}

//Create a FieldVal instance using the data
var validator = new FieldVal(data);

//Get values using validator.get(field_name, field_type, required)
var my_integer = validator.get("my_integer", bval.integer(true));

//Log the result of the validation (null if no errors)
console.log(validator.end());

Output:

{
    "invalid": {
        "my_integer": {
            "error_message": "Incorrect field type. Expected integer.",
            "error": 2,
            "expected": "integer",
            "received": "string"
        }
    },
    "error_message": "One or more errors.",
    "error": 0
}

Chaining

validator.get("my_integer", bval.integer(true))

checks that the value is an integer and indicates that it is required (true).

validator.get("my_integer", bval.integer(true), bval.minimum(42))

now also checks that the integer is at least 42. You can add as many checks as you like from here, or just write your own - they're just functions that return errors.

FieldVal Modules

  • FieldVal-JS (This repository)

    The core of FieldVal - provides basic validation functionality such as getting keys from an object and allows chaining of checks.

  • FieldVal-BasicVal-JS

    Basic checks and errors for required fields, type checking, length and numeric rules.

  • FieldVal-UI

    A companion library that creates customizable forms that parse and display FieldVal error structures.

NodeJS Usage

To install the node packages, run:

npm install fieldval
npm install fieldval-basicval

Bower Usage

The FieldVal library works both as a node package and via the browser. To install the node packages, run:

bower install fieldval
bower install fieldval-basicval

How to use in the browser

To use in the browser, download and include the fieldval.js file from this repository and fieldval-basicval.js from https://github.com/FieldVal/fieldval-basicval-js/.

Development

This project uses gulp.js to build and mocha to test.

npm install
gulp js
mocha test/test

FAQs

Package last updated on 16 Jan 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