-
Notifications
You must be signed in to change notification settings - Fork 0
/
jsony.js
56 lines (35 loc) · 944 Bytes
/
jsony.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
;(function(){
var JSONY = function(){
this.input = '';
this.output = {};
};
JSONY.prototype.parse = function(string){
this.input = string;
var tmpObj = {};
//string: "{ hello: \"world\" }",
//object: { hello: "world" }
// clean spaces
this.input = this.input.split(' ').join('');
// unescape quotes
this.input.replace(new RegExp('\\"', 'g'),'"');
// clean braces
this.input = this.input.substr(1 , this.input.length - 2);
// break by elements
if( this.input.indexOf(',') > -1){
}else{
key = this.input.split(':')[0];
if( typeof this.input.split(':')[1] == 'string' )
{
value = this.input.split(':')[1];
value = value.substr(1 , value.length - 2)
}else{
value = this.input.split(':')[1];
}
tmpObj[key] = value;
}
console.log(tmpObj);
this.output = tmpObj;
return this.output ;
}
window.JSONY = JSONY;
})()