co.validation 2.2.0 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -354,6 +354,45 @@ describe('createValidation', () => {
354
354
  errors: ['Must be a number']
355
355
  });
356
356
  });
357
+ it('supports minValue', () => {
358
+ expect((0, _.createValidation)({
359
+ type: 'minValue',
360
+ min: 1
361
+ })(0)).toEqual({
362
+ data: undefined,
363
+ errors: ['Must be at least 1']
364
+ });
365
+ expect((0, _.createValidation)({
366
+ type: 'minValue',
367
+ min: 1
368
+ })(-1)).toEqual({
369
+ data: undefined,
370
+ errors: ['Must be at least 1']
371
+ });
372
+ expect((0, _.createValidation)({
373
+ type: 'minValue',
374
+ min: 3,
375
+ getMessage: () => 'MinValue'
376
+ })(123)).toEqual({
377
+ data: 123,
378
+ errors: undefined
379
+ });
380
+ expect((0, _.createValidation)({
381
+ type: 'minValue',
382
+ min: 233,
383
+ getMessage: () => 'MinValue'
384
+ })(123)).toEqual({
385
+ data: undefined,
386
+ errors: ['MinValue']
387
+ });
388
+ expect((0, _.createValidation)({
389
+ type: 'minValue',
390
+ min: 333
391
+ })(22)).toEqual({
392
+ data: undefined,
393
+ errors: ['Must be at least 333']
394
+ });
395
+ });
357
396
  it('supports string', () => {
358
397
  expect((0, _.createValidation)({
359
398
  type: 'string',
package/lib/validators.js CHANGED
@@ -84,10 +84,10 @@ exports.number = number;
84
84
  const minValue = ({
85
85
  min,
86
86
  getMessage
87
- }) => value => value && value < min ? {
87
+ }) => value => !isNaN(value) && Number(value) < min ? {
88
88
  errors: (0, _messageProcessor.default)(getMessage, `##minValue`, string => string.replace(/{min}/g, min), min)
89
89
  } : {
90
- data: value
90
+ data: Number(value)
91
91
  };
92
92
 
93
93
  exports.minValue = minValue;
@@ -95,10 +95,10 @@ exports.minValue = minValue;
95
95
  const maxValue = ({
96
96
  max,
97
97
  getMessage
98
- }) => value => value && value > max ? {
98
+ }) => value => !isNaN(value) && Number(value) > max ? {
99
99
  errors: (0, _messageProcessor.default)(getMessage, `##maxValue`, string => string.replace(/{max}/g, max), max)
100
100
  } : {
101
- data: value
101
+ data: Number(value)
102
102
  };
103
103
 
104
104
  exports.maxValue = maxValue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "co.validation",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "description": "JSON based fluent validation for browser, node.js, redux-form and anything javascript compatible.",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {