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 2.2.1 to 2.2.5

LICENSE

102

m-validate.js

@@ -21,2 +21,20 @@ var Localization = require('i18n-2');

/**
* MValidate uses a Json to validate another Json.
*
* @class MValidate
* @param {object} localesConfig Object with the localization config.
* @param {string} locale The locale to be used
* @constructor
* @module MValidate
* @example
* ```javascript
* var localesConfig = {
* locales: ['pt-BR', 'en-US', 'es-ES'],
* directory: './locales',
* extension: '.json'
* };
* var validator = new MValidate(localesConfig, 'pt-BR');
* ```
*/
var MValidate = function(localesConfig, locale) {

@@ -27,2 +45,80 @@ this.i18n = new Localization(localesConfig);

/**
* Validate the content fields using the properties Json
* @method validate
* @param {object} content The Json with each field to be validated
* @param {Json} properties The Json with each field definition
* @return {object} An object with each validated field and the
* found errors. If no error is found, an empty object is returned
* @example
**content** example:
```javascript
var content = {
password: "1234",
title: "Hi there!",
text: "Hello there",
color: "#FFGG32",
backgroundColor: ""
};
```
**properties** example:
```json
"fields": [
{
"name": "password",
"type": "number",
"min-length": 6,
"max-length": 30
},
{
"name": "title",
"type": "text",
"min-length": 2,
"max-length": 144,
"string": "alphaSpace",
"required": true
},
{
"name": "text",
"type": "text-area",
"min-length": 2,
"max-length": 3000,
"string": "alphaSpace"
},
{
"name": "color",
"type": "color"
"required": true
},
{
"name": "backgroundColor",
"type": "color"
"required": true
}
]
```
Using this content with this validator and no translation you should get the
following response:
```javascript
{
password: {
min-length: 'must_be_min: 6'
},
title: {
string: 'not_an_alpha_space'
},
text: {},
color: {
type: 'not_a_color'
},
backgroundColor: {
required: 'field_is_required'
}
}
```
* You can check how to create the translation Json in the [spec/locales](https://github.com/moblets/m-validate/tree/develop/spec/locales) folder.
* Check all possible validations and usage in the [readme documentation](https://github.com/moblets/m-validate#m-validate).
*/
MValidate.prototype.validate = function(content, properties) {

@@ -92,2 +188,8 @@ var error = false;

/**
MValidate module
@module MValidate
@class MValidate
@main MValidate
**/
module.exports = MValidate;

5

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

@@ -31,3 +31,4 @@ "main": "m-validate.js",

"eslint-plugin-jsdoc": "^2.3.1",
"jsdoc": "^3.4.0"
"jsdoc": "^3.4.0",
"markdown-it": "^7.0.0"
},

@@ -34,0 +35,0 @@ "dependencies": {

51

readme.md
# m-validate
![m-validate](m-validate-logo.png)
[![npm](https://img.shields.io/npm/v/m-validate.svg?maxAge=2592000&style=flat-square)](https://www.npmjs.com/package/m-validate)

@@ -11,2 +13,43 @@ [![npm](https://img.shields.io/npm/dt/m-validate.svg?maxAge=2592000&style=flat-square)](https://www.npmjs.com/package/m-validate)

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*
- [Installation](#installation)
- [Available validations](#available-validations)
- [Input type validation](#input-type-validation)
- [number](#number)
- [select, radio and checkbox](#select-radio-and-checkbox)
- [color](#color)
- [date](#date)
- [time](#time)
- [email](#email)
- [url](#url)
- [tel](#tel)
- [Value validation](#value-validation)
- [lessThan and moreThan](#lessthan-and-morethan)
- [lessThanOrEqual and moreThanOrEqual](#lessthanorequal-and-morethanorequal)
- [Length validation](#length-validation)
- [minLength and maxLength](#minlength-and-maxlength)
- [Required validation](#required-validation)
- [required](#required)
- [String validations](#string-validations)
- [alpha](#alpha)
- [alphaSpace](#alphaspace)
- [alphaDash](#alphadash)
- [alphaSymbol](#alphasymbol)
- [alphaNumeric](#alphanumeric)
- [alphaNumericSpace](#alphanumericspace)
- [alphaNumericDash](#alphanumericdash)
- [alphaNumericSymbol](#alphanumericsymbol)
- [numeric](#numeric)
- [numericFloat](#numericfloat)
- [numericDash](#numericdash)
- [numericSymbol](#numericsymbol)
- [Pre requisites](#pre-requisites)
- [Usage](#usage)
- [License](#license)
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
## Installation

@@ -19,3 +62,3 @@

## Available validations
Validations were created for **input type**, **length**, **required** and **string**.
Validations were created for **input type**, **length**, **required**, **value** and **string**.

@@ -188,2 +231,5 @@ ### Input type validation

#### minLength and maxLength
These validations require the data to be a string that has a minimux or maximum number of characters.
**Usage**

@@ -206,2 +252,5 @@

#### required
These validations can be used in any kind of field
**Usage**

@@ -208,0 +257,0 @@

module.exports = function(required, theData) {
var response = true;
if (theData === undefined) {
if (typeof theData === 'undefined' || theData === '' || theData === null) {
response = 'field_is_required';

@@ -5,0 +5,0 @@ }

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