-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.html
217 lines (194 loc) · 11.7 KB
/
index.html
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<html>
<head>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-119928829-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-119928829-1');
</script>
<title>निम्न | NIMN</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prettify/r298/prettify.min.css">
<link rel="stylesheet" href="static/css/jquery-confirm.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prettify/r298/prettify.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.min.css">
<script src="static/js/jquery-confirm.min.js"></script>
<script src="dist/nimn.js"></script>
<script src="https://cdn.rawgit.com/nimndata/nimnjs-schema-builder/1f50f478/dist/nimn-schema-builder.js"></script>
<script src="static/js/nimn-dateparser.js"></script>
</head>
<body>
<div class="container-fluid">
<a style="position: absolute; left: 0; z-index: 1" href="https://github.com/nimndata/nimnjs-node"><img class="bring-up" style="position: absolute; top: 0; left: 0; border: 0;" src="https://camo.githubusercontent.com/121cd7cbdc3e4855075ea8b558508b91ac463ac2/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f6c6566745f677265656e5f3030373230302e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_left_green_007200.png"></a>
<div class="row">
<div class="col-md-12" style="text-align: center">
<img src="static/img/nimnjs-logo.png" >
</div>
</div>
<div class="row">
<div class="col-md-4">
Length:<span id="lengthJson" class="badge" style="margin:5px">0</span>
<textarea id="txtJson" name="json" rows="30" class="form-control" placeholder="Paste JSON here"></textarea>
</div>
<div class="col-md-4">
<br>
<br>
<br>
<button id="j2n" style="width: 100%" class="btn btn-primary" type="button">>> NIMN data</button>
<br>
<br>
<input id="nimnDt" class="" type="checkbox" disabled>Compress dates
<br>
<button id="n2j" style="width: 100%" class="btn btn-primary" type="button"><< JSON</button>
<br>
<br>
<textarea id="txtNimnSchema" name="nimn" rows="20" class="form-control" placeholder="Paste NIMN schema here"></textarea>
</div>
<div class="col-md-4">
<button id="makeitreadable" style="width: 100%;" class="btn btn-primary disabled" type="button">Make it Readable</button>
Length:<span id="lengthNimn" class="badge" style="margin:5px">0</span>
<textarea id="txtNimn" name="nimn" rows="30" class="form-control" placeholder="Paste NIMN data here"></textarea>
</div>
</div>
<script>
$( document ).ready(function() {
setTimeout(function(){
$.dialog({
title: '',
content: '<p>Give a '
+ '<a href="https://github.com/nimndata/nimnjs/stargazers">star</a> to appreciate the work'
+ '.</p>'
});
}, 5000);
$("#j2n").click(function(){
try{
var jObj = JSON.parse($('#txtJson').val());
var schema = {};
if($('#txtNimnSchema').val()){
schema = JSON.parse($('#txtNimnSchema').val()
);
}else{
schema = nimnSchemaBuilder.build(jObj);
$('#txtNimnSchema').text(JSON.stringify(schema,null,4));
}
var newSchema = nimn.buildSchema(schema)
/* if($("#nimnDt").prop("checked")){
nimnEncoder.addDataHandler("date",function(val){
return nimnDateparser.parse(val,true,true,true)
},function(val){
return nimnDateparser.parseBack(val,true,true,true)
});
} */
var result = nimn.stringify(newSchema, jObj);
$('#txtNimn').val(result);
$("#lengthJson")[0].innerText= JSON.stringify(jObj).length;
$("#lengthNimn")[0].innerText= result.length;
$("#makeitreadable").removeClass("disabled");
}catch(e){
$('#txtNimn').val(e);
$("#makeitreadable").addClass("disabled");
$("#lengthNimn")[0].innerText = "#"
$("#lengthJson")[0].innerText = "#"
}
});
$("#n2j").click(function(){
try{
var schemaStr = $('#txtNimnSchema').val();
var nimnData = $('#txtNimn').val()
if(schemaStr === ""){
$.dialog({
title: 'Schema is not given',
content: '<p>NIMN data parsing depends on the JSON schema. <br> It can\'t be empty.</p>'
});
}else if(nimnData === "" ){
$.dialog({
title: 'Nimn Data is not given',
content: '<p>OOPS!! You have missed to feed NIMN data</p>'
});
} else{
var schema = JSON.parse(schemaStr);
var newSchema = nimn.buildSchema(schema);
/* if($("#nimnDt").prop("checked")){
nimnDecoder.addDataHandler("date",function(val){
return nimnDateparser.parse(val,true,true,true)
},function(val){
return nimnDateparser.parseBack(val,true,true,true)
});
} */
var result = nimn.parse(newSchema, nimnData);
$('#txtJson').val(
JSON.stringify(result,null,4)
);
$("#lengthNimn")[0].innerText= nimnData.length;
$("#lengthJson")[0].innerText= JSON.stringify(result).length;
}
}catch(e){
$('#txtJson').val(e);
$("#lengthNimn")[0].innerText = "#"
$("#lengthJson")[0].innerText = "#"
}
});
$("#txtJson").on('input', function()
{
try{
if(this.value){
$('#lengthJson')[0].innerText = JSON.stringify(JSON.parse(this.value)).length; //This will fail until a proper json is entered
} else {
$('#lengthJson')[0].innerText = 0;
}
}catch(e){
$('#lengthJson')[0].innerText = "Invalid JSON"
}
});
$("#txtNimn").on('input', function()
{
$('#lengthNimn')[0].innerText = this.value.length;
if( !this.value ) {
$("#makeitreadable").addClass("disabled");
}
else $("#makeitreadable").removeClass("disabled");
});
$("#makeitreadable").click(function(){
var nimnData = $('#txtNimn').val();
nimnData = replaceAll(nimnData, nilchar , '@');
nimnData = replaceAll(nimnData, missingchar , '~');
nimnData = replaceAll(nimnData, nilPremitivechar , '!');
nimnData = replaceAll(nimnData, missingPremitivechar , '*');
nimnData = replaceAll(nimnData, emptychar , '#');
nimnData = replaceAll(nimnData, emptyPremitivechar , '$');
nimnData = replaceAll(nimnData, boundarychar , '|');
nimnData = replaceAll(nimnData, objStartchar , '{');
nimnData = replaceAll(nimnData, arrayStartchar , '[');
nimnData = replaceAll(nimnData, arrayEndchar , ']');
nimnData = replaceAll(nimnData, yeschar , 'Y');
nimnData = replaceAll(nimnData, nochar , 'N');
$.dialog({
title: 'Redable data',
content: '<p>' + nimnData + '</p>',
escapeKey: true
});
});
});
function replaceAll(str,replaceWhat,replaceTo){
var re = new RegExp(replaceWhat, 'g');
return str.replace(re,replaceTo);
}
var nilchar = String.fromCharCode(176)
var missingchar = String.fromCharCode(201)
var nilPremitivechar = String.fromCharCode(175)
var missingPremitivechar = String.fromCharCode(200)
var emptychar = String.fromCharCode(178)
var emptyPremitivechar = String.fromCharCode(177)
var boundarychar = String.fromCharCode(179)
var objStartchar = String.fromCharCode(198)
var arrayStartchar = String.fromCharCode(204)
var arrayEndchar = String.fromCharCode(185)
var yeschar = String.fromCharCode(181)
var nochar = String.fromCharCode(183)
</script>
</body>
</html>