-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbundle.js
123 lines (102 loc) · 3.05 KB
/
bundle.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
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
var format = require('json-nice');
var output = document.querySelector(".formatted");
document.body.addEventListener('paste', function(e){
try {
var data = e.clipboardData.getData('text/plain');
var json = JSON.parse(data);
var fmtJson = format(json);
output.textContent = fmtJson;
} catch (e) {
output.textContent = e;
}
});
},{"json-nice":2}],2:[function(require,module,exports){
function render (key, value, options, indent) {
var text = '', i;
indent = indent || 0;
if (Array.isArray(value)) {
for (i = 0; i < indent; i++) {
text += options.indent;
}
if (key !== null) {
text += "\"" + key + "\": ";
}
text += "[\n";
for (var i = 0; i < value.length; i++) {
text += render(null, value[i], options, indent + 1);
if (i < value.length - 1) {
text += ",";
}
text += "\n";
}
for (i = 0; i < indent; i++) {
text += options.indent;
}
text += "]";
} else if (value !== null && typeof value === 'object' && value.toString() === '[object Object]') {
for (i = 0; i < indent; i++) {
text += options.indent;
}
if (key !== null) {
text += "\"" + key + "\": ";
}
text += "{\n";
var keys = Object.keys(value);
for (var i = 0; i < keys.length; i++) {
text += render(keys[i], value[keys[i]], options, indent + 1);
if (i < keys.length - 1) {
text += ",";
}
text += "\n";
}
for (i = 0; i < indent; i++) {
text += options.indent;
}
text += "}";
} else if (typeof value === 'number' || typeof value === 'boolean') {
for (i = 0; i < indent; i++) {
text += options.indent;
}
if (key !== null) {
text += "\"" + key + "\": ";
}
if (typeof value === 'number') {
text += Number(value);
} else {
text += value ? 'true' : 'false';
}
text += "";
} else {
for (i = 0; i < indent; i++) {
text += options.indent;
}
if (key !== null) {
key = key.replace(/\"/g, "\\\"");
text += "\"" + key + "\": ";
}
if (value === null) {
text += "null";
} else if (value === undefined) {
text += "undefined";
} else {
value = value.replace(/\"/g, "\\\"");
text += '"' + value + '"';
}
text += "";
}
return text;
}
function format (obj, opt) {
var options = { indent: " " };
if (typeof obj === 'object') {
if (typeof opt === 'object') {
for (var i in opt) {
options[i] = opt[i];
}
}
return render(null, obj, options);
}
}
module.exports = exports = format;
},{}]},{},[1]);