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.0.0 to 2.0.1

12

m-validate.js

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

var MValidate = function(localesConfig) {
var MValidate = function(localesConfig, locale) {
this.i18n = new Localization(localesConfig);
this.i18n.setLocale(locale);
};

@@ -59,3 +60,10 @@

if (validationResult !== true) {
(response[fieldName])[rule] = this.i18n.__(validationResult);
var splitedResponse = validationResult.split(': ');
if (splitedResponse.length > 1) {
(response[fieldName])[rule] = this.i18n
.__(splitedResponse[0] + ': %s', splitedResponse[1]);
} else {
(response[fieldName])[rule] = this.i18n
.__(validationResult);
}
error = true;

@@ -62,0 +70,0 @@ }

2

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

@@ -5,0 +5,0 @@ "main": "m-validate.js",

@@ -499,9 +499,22 @@ # m-validate

Just call the validation with the definition and the data:
First, you need to configure the language (m-validate uses [i18n-2](https://www.npmjs.com/package/i18n-2)) passing a config object and the language you want your response.
i18n-2 will create the language files as they are needed, but you can set all translations using [this base file](https://raw.githubusercontent.com/moblets/m-validate/master/spec/locales/en-US.json).
```javascript
// Get the definition json here
var validate = require('m-validate');
var MValidate = require('../m-validate');
// The object is a i18n-2 config object. The second parameter is the locale
var validator = new MValidate({
locales: [
'en-US',
'pt-BR'
],
directory: './locales',
extension: '.json'
},
'pt-BR');
var fs = require('fs');
// Get the definition json here
var definitionPath = 'form.json';

@@ -516,3 +529,3 @@ var definitionContent = fs.readFileSync(definitionPath, 'utf8');

// Response variable will have the result
var response = validate(content, mobletDefinitionFields);
var response = validator.validate(content, mobletDefinitionFields);
```

@@ -524,3 +537,3 @@

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:
The **object** is called **"result"** and will have all the **validated fields** as an object. If any validation failed, this object will have the translated validation type and the result, for instance:

@@ -557,2 +570,4 @@ ```javascript

You can check the [tests](https://github.com/moblets/m-validate/tree/develop/spec) to see it in action.
## License

@@ -559,0 +574,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