drip-form-validator
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -19,5 +19,6 @@ "use strict"; | ||
}, | ||
betweenWith: 'The {{field}} must be between {{minLabel}} and {{maxLabel}}.', | ||
date: 'The {{field}} is not a valid date.', | ||
dateFormat: 'The {{field}} does not matche the date format {{format}}.', | ||
different: 'The {{field}} and {{key}} must be different.', | ||
different: 'The {{field}} and {{label}} must be different.', | ||
email: 'The {{field}} must be a valid email address.', | ||
@@ -32,6 +33,7 @@ equals: 'The {{field}} must be "{{value}}".', | ||
max: { | ||
defaultMessage: 'The {{field}} may note be greater than {{max}}.', | ||
string: 'The {{field}} may note be greater than {{max}} characters.', | ||
array: 'The {{field}} may note be greater than {{max}} items.', | ||
defaultMessage: 'The {{field}} may not be greater than {{max}}.', | ||
string: 'The {{field}} may not be greater than {{max}} characters.', | ||
array: 'The {{field}} may not be greater than {{max}} items.', | ||
}, | ||
maxWith: 'The {{field}} may not be greater than {{label}}.', | ||
min: { | ||
@@ -42,2 +44,3 @@ defaultMessage: 'The {{field}} must be at least {{min}}.', | ||
}, | ||
minWith: 'The {{field}} must be at least {{label}}.', | ||
natural: 'The {{field}} must be a natural number.', | ||
@@ -50,3 +53,3 @@ notIn: 'The {{field}} is invalid.', | ||
required: 'The {{field}} field is required.', | ||
same: 'The {{field}} and {{key}} must match.', | ||
same: 'The {{field}} and {{label}} must match.', | ||
size: { | ||
@@ -53,0 +56,0 @@ defaultMessage: 'The {{field}} must be {{size}}.', |
@@ -19,5 +19,6 @@ "use strict"; | ||
}, | ||
betweenWith: '{{field}}は{{min}}から{{max}}の間で指定してください。', | ||
date: '{{field}}には有効な日付を指定してください。', | ||
dateFormat: '{{field}}には有効な日付を指定してください。', | ||
different: '{{field}}は{{key}}には異なる内容を指定してください。', | ||
different: '{{field}}は{{label}}には異なる内容を指定してください。', | ||
email: '{{field}}には有効なメールアドレスを指定してください。', | ||
@@ -32,11 +33,13 @@ equals: '{{field}}は"{{value}}"でなくてはなりません。', | ||
max: { | ||
defaultMessage: '{{field}}は{{max}}以下の数値を指定してください。', | ||
defaultMessage: '{{field}}は{{max}}以下を指定してください。', | ||
string: '{{field}}は{{max}}文字以下で指定してください。', | ||
array: '{{field}}は{{max}}個以下で指定してください。', | ||
}, | ||
maxWith: '{{field}}は{{max}}以下の数値を指定してください。', | ||
min: { | ||
defaultMessage: '{{field}}は{{min}}以上の数値を指定してください。', | ||
defaultMessage: '{{field}}は{{min}}以上を指定してください。', | ||
string: '{{field}}は{{min}}文字以上で指定してください。', | ||
array: '{{field}}は{{min}}個以上で指定してください。', | ||
}, | ||
minWith: '{{field}}は{{min}}以上を指定してください。', | ||
natural: '{{field}}は自然数でなくてはなりません。', | ||
@@ -49,3 +52,3 @@ notIn: '{{field}}が正しくありません。', | ||
required: '{{field}}は必須項目です。', | ||
same: '{{field}}と{{key}}は一致しなくてはなりません。', | ||
same: '{{field}}と{{label}}は一致しなくてはなりません。', | ||
size: { | ||
@@ -52,0 +55,0 @@ defaultMessage: '{{field}}は{{size}}を指定してください。', |
@@ -10,3 +10,6 @@ "use strict"; | ||
}, { | ||
mapArgsToParams: function (key) { return ({ key: key }); }, | ||
mapArgsToParams: function (key, v) { return ({ | ||
key: key, | ||
label: v.getLabel(key), | ||
}); }, | ||
}); |
@@ -19,2 +19,3 @@ import './array'; | ||
import './between'; | ||
import './betweenWith'; | ||
import './dateFormat'; | ||
@@ -28,3 +29,5 @@ import './different'; | ||
import './max'; | ||
import './maxWith'; | ||
import './min'; | ||
import './minWith'; | ||
import './natural'; | ||
@@ -31,0 +34,0 @@ import './notIn'; |
@@ -21,2 +21,3 @@ "use strict"; | ||
require("./between"); | ||
require("./betweenWith"); | ||
require("./dateFormat"); | ||
@@ -30,3 +31,5 @@ require("./different"); | ||
require("./max"); | ||
require("./maxWith"); | ||
require("./min"); | ||
require("./minWith"); | ||
require("./natural"); | ||
@@ -33,0 +36,0 @@ require("./notIn"); |
@@ -10,3 +10,6 @@ "use strict"; | ||
}, { | ||
mapArgsToParams: function (key) { return ({ key: key }); }, | ||
mapArgsToParams: function (key, v) { return ({ | ||
key: key, | ||
label: v.getLabel(key), | ||
}); }, | ||
}); |
@@ -74,3 +74,3 @@ /// <reference types="node" /> | ||
export interface MapArgsToParams { | ||
(args: any): any; | ||
(args: any, validator: Validator): any; | ||
} | ||
@@ -123,3 +123,3 @@ export interface BuiltinRuleOptions { | ||
} | ||
declare class Validator extends EventEmitter { | ||
export default class Validator extends EventEmitter { | ||
static _locale: string; | ||
@@ -249,2 +249,1 @@ static _localeMessages: DefinedLocaleMessages; | ||
} | ||
export default Validator; |
@@ -49,4 +49,2 @@ "use strict"; | ||
var opts = __assign({}, defaultOptions, options); | ||
_this.setValues(values); | ||
_this.setRules(rules); | ||
if (opts.normalizers) | ||
@@ -58,2 +56,4 @@ _this.setNormalizers(opts.normalizers); | ||
_this.setLabels(opts.labels); | ||
_this.setValues(values); | ||
_this.setRules(rules); | ||
return _this; | ||
@@ -387,2 +387,3 @@ } | ||
Validator.prototype.mergeRules = function (rules) { | ||
var _this = this; | ||
invariant(isPlainObject(rules), '"rules" must be plain object'); | ||
@@ -394,3 +395,3 @@ var results = __assign({}, this._rules, rules); | ||
if (rule) { | ||
results[field] = __assign({}, (results[field] || {}), (_a = {}, _a[ruleName] = rule.mapArgsToParams(params), _a)); | ||
results[field] = __assign({}, (results[field] || {}), (_a = {}, _a[ruleName] = rule.mapArgsToParams(params, _this), _a)); | ||
} | ||
@@ -397,0 +398,0 @@ var _a; |
{ | ||
"name": "drip-form-validator", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Simple and Powerful and Customizable validation library for JavaScript.", | ||
@@ -56,4 +56,4 @@ "main": "lib/index.js", | ||
"rimraf": "^2.6.1", | ||
"sinon": "^2.3.4", | ||
"ts-node": "^3.0.6", | ||
"sinon": "^2.3.5", | ||
"ts-node": "^3.1.0", | ||
"tslint": "^5.4.3", | ||
@@ -60,0 +60,0 @@ "typedoc": "^0.7.1", |
@@ -847,2 +847,6 @@ import * as sinon from 'sinon'; | ||
Validator.registerAsyncRule('rule4', () => Promise.resolve(), { | ||
mapArgsToParams: (baz: string, v: Validator) => ({ baz, v }), | ||
}); | ||
v.setRules({ | ||
@@ -853,2 +857,3 @@ key1: { | ||
rule3: 'key1-rule3', | ||
rule4: 'key1-rule4', | ||
}, | ||
@@ -859,2 +864,3 @@ key2: { | ||
rule3: 'key2-rule3', | ||
rule4: 'key2-rule4', | ||
}, | ||
@@ -868,2 +874,3 @@ }); | ||
rule3: { bar: 'key1-rule3' }, | ||
rule4: { baz: 'key1-rule4', v }, | ||
}, | ||
@@ -874,2 +881,3 @@ key2: { | ||
rule3: { bar: 'key2-rule3' }, | ||
rule4: { baz: 'key2-rule4', v }, | ||
}, | ||
@@ -876,0 +884,0 @@ }); |
196137
196
5184