-
Notifications
You must be signed in to change notification settings - Fork 1
/
Object2css.js
46 lines (41 loc) · 1.12 KB
/
Object2css.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
String.prototype.replaceAt=function(index, replacement) {
return this.substr(0, index) + replacement+ this.substr(index + replacement.length);
}
var indexes = function(string , char){
var result = [];
for(var i = 0 ; i < string.length ; i++ ){
var pos1 = string.substr( i , char.length);
if(pos1 == char){
result.push(i)
}
}
return(result)
}
var maker = function(value){
var a = JSON.stringify(value).replace(/"/g,'').replace(/,/g,'; '),
index = indexes(a,'%:')
index2 = indexes(a,'};');
if(index && index.length > 0){
for(var i = 0 ; i < index.length ; i++){
a = a.replaceAt(index[i]+1, " ");
}
}
if(index2 && index2.length > 0){
for(var i = 0 ; i < index2.length ; i++){
a = a.replaceAt(index2[i]+1,' ');
}
}
return a;
};
var toStyles = function(object){
var store = '';
Object.keys(object).forEach(name => {
var value = object[name];
if(typeof value == 'object'){
}
var style = name+' '+maker(value)+'\n';
store = store + style;
});
return(store)
}
module.exports = toStyles;