m-validate
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -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 @@ } |
{ | ||
"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 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
22379
279
580
0