-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrange.js
More file actions
24 lines (20 loc) · 782 Bytes
/
range.js
File metadata and controls
24 lines (20 loc) · 782 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
var format = require("./lib/format")
var LIST_MESSAGE = "Expected %s to be between %d and %d characters long"
var NUMBER_MESSAGE = "Expected %s to between %d and %d"
module.exports = range
function range(n, m, message) {
var listMessage = message || LIST_MESSAGE
var numberMessage = message || NUMBER_MESSAGE
return function validate(value, key) {
if (typeof value === "number") {
if (value < n || value > m || isNaN(value)) {
return {
message: format(numberMessage, key, n, m),
type: "range"
}
}
} else if (!value || value.length < n || value.length > m) {
return { message: format(listMessage, key, n, m), type: "range" }
}
}
}