-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmax.ts
39 lines (35 loc) · 1.1 KB
/
max.ts
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
import { isNumeric } from '../common/utils';
import { IncorrectArgumentTypeError } from './IncorrectArgumentTypeError';
import {
getValue,
isInputElement,
isMeterElement,
isOutputElement,
isProgressElement,
isSelectElement
} from '../common/dom';
export default {
passed(elements: HTMLElement[], max: string): boolean {
if (!isNumeric(max)) {
throw new IncorrectArgumentTypeError(`max rule has incorrect argument ${max}. Expected a number.`);
}
return elements.every((element: HTMLElement) => {
if (
isInputElement(element)
|| isSelectElement(element)
|| isProgressElement(element)
|| isMeterElement(element)
|| isOutputElement(element)
) {
const value = getValue(element);
return value.every((val: string) => {
return isNumeric(val) && parseFloat(val) <= parseFloat(max);
});
}
return true;
})
},
message(): string {
return 'max';
}
};