-
Notifications
You must be signed in to change notification settings - Fork 1
/
HeavyExtraction.js
142 lines (135 loc) · 4.33 KB
/
HeavyExtraction.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
var found = function found(array) {
for(var i = 0; i < array.length ; i++){
if(array[i] == true){
array[i] = false;
return(array);
}
}
return(array);
},
WorkDivider = function WorkDivider(x , alldata) {
var p1 = x.indexOf('new App(');
if(p1 !== -1){
var newstr = x.substr(p1),
allStores = [],
chunk = HeavyExtraction(x , allStores);
if(chunk !== undefined){
return(chunk);
}
}
},
HeavyExtraction = function HeavyExtraction(newstr , allStores = []) {
var p2 = newstr.indexOf('new App('),
len1 = newstr.length;
var quortPosition = p2 + 8;
quorttype = newstr.substr(quortPosition, 1),
positionGain = 0,
finalposition = 0;
for (let i = p2 ; i > 0; i--) {
var el = newstr[i], char3 = newstr.substr(i,3) , char5 = newstr.substr(i , 5) , char7 = newstr.substr(i , 7);
if( (el && el == ';') || (el && el == "'") || (el && el == '"') || (el && el == ",")){
console.error('Please make sure you have supplied Valid Component Name on your click native component file.');
return;
}
if( (char3 && char3.toLocaleLowerCase() === 'var') || (char3 && char3.toLocaleLowerCase() === 'let')){
positionGain = i + 3;
break;
}
if((char5 && char5.toLocaleLowerCase() === 'const')){
positionGain = i + 5;
break;
}
if((char7 && char7.toLocaleLowerCase() === 'default')){
positionGain = i + 7;
break;
}
}
var name = newstr.substr(positionGain , (p2 - positionGain) - 1 ),
starter = quortPosition,
state = {
parm1:[]
};
if(name !== void 0){
name = name.trim();
}
if(name.length < 0){
console.log('Please make sure you have supplied component name' , newstr.substr(quortPosition));
}
for (var j = starter + 1; j < len1; j++) {
var el2 = newstr[j];
if(el2 == '{'){
state.parm1.push(true);
}
if(state.parm1.indexOf(true) !== -1){
if(el2 == '}'){
found(state.parm1)
}
}
if(state.parm1.indexOf(true) == -1){
if(el2 == '}'){
if(newstr[j + 1] == ')'){
if(finalposition == 0){
finalposition = j;
componentTree = newstr.substr(starter , finalposition - starter + 1);
allStores.push({
name:name,
componentTree:componentTree,
finalposition:finalposition
});
var lateChunk = newstr.substr(finalposition);
if(lateChunk.indexOf('new App(') !== -1){
HeavyExtraction(lateChunk , allStores);
}else{
break;
}
}
}
}
}
}
return(allStores);
},
cssfound = function(state , index){
for(var i = 0 ; i < state.length ; i++){
if(state[i] == '{'){
state[i] = index;
FirstEntry = true;
break;
}
}
},
check = function(state){
for(var j = 0 ; j < state.length ; j++){
if(typeof state[j] !== 'number'){
return(0);
}
}
return(1);
},
Extraction = function(a){
var state = [],
Endpoint = -1,
a = a.substr(a.indexOf(':')+1);//.replace(/\s/g,'');
for(var i = 0 ; i < a.length ; i++){
var el = a[i];
if(el == '{'){
state.push(el);
}
if(el == '}'){
cssfound(state , i);
}
if(check(state)){
Endpoint = i;
break;
}
}
return(a.substr(0,Endpoint+1));
},
CssExtraction = function(a) {
var csspos = a.indexOf('@css'),
text = a.substr(csspos);
if(text.indexOf(':') !== -1){
return Extraction(text)
}
};
module.exports = { WorkDivider:WorkDivider, CssExtraction:CssExtraction}