-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmax.js
More file actions
24 lines (20 loc) · 721 Bytes
/
max.js
File metadata and controls
24 lines (20 loc) · 721 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 at most %d characters long"
var NUMBER_MESSAGE = "Expected %s to be at most %d"
module.exports = max
function max(m, message) {
var listMessage = message || LIST_MESSAGE
var numberMessage = message || NUMBER_MESSAGE
return function validate(value, key) {
if (typeof value === "number") {
if (value > m || isNaN(value)) {
return {
message: format(numberMessage, key, m),
type: "max"
}
}
} else if (!value || value.length > m) {
return { message: format(listMessage, key, m), type: "max" }
}
}
}