Passed
Push — master ( 1201cf...ce6d06 )
by Zhenyu
01:08
created

src/decorator.ts   A

Complexity

Total Complexity 4
Complexity/F 0

Size

Lines of Code 21
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 10
mnd 4
bc 4
fnc 0
dl 0
loc 21
rs 10
bpm 0
cpm 0
noi 0
c 0
b 0
f 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