All files / src/ruleHandlers numberRules.js

100% Statements 18/18
100% Branches 2/2
100% Functions 9/9
100% Lines 9/9
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46    9x         9x         9x         9x         9x         9x         9x         9x         9x      
import is from 'is_js';
 
export const min = (name, value, schema) => ({
  isValid: is.above(value * 1, schema.min * 1),
  errorText: `${name} should be greater than ${schema.min}. Current: ${value}`
});
 
export const max = (name, value, schema) => ({
  isValid: is.under(value * 1, schema.max * 1),
  errorText: `${name} should be less than ${schema.max}. Current: ${value}`
});
 
export const equal = (name, value, schema) => ({
  isValid: is.equal(value * 1, schema.equal * 1),
  errorText: `${name} should equal to ${schema.equal * 1}.`
});
 
export const notEqual = (name, value, schema) => ({
  isValid: is.not.equal(value * 1, schema.notEqual * 1),
  errorText: `${name} should not equal to ${schema.notEqual * 1}.`
});
 
export const isPositive = (name, value) => ({
  isValid: is.positive(value * 1),
  errorText: `${name} should be positive.`
});
 
export const isNegative = (name, value) => ({
  isValid: is.negative(value * 1),
  errorText: `${name} should be negative.`
});
 
export const isInt = (name, value) => ({
  isValid: is.integer(value * 1),
  errorText: `${name} should be integer.`
});
 
export const isDecimal = (name, value) => ({
  isValid: is.decimal(value * 1),
  errorText: `${name} should be decimal.`
});
 
export const isIntOrDecimal = (name, value) => ({
  isValid: is.integer(value * 1) || is.decimal(value * 1),
  errorText: `${name} should be either integer or decimal.`
});