| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6a098ad commit a0cfb0c
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,7 +13,21 @@ function isUint32(value) { | |||
| 13 | 13 | return value === (value >>> 0); | |
| 14 | 14 | } | |
| 15 | 15 | ||
| 16 | - function validateInt32(value, name) { | ||
| 16 | + function validateInteger(value, name) { | ||
| 17 | + let err; | ||
| 18 | + | ||
| 19 | + if (typeof value !== 'number') | ||
| 20 | + err = new ERR_INVALID_ARG_TYPE(name, 'number', value); | ||
| 21 | + else if (!Number.isSafeInteger(value)) | ||
| 22 | + err = new ERR_OUT_OF_RANGE(name, 'an integer', value); | ||
| 23 | + | ||
| 24 | + if (err) { | ||
| 25 | + Error.captureStackTrace(err, validateInteger); | ||
| 26 | + throw err; | ||
| 27 | + } | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + function validateInt32(value, name, min = -2147483648, max = 2147483647) { | ||
| 17 | 31 | if (!isInt32(value)) { | |
| 18 | 32 | let err; | |
| 19 | 33 | if (typeof value !== 'number') { | |
@@ -53,6 +67,7 @@ function validateUint32(value, name, positive) { | |||
| 53 | 67 | module.exports = { | |
| 54 | 68 | isInt32, | |
| 55 | 69 | isUint32, | |
| 70 | + validateInteger, | ||
| 56 | 71 | validateInt32, | |
| 57 | 72 | validateUint32 | |
| 58 | 73 | }; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments