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

m-validate

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

m-validate - npm Package Compare versions

Comparing version 0.0.3 to 0.0.6

spec/form.json

5

package.json
{
"name": "m-validate",
"version": "0.0.3",
"version": "0.0.6",
"description": "NodeJS simple validation functions",

@@ -28,3 +28,6 @@ "main": "m-validate.js",

"jsdoc": "^3.4.0"
},
"dependencies": {
"moment": "^2.13.0"
}
}

145

readme.md

@@ -1,3 +0,144 @@

# Node Simple Validate
# m-validate
NodeJS simple validation functions
[![npm](https://img.shields.io/npm/v/npm.svg?maxAge=2592000&style=flat-square)](https://www.npmjs.com/package/m-validate)
[![npm](https://img.shields.io/npm/dt/express.svg?maxAge=2592000&style=flat-square)](https://www.npmjs.com/package/m-validate)
![stars](https://img.shields.io/github/stars/moblets/m-validate.svg?style=flat-square)
![license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)
Moblets' NodeJS simple validation to validate data based on a deffinition JSon.
## Installation
```
$ npm install --save m-validate
```
## Pre requisites
You must have a definition json like this:
```json
{
"fields": [
{
"name": "name",
"type": "text",
"min-length": 3
},
{
"name": "password",
"type": "number",
"max-length": 4,
"min-length": 4,
"required": true
},
{
"name": "description",
"type": "text-area"
},
{
"name": "quantity",
"type": "select",
"values": {
"0": "value_3",
"1": "value_6",
"2": "value_9"
}
},
{
"name": "themeColor",
"type": "color"
},
{
"name": "birthDay",
"type": "date"
},
{
"name": "arrival",
"type": "time"
}
]
}
```
This definition must have all the fields and the validations.
And you must have the data to be validated:
```json
{
"password": "1232",
"description": "A great fidelity card",
"quantity": "0"
}
```
## Usage
Just call the validation with the definition and the data:
```javascript
// Get the definition json here
var validate = require('m-validate');
var fs = require('fs');
var definitionPath = 'form.json';
var definitionContent = fs.readFileSync(definitionPath, 'utf8');
var definition = JSON.parse(definitionContent);
var definitionFields = definition.fields;
// Assuming the data comes from a post
var content = req.body;
// Response variable will have the result
var response = validate(content, mobletDefinitionFields);
```
The validation response will be an object with two items: a **boolean** and an **object**.
The **boolean** is called **"error"** and will be true if **any of the validations did not pass**.
The **object** is called **"result"** and will have all the **validated fields** as an object. If any validation failed, this object will have the validation type and the result, for instance:
```javascript
{
error: true,
response: {
name: {},
password: {
required: 'field_is_required',
'max-length': 'must_be_more_than_chars: 4'
},
description: {},
quantity: {},
position: {},
color: {},
themeColor: {
type: 'not_a_color'
},
birthDay: {},
arrival: {},
email: {},
siteaddress: {
type: 'not_an_url'
},
phone: {
type: 'not_a_tel'
},
cell: {}
}
}
```
## License
The MIT License (MIT)
Copyright (c) 2016 Moblets
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Sorry, the diff of this file is too big to display

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