Total Complexity | 4 |
Complexity/F | 0 |
Lines of Code | 21 |
Function Count | 0 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | /** |
||
2 | * A decorator configurable to validate the param type of a function. |
||
3 | * |
||
4 | * @param {object} options - Config. |
||
5 | * @param options.validate - The validation method. |
||
6 | * @param options.skip - Whether to skip the check. |
||
7 | * @returns {Function} - The decorated. |
||
8 | */ |
||
9 | export const validateParam = ({ |
||
10 | validate = (...args) => false, |
||
11 | skip = false, |
||
12 | }) => action => ( |
||
13 | ...args |
||
14 | ) => { |
||
15 | if (skip) return action(...args); |
||
16 | if (validate(...args)) return action(...args); |
||
17 | throw Error('function validation failed'); |
||
18 | }; |
||
19 | |||
20 | export default validateParam; |
||
21 |