Comparing version 1.0.3 to 1.0.4
@@ -72,3 +72,3 @@ 'use strict'; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
@@ -80,2 +80,8 @@ | ||
var classCallCheck = function (instance, Constructor) { | ||
@@ -105,52 +111,6 @@ if (!(instance instanceof Constructor)) { | ||
var set = function set(object, property, value, receiver) { | ||
var desc = Object.getOwnPropertyDescriptor(object, property); | ||
if (desc === undefined) { | ||
var parent = Object.getPrototypeOf(object); | ||
if (parent !== null) { | ||
set(parent, property, value, receiver); | ||
} | ||
} else if ("value" in desc && desc.writable) { | ||
desc.value = value; | ||
} else { | ||
var setter = desc.set; | ||
if (setter !== undefined) { | ||
setter.call(receiver, value); | ||
} | ||
} | ||
return value; | ||
}; | ||
var Validator = function () { | ||
function Validator(data, rules) { | ||
var customMessages = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; | ||
var customNames = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3]; | ||
var customMessages = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var customNames = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; | ||
classCallCheck(this, Validator); | ||
@@ -184,10 +144,10 @@ | ||
key: 'parseItemRules', | ||
value: function parseItemRules(rule) { | ||
value: function parseItemRules(itemRules) { | ||
var self = this; | ||
var arr = []; | ||
var rules = []; | ||
rule.split('|').forEach(function (ruleAndArgs) { | ||
itemRules.split('|').forEach(function (ruleAndArgs) { | ||
if (ruleAndArgs.trim()) { | ||
var args = ruleAndArgs.split(':'); | ||
arr.push({ | ||
rules.push({ | ||
name: self.titleCase(args[0], '_'), | ||
@@ -199,3 +159,3 @@ params: args[1] ? args[1].split(',') : [] | ||
return arr; | ||
return rules; | ||
} | ||
@@ -336,5 +296,4 @@ }, { | ||
value: function getMessage(name, rule) { | ||
var key = this.snakeCase(rule.name); | ||
var msg = this.customMessages[name + '.' + key]; | ||
// return custom message if defined | ||
var msg = this.getCustomMessage(name, rule); | ||
if (typeof msg !== 'undefined') { | ||
@@ -344,2 +303,4 @@ return msg; | ||
// then, use the default message for that rule | ||
var key = this.snakeCase(rule.name); | ||
msg = Messages[key]; | ||
@@ -354,3 +315,18 @@ // message might has sub-rule | ||
} | ||
/** | ||
* return user-defined custom message for a given rule, or undefined | ||
*/ | ||
}, { | ||
key: 'getCustomMessage', | ||
value: function getCustomMessage(name, rule) { | ||
var ruleName = this.snakeCase(rule.name); | ||
var msg = this.customMessages[name + '.' + ruleName]; | ||
// first, check for custom message for specific attribute rule | ||
// then, check for custom message for rule | ||
return typeof msg === 'undefined' ? this.customMessages[ruleName] : msg; | ||
} | ||
}, { | ||
key: 'getDataType', | ||
@@ -446,3 +422,3 @@ value: function getDataType(name) { | ||
value: function hasError() { | ||
var name = arguments.length <= 0 || arguments[0] === undefined ? null : arguments[0]; | ||
var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; | ||
@@ -1120,3 +1096,3 @@ if (name === null) { | ||
key: 'dateRules', | ||
get: function get() { | ||
get: function get$$1() { | ||
return ['Before', 'After', 'DateBetween']; | ||
@@ -1126,3 +1102,3 @@ } | ||
key: 'sizeRules', | ||
get: function get() { | ||
get: function get$$1() { | ||
return ['Size', 'Between', 'Min', 'Max']; | ||
@@ -1132,3 +1108,3 @@ } | ||
key: 'numericRules', | ||
get: function get() { | ||
get: function get$$1() { | ||
return ['Numeric', 'Integer']; | ||
@@ -1138,3 +1114,3 @@ } | ||
key: 'implicitRules', | ||
get: function get() { | ||
get: function get$$1() { | ||
return ['Required', 'Filled', 'RequiredWith', 'RequiredWithAll', 'RequiredWithout', 'RequiredWithoutAll', 'RequiredIf', 'RequiredUnless', 'Accepted', 'Present']; | ||
@@ -1144,3 +1120,3 @@ } | ||
key: 'dependentRules', | ||
get: function get() { | ||
get: function get$$1() { | ||
return ['RequiredWith', 'RequiredWithAll', 'RequiredWithout', 'RequiredWithoutAll', 'RequiredIf', 'RequiredUnless', 'Confirmed', 'Same', 'Different', 'Unique', 'Before', 'After']; | ||
@@ -1151,3 +1127,3 @@ } | ||
value: function make(data, rules) { | ||
var customMessages = arguments.length <= 2 || arguments[2] === undefined ? [] : arguments[2]; | ||
var customMessages = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : []; | ||
var customNames = arguments[3]; | ||
@@ -1161,2 +1137,2 @@ | ||
module.exports = Validator; | ||
module.exports = Validator; |
{ | ||
"name": "Validator", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Client-side Javascript Validator library. Ports from Laravel 5.2", | ||
@@ -26,11 +26,12 @@ "main": "dist/Validator.js", | ||
"devDependencies": { | ||
"babel-preset-es2015": "^6.9.0", | ||
"babel-preset-es2015-rollup": "^1.1.1", | ||
"babel-plugin-external-helpers": "^6.22.0", | ||
"babel-preset-es2015": "^6.22.0", | ||
"babel-register": "^6.11.6", | ||
"chai": "^3.5.0", | ||
"mocha": "^2.5.3", | ||
"mocha": "^3.2.0", | ||
"rimraf": "^2.5.2", | ||
"rollup-plugin-babel": "^2.6.1", | ||
"rollup": "^0.41.4", | ||
"rollup-plugin-babel": "^2.7.1", | ||
"rollup-watch": "^2.4.0" | ||
} | ||
} |
# Javascript Validator library | ||
[![Travis build](https://img.shields.io/travis/ratiw/Validator.svg)](https://travis-ci.org/ratiw/Validator) | ||
[![npm](https://img.shields.io/npm/v/Validator.svg)](https://www.npmjs.com/package/Validator) | ||
[![npm](https://img.shields.io/npm/dt/Validator.svg)](https://www.npmjs.com/package/Validator) | ||
[![npm](https://img.shields.io/npm/dm/Validator.svg)](https://www.npmjs.com/package/Validator) | ||
> Client-side javascript validator library. Ports from Laravel 5.2 | ||
## Instalation | ||
## Installation | ||
@@ -9,0 +11,0 @@ 1. Included as global `<script>`, copy the `Validator.js` file inside `dist` directory to your project directory |
@@ -59,10 +59,10 @@ import Messages from './Messages' | ||
parseItemRules(rule) { | ||
parseItemRules(itemRules) { | ||
let self = this | ||
let arr = [] | ||
let rules = [] | ||
rule.split('|').forEach(function(ruleAndArgs) { | ||
itemRules.split('|').forEach(function(ruleAndArgs) { | ||
if (ruleAndArgs.trim()) { | ||
let args = ruleAndArgs.split(':') | ||
arr.push({ | ||
rules.push({ | ||
name: self.titleCase(args[0], '_'), | ||
@@ -74,3 +74,3 @@ params: args[1] ? args[1].split(',') : [] | ||
return arr | ||
return rules | ||
} | ||
@@ -196,5 +196,4 @@ | ||
getMessage(name, rule) { | ||
let key = this.snakeCase(rule.name) | ||
let msg = this.customMessages[name + '.' + key] | ||
// return custom message if defined | ||
let msg = this.getCustomMessage(name, rule) | ||
if (typeof(msg) !== 'undefined') { | ||
@@ -204,2 +203,4 @@ return msg | ||
// then, use the default message for that rule | ||
let key = this.snakeCase(rule.name) | ||
msg = Messages[key] | ||
@@ -215,2 +216,16 @@ // message might has sub-rule | ||
/** | ||
* return user-defined custom message for a given rule, or undefined | ||
*/ | ||
getCustomMessage(name, rule) { | ||
let ruleName = this.snakeCase(rule.name) | ||
let msg = this.customMessages[name + '.' + ruleName] | ||
// first, check for custom message for specific attribute rule | ||
// then, check for custom message for rule | ||
return typeof(msg) === 'undefined' | ||
? this.customMessages[ruleName] | ||
: msg | ||
} | ||
getDataType(name) { | ||
@@ -217,0 +232,0 @@ if (this.hasRule(name, this.numericRules)) { |
Sorry, the diff of this file is not supported yet
1752
93
67644
9
11