-
-
Notifications
You must be signed in to change notification settings - Fork 258
/
base.js
101 lines (89 loc) · 2.09 KB
/
base.js
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
* Copyright (C) 2015-2016 Ben Ockmore
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
import _ from 'lodash';
export function formatRow(kind, key, lhs, rhs) {
if (_.isNil(lhs) && _.isNil(rhs)) {
return [];
}
if (kind === 'N' || _.isNil(lhs)) {
return {
key,
kind: 'N',
rhs
};
}
if (kind === 'D' || _.isNil(rhs)) {
return {
key,
kind: 'D',
lhs
};
}
return {
key,
kind,
lhs,
rhs
};
}
export function formatChange(change, label, transformer) {
return formatRow(
change.kind,
label,
transformer(change.lhs),
transformer(change.rhs)
);
}
export function formatGenderChange(change) {
return formatChange(
change,
'Gender',
(side) => side && [side.name]
);
}
export function formatEndedChange(change) {
return [
formatChange(
change,
'Ended',
(side) => [_.isNull(side) || (side ? 'Yes' : 'No')]
)
];
}
export function formatTypeChange(change, label) {
// eslint-disable-next-line consistent-return
return formatChange(change, label, (side) => {
if (typeof side === 'string') {
return [side];
}
else if (side) {
return [side.label];
}
});
}
export function formatScalarChange(change, label) {
return formatChange(change, label, (side) => side && [side]);
}
export function formatAreaChange(change, label) {
return formatChange(
change,
label || 'Area',
// eslint-disable-next-line
(side) => typeof side === 'string' ? [side] : side && [side.name]
);
}