src/utils.js   A
last analyzed

Complexity

Total Complexity 3
Complexity/F 3

Size

Lines of Code 16
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 10
mnd 2
bc 2
fnc 1
dl 0
loc 16
rs 10
bpm 2
cpm 3
noi 0
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A utils.js ➔ validate 0 13 3
1
import cottus, { ValidationError } from 'cottus';
2
import { VALIDATION_FAILED } from './Error';
3
4
export function validate(data, rules) {
5
    const validator = cottus.compile([ 'required', { 'attributes': rules } ]);
6
7
    try {
8
        return validator.validate(data);
9
    } catch (error) {
10
        if (error instanceof ValidationError) {
11
            throw new VALIDATION_FAILED(error);
12
        }
13
14
        throw error;
15
    }
16
}
17