Completed
Push — master ( 5dc4b7...3c0927 )
by Marcelo
11s
created

src/types.js   A

Complexity

Total Complexity 13
Complexity/F 1

Size

Lines of Code 84
Function Count 13

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 11
Bugs 0 Features 0
Metric Value
cc 0
wmc 13
c 11
b 0
f 0
nc 1
mnd 0
bc 0
fnc 13
dl 0
loc 84
rs 10
bpm 0
cpm 1
noi 7

1 Function

Rating   Name   Duplication   Size   Complexity  
A types.js ➔ ??? 0 1 1
1
import {
2
    __,
3
    T,
4
    all,
5
    allPass,
6
    clamp,
7
    complement,
8
    cond,
9
    equals,
10
    evolve,
11
    gte,
12
    identity,
13
    length,
14
    lte,
15
    map,
16
    none,
17
    propEq,
18
    replace,
19
    split,
20
    take,
21
    tryCatch,
22
    unary,
23
    values
24
} from 'ramda';
25
import { isEmail, isHexColor, isURL } from 'validator';
26
27
export const Integer = { name: 'Integer' };
28
export const Double = { name: 'Double' };
29
export const DateTime = { name: 'DateTime' };
30
export const Natural = { name: 'Natural' };
31
export const Char = length => ({ name: 'Char', length });
32
export const IntegerRange = (from, to) => ({ name: 'IntegerRange', from, to });
33
export const DoubleRange = (from, to) => ({ name: 'DoubleRange', from, to });
34
export const Money = { name: 'Money' };
35
export const String = { name: 'String' };
0 ignored issues
show
Comprehensibility introduced by
You are shadowing the built-in type String. This makes code hard to read, consider using a different name.
Loading history...
36
export const Color = { name: 'Color' };
37
export const Email = { name: 'Email' };
38
export const Checkbox = { name: 'Checkbox' };
39
export const OneOf = values => ({ name: 'OneOf', values });
40
export const Url = { name: 'Url' };
41
export const IntegerMultiRange = (from, to) => ({ name: 'IntegerMultiRange', from, to });
42
export const Calendar = { name: 'Calendar' };
43
export const AutoComplete = { name: 'AutoComplete' };
44
export const Location = { name: 'Location' };
45
46
/**
47
 * Returns the human-readable name of a type
48
 *
49
 * @author Marcelo Haskell Camargo
50
 * @param {String} type {anonymous}
51
 * @return {String} {anonymous}
52
 */
53
export const getTypeName = cond([
54
    [propEq('name', 'Char'), t => `Char(${t.length})`],
55
    [propEq('name', 'IntegerRange'), t => `IntegerRange(${t.from}, ${t.to})`],
56
    [propEq('name', 'DoubleRange'), t => `DoubleRange(${t.from}, ${t.to})`],
57
    [propEq('name', 'OneOf'), t => `OneOf([${t.values.join(', ')}])`],
58
    [propEq('name', 'IntegerMultiRange'), t => `IntegerMultiRange(${t.from}, ${t.to})`],
59
    [T, _.name]
0 ignored issues
show
Bug introduced by
The variable _ seems to be never declared. If this is a global, consider adding a /** global: _ */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
60
]);
61
62
export const validator = {
63
    Color: isHexColor,
64
    Double: complement(isNaN),
0 ignored issues
show
Bug introduced by
The variable isNaN seems to be never declared. If this is a global, consider adding a /** global: isNaN */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
65
    Email: unary(isEmail),
66
    Integer: complement(isNaN),
67
    IntegerMultiRange: (from, to) => allPass([
68
        length & equals(2),
69
        none(isNaN),
0 ignored issues
show
Bug introduced by
The variable isNaN seems to be never declared. If this is a global, consider adding a /** global: isNaN */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
70
        evolve([gte(__, from), lte(__, to)]) & values & all(identity)]),
71
    Money: complement(isNaN),
72
    Natural: lte(0),
73
    Range: (from, to) => clamp(from, to, _) === _,
0 ignored issues
show
Bug introduced by
The variable _ seems to be never declared. If this is a global, consider adding a /** global: _ */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
74
    Url: unary(isURL)
75
};
76
77
export const filter = {
78
    Calendar: date => new Date(date),
79
    Char: take,
80
    Double: parseFloat,
0 ignored issues
show
Bug introduced by
The variable parseFloat seems to be never declared. If this is a global, consider adding a /** global: parseFloat */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
81
    Integer: parseInt(_, 10),
0 ignored issues
show
Bug introduced by
The variable _ seems to be never declared. If this is a global, consider adding a /** global: _ */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
82
    IntegerMultiRange: split(' ') & map(parseInt(_, 10)),
83
    Money: tryCatch(replace(',', '.') & parseFloat, ~NaN)
84
};
85