(str, options)
| 5 | const intLeadingZeroes = /^[-+]?[0-9]+$/; |
| 6 | |
| 7 | export default function isInt(str, options) { |
| 8 | assertString(str); |
| 9 | options = options || {}; |
| 10 | |
| 11 | // Get the regex to use for testing, based on whether |
| 12 | // leading zeroes are allowed or not. |
| 13 | const regex = options.allow_leading_zeroes === false ? int : intLeadingZeroes; |
| 14 | |
| 15 | // Check min/max/lt/gt |
| 16 | let minCheckPassed = (!options.hasOwnProperty('min') || isNullOrUndefined(options.min) || str >= options.min); |
| 17 | let maxCheckPassed = (!options.hasOwnProperty('max') || isNullOrUndefined(options.max) || str <= options.max); |
| 18 | let ltCheckPassed = (!options.hasOwnProperty('lt') || isNullOrUndefined(options.lt) || str < options.lt); |
| 19 | let gtCheckPassed = (!options.hasOwnProperty('gt') || isNullOrUndefined(options.gt) || str > options.gt); |
| 20 | |
| 21 | return regex.test(str) && minCheckPassed && maxCheckPassed && ltCheckPassed && gtCheckPassed; |
| 22 | } |
no test coverage detected