-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
64 lines (64 loc) · 1.63 KB
/
utils.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
utils = {
_convertArrayToJson: function(data) {
var propertyNames = data[0];
data = this._checkLastLine(data);
var i = 1;
var cols = [];
for(var line = data[i]; data.length > i; i++, line = data[i]) {
var j = 0;
var temp = {};
for(var prop = line[j]; line.length > j; j++, prop = line[j]) {
temp[propertyNames[j]] = prop;
}
cols.push(temp);
}
return cols;
},
_checkLastLine: function(data) {
var control = data[data.length - 1][0] == '';
if(control) {
data = data.slice(0, data.length - 1);
return data;
} else {
return data;
}
},
fillProps: function(properties, value) {
var i = 0;
for(var prop = properties[i]; i < properties.length; i++, prop = properties[i]) {
if(!value.hasOwnProperty(prop)) {
value[prop] = '';
}
}
return value;
},
fillAllProps: function(properties, values) {
var i = 0;
var filled = [];
for(var value = values[i]; values.length > i; i++, value = values[i]) {
filled.push(this.fillProps(properties, value));
}
return filled;
},
isCompatibility: function(properties, value) {
if(Object.keys(value).length <= properties.length) {
for(var el in value) {
if(!_.contains(properties, el)) {
return false;
}
}
return true;
} else {
return false;
}
},
isAllCompatibility: function(properties, values) {
var i = 0;
for(var value = values[i]; values.length > i; i++, value = values[i]) {
if(!this.isCompatibility(properties, value)) {
return false;
}
}
return true;
}
};