├── README.md ├── codemirror ├── FileSaver.js ├── codemirror.css ├── codemirror.js ├── docs.css ├── javascript.js ├── json-lint.js ├── lint.css └── lint.js ├── codepretty ├── prettify.css └── prettify.js ├── font └── SourceSansPro-Regular.woff ├── index.html └── res ├── favicon.ico ├── icon-128.png ├── icon-180.png ├── json2.js ├── jsonlint.js ├── jsonmodel.js ├── jszip.js └── style.css /README.md: -------------------------------------------------------------------------------- 1 | # json2model 2 | a web tool that convert json to Object-c Model or Java bin. 3 | 4 | 5 | With this you will never need to write model files line by line, and just paste the json string to the web, you will get the model what you want. 6 | 7 | ###Object-c 8 | 9 | ![](http://notiimg.y500.me/57608ae847244e78fb6f8185c6e6f50a.png) 10 | 11 | 12 | ###JAVA 13 | ![](http://notiimg.y500.me/3da808647ba4a137266b88a54178f390.png) 14 | -------------------------------------------------------------------------------- /codemirror/FileSaver.js: -------------------------------------------------------------------------------- 1 | /*! FileSaver.js 2 | * A saveAs() FileSaver implementation. 3 | * 2014-01-24 4 | * 5 | * By Eli Grey, http://eligrey.com 6 | * License: X11/MIT 7 | * See LICENSE.md 8 | */ 9 | 10 | /*global self */ 11 | /*jslint bitwise: true, indent: 4, laxbreak: true, laxcomma: true, smarttabs: true, plusplus: true */ 12 | 13 | /*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */ 14 | 15 | var saveAs = saveAs 16 | // IE 10+ (native saveAs) 17 | || (typeof navigator !== "undefined" && 18 | navigator.msSaveOrOpenBlob && navigator.msSaveOrOpenBlob.bind(navigator)) 19 | // Everyone else 20 | || (function(view) { 21 | "use strict"; 22 | // IE <10 is explicitly unsupported 23 | if (typeof navigator !== "undefined" && 24 | /MSIE [1-9]\./.test(navigator.userAgent)) { 25 | return; 26 | } 27 | var 28 | doc = view.document 29 | // only get URL when necessary in case BlobBuilder.js hasn't overridden it yet 30 | , get_URL = function() { 31 | return view.URL || view.webkitURL || view; 32 | } 33 | , URL = view.URL || view.webkitURL || view 34 | , save_link = doc.createElementNS("http://www.w3.org/1999/xhtml", "a") 35 | , can_use_save_link = !view.externalHost && "download" in save_link 36 | , click = function(node) { 37 | var event = doc.createEvent("MouseEvents"); 38 | event.initMouseEvent( 39 | "click", true, false, view, 0, 0, 0, 0, 0 40 | , false, false, false, false, 0, null 41 | ); 42 | node.dispatchEvent(event); 43 | } 44 | , webkit_req_fs = view.webkitRequestFileSystem 45 | , req_fs = view.requestFileSystem || webkit_req_fs || view.mozRequestFileSystem 46 | , throw_outside = function(ex) { 47 | (view.setImmediate || view.setTimeout)(function() { 48 | throw ex; 49 | }, 0); 50 | } 51 | , force_saveable_type = "application/octet-stream" 52 | , fs_min_size = 0 53 | , deletion_queue = [] 54 | , process_deletion_queue = function() { 55 | var i = deletion_queue.length; 56 | while (i--) { 57 | var file = deletion_queue[i]; 58 | if (typeof file === "string") { // file is an object URL 59 | URL.revokeObjectURL(file); 60 | } else { // file is a File 61 | file.remove(); 62 | } 63 | } 64 | deletion_queue.length = 0; // clear queue 65 | } 66 | , dispatch = function(filesaver, event_types, event) { 67 | event_types = [].concat(event_types); 68 | var i = event_types.length; 69 | while (i--) { 70 | var listener = filesaver["on" + event_types[i]]; 71 | if (typeof listener === "function") { 72 | try { 73 | listener.call(filesaver, event || filesaver); 74 | } catch (ex) { 75 | throw_outside(ex); 76 | } 77 | } 78 | } 79 | } 80 | , FileSaver = function(blob, name) { 81 | // First try a.download, then web filesystem, then object URLs 82 | var 83 | filesaver = this 84 | , type = blob.type 85 | , blob_changed = false 86 | , object_url 87 | , target_view 88 | , get_object_url = function() { 89 | var object_url = get_URL().createObjectURL(blob); 90 | deletion_queue.push(object_url); 91 | return object_url; 92 | } 93 | , dispatch_all = function() { 94 | dispatch(filesaver, "writestart progress write writeend".split(" ")); 95 | } 96 | // on any filesys errors revert to saving with object URLs 97 | , fs_error = function() { 98 | // don't create more object URLs than needed 99 | if (blob_changed || !object_url) { 100 | object_url = get_object_url(blob); 101 | } 102 | if (target_view) { 103 | target_view.location.href = object_url; 104 | } else { 105 | window.open(object_url, "_blank"); 106 | } 107 | filesaver.readyState = filesaver.DONE; 108 | dispatch_all(); 109 | } 110 | , abortable = function(func) { 111 | return function() { 112 | if (filesaver.readyState !== filesaver.DONE) { 113 | return func.apply(this, arguments); 114 | } 115 | }; 116 | } 117 | , create_if_not_found = {create: true, exclusive: false} 118 | , slice 119 | ; 120 | filesaver.readyState = filesaver.INIT; 121 | if (!name) { 122 | name = "download"; 123 | } 124 | if (can_use_save_link) { 125 | object_url = get_object_url(blob); 126 | // FF for Android has a nasty garbage collection mechanism 127 | // that turns all objects that are not pure javascript into 'deadObject' 128 | // this means `doc` and `save_link` are unusable and need to be recreated 129 | // `view` is usable though: 130 | doc = view.document; 131 | save_link = doc.createElementNS("http://www.w3.org/1999/xhtml", "a"); 132 | save_link.href = object_url; 133 | save_link.download = name; 134 | var event = doc.createEvent("MouseEvents"); 135 | event.initMouseEvent( 136 | "click", true, false, view, 0, 0, 0, 0, 0 137 | , false, false, false, false, 0, null 138 | ); 139 | save_link.dispatchEvent(event); 140 | filesaver.readyState = filesaver.DONE; 141 | dispatch_all(); 142 | return; 143 | } 144 | // Object and web filesystem URLs have a problem saving in Google Chrome when 145 | // viewed in a tab, so I force save with application/octet-stream 146 | // http://code.google.com/p/chromium/issues/detail?id=91158 147 | if (view.chrome && type && type !== force_saveable_type) { 148 | slice = blob.slice || blob.webkitSlice; 149 | blob = slice.call(blob, 0, blob.size, force_saveable_type); 150 | blob_changed = true; 151 | } 152 | // Since I can't be sure that the guessed media type will trigger a download 153 | // in WebKit, I append .download to the filename. 154 | // https://bugs.webkit.org/show_bug.cgi?id=65440 155 | if (webkit_req_fs && name !== "download") { 156 | name += ".download"; 157 | } 158 | if (type === force_saveable_type || webkit_req_fs) { 159 | target_view = view; 160 | } 161 | if (!req_fs) { 162 | fs_error(); 163 | return; 164 | } 165 | fs_min_size += blob.size; 166 | req_fs(view.TEMPORARY, fs_min_size, abortable(function(fs) { 167 | fs.root.getDirectory("saved", create_if_not_found, abortable(function(dir) { 168 | var save = function() { 169 | dir.getFile(name, create_if_not_found, abortable(function(file) { 170 | file.createWriter(abortable(function(writer) { 171 | writer.onwriteend = function(event) { 172 | target_view.location.href = file.toURL(); 173 | deletion_queue.push(file); 174 | filesaver.readyState = filesaver.DONE; 175 | dispatch(filesaver, "writeend", event); 176 | }; 177 | writer.onerror = function() { 178 | var error = writer.error; 179 | if (error.code !== error.ABORT_ERR) { 180 | fs_error(); 181 | } 182 | }; 183 | "writestart progress write abort".split(" ").forEach(function(event) { 184 | writer["on" + event] = filesaver["on" + event]; 185 | }); 186 | writer.write(blob); 187 | filesaver.abort = function() { 188 | writer.abort(); 189 | filesaver.readyState = filesaver.DONE; 190 | }; 191 | filesaver.readyState = filesaver.WRITING; 192 | }), fs_error); 193 | }), fs_error); 194 | }; 195 | dir.getFile(name, {create: false}, abortable(function(file) { 196 | // delete file if it already exists 197 | file.remove(); 198 | save(); 199 | }), abortable(function(ex) { 200 | if (ex.code === ex.NOT_FOUND_ERR) { 201 | save(); 202 | } else { 203 | fs_error(); 204 | } 205 | })); 206 | }), fs_error); 207 | }), fs_error); 208 | } 209 | , FS_proto = FileSaver.prototype 210 | , saveAs = function(blob, name) { 211 | return new FileSaver(blob, name); 212 | } 213 | ; 214 | FS_proto.abort = function() { 215 | var filesaver = this; 216 | filesaver.readyState = filesaver.DONE; 217 | dispatch(filesaver, "abort"); 218 | }; 219 | FS_proto.readyState = FS_proto.INIT = 0; 220 | FS_proto.WRITING = 1; 221 | FS_proto.DONE = 2; 222 | 223 | FS_proto.error = 224 | FS_proto.onwritestart = 225 | FS_proto.onprogress = 226 | FS_proto.onwrite = 227 | FS_proto.onabort = 228 | FS_proto.onerror = 229 | FS_proto.onwriteend = 230 | null; 231 | 232 | view.addEventListener("unload", process_deletion_queue, false); 233 | saveAs.unload = function() { 234 | process_deletion_queue(); 235 | view.removeEventListener("unload", process_deletion_queue, false); 236 | }; 237 | return saveAs; 238 | }( 239 | typeof self !== "undefined" && self 240 | || typeof window !== "undefined" && window 241 | || this.content 242 | )); 243 | // `self` is undefined in Firefox for Android content script context 244 | // while `this` is nsIContentFrameMessageManager 245 | // with an attribute `content` that corresponds to the window 246 | 247 | if (typeof module !== "undefined") module.exports = saveAs; 248 | -------------------------------------------------------------------------------- /codemirror/codemirror.css: -------------------------------------------------------------------------------- 1 | /* BASICS */ 2 | 3 | .CodeMirror { 4 | /* Set height, width, borders, and global font properties here */ 5 | font-family: monospace; 6 | height: 300px; 7 | color: black; 8 | direction: ltr; 9 | border: 1px solid #e1e1e1; 10 | } 11 | 12 | /* PADDING */ 13 | 14 | .CodeMirror-lines { 15 | padding: 4px 0; /* Vertical padding around content */ 16 | } 17 | .CodeMirror pre { 18 | padding: 0 4px; /* Horizontal padding of content */ 19 | } 20 | 21 | .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler { 22 | background-color: white; /* The little square between H and V scrollbars */ 23 | } 24 | 25 | /* GUTTER */ 26 | 27 | .CodeMirror-gutters { 28 | border-right: 1px solid #ddd; 29 | background-color: #f7f7f7; 30 | white-space: nowrap; 31 | } 32 | .CodeMirror-linenumbers {} 33 | .CodeMirror-linenumber { 34 | padding: 0 3px 0 5px; 35 | min-width: 20px; 36 | text-align: right; 37 | color: #999; 38 | white-space: nowrap; 39 | } 40 | 41 | .CodeMirror-guttermarker { color: black; } 42 | .CodeMirror-guttermarker-subtle { color: #999; } 43 | 44 | /* CURSOR */ 45 | 46 | .CodeMirror-cursor { 47 | border-left: 1px solid black; 48 | border-right: none; 49 | width: 0; 50 | } 51 | /* Shown when moving in bi-directional text */ 52 | .CodeMirror div.CodeMirror-secondarycursor { 53 | border-left: 1px solid silver; 54 | } 55 | .cm-fat-cursor .CodeMirror-cursor { 56 | width: auto; 57 | border: 0 !important; 58 | background: #7e7; 59 | } 60 | .cm-fat-cursor div.CodeMirror-cursors { 61 | z-index: 1; 62 | } 63 | .cm-fat-cursor-mark { 64 | background-color: rgba(20, 255, 20, 0.5); 65 | -webkit-animation: blink 1.06s steps(1) infinite; 66 | -moz-animation: blink 1.06s steps(1) infinite; 67 | animation: blink 1.06s steps(1) infinite; 68 | } 69 | .cm-animate-fat-cursor { 70 | width: auto; 71 | border: 0; 72 | -webkit-animation: blink 1.06s steps(1) infinite; 73 | -moz-animation: blink 1.06s steps(1) infinite; 74 | animation: blink 1.06s steps(1) infinite; 75 | background-color: #7e7; 76 | } 77 | @-moz-keyframes blink { 78 | 0% {} 79 | 50% { background-color: transparent; } 80 | 100% {} 81 | } 82 | @-webkit-keyframes blink { 83 | 0% {} 84 | 50% { background-color: transparent; } 85 | 100% {} 86 | } 87 | @keyframes blink { 88 | 0% {} 89 | 50% { background-color: transparent; } 90 | 100% {} 91 | } 92 | 93 | /* Can style cursor different in overwrite (non-insert) mode */ 94 | .CodeMirror-overwrite .CodeMirror-cursor {} 95 | 96 | .cm-tab { display: inline-block; text-decoration: inherit; } 97 | 98 | .CodeMirror-rulers { 99 | position: absolute; 100 | left: 0; right: 0; top: -50px; bottom: -20px; 101 | overflow: hidden; 102 | } 103 | .CodeMirror-ruler { 104 | border-left: 1px solid #ccc; 105 | top: 0; bottom: 0; 106 | position: absolute; 107 | } 108 | 109 | /* DEFAULT THEME */ 110 | 111 | .cm-s-default .cm-header {color: blue;} 112 | .cm-s-default .cm-quote {color: #090;} 113 | .cm-negative {color: #d44;} 114 | .cm-positive {color: #292;} 115 | .cm-header, .cm-strong {font-weight: bold;} 116 | .cm-em {font-style: italic;} 117 | .cm-link {text-decoration: underline;} 118 | .cm-strikethrough {text-decoration: line-through;} 119 | 120 | .cm-s-default .cm-keyword {color: #708;} 121 | .cm-s-default .cm-atom {color: #219;} 122 | .cm-s-default .cm-number {color: #164;} 123 | .cm-s-default .cm-def {color: #00f;} 124 | .cm-s-default .cm-variable, 125 | .cm-s-default .cm-punctuation, 126 | .cm-s-default .cm-property, 127 | .cm-s-default .cm-operator {} 128 | .cm-s-default .cm-variable-2 {color: #05a;} 129 | .cm-s-default .cm-variable-3, .cm-s-default .cm-type {color: #085;} 130 | .cm-s-default .cm-comment {color: #a50;} 131 | .cm-s-default .cm-string {color: #a11;} 132 | .cm-s-default .cm-string-2 {color: #f50;} 133 | .cm-s-default .cm-meta {color: #555;} 134 | .cm-s-default .cm-qualifier {color: #555;} 135 | .cm-s-default .cm-builtin {color: #30a;} 136 | .cm-s-default .cm-bracket {color: #997;} 137 | .cm-s-default .cm-tag {color: #170;} 138 | .cm-s-default .cm-attribute {color: #00c;} 139 | .cm-s-default .cm-hr {color: #999;} 140 | .cm-s-default .cm-link {color: #00c;} 141 | 142 | .cm-s-default .cm-error {color: #f00;} 143 | .cm-invalidchar {color: #f00;} 144 | 145 | .CodeMirror-composing { border-bottom: 2px solid; } 146 | 147 | /* Default styles for common addons */ 148 | 149 | div.CodeMirror span.CodeMirror-matchingbracket {color: #0f0;} 150 | div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;} 151 | .CodeMirror-matchingtag { background: rgba(255, 150, 0, .3); } 152 | .CodeMirror-activeline-background {background: #e8f2ff;} 153 | 154 | /* STOP */ 155 | 156 | /* The rest of this file contains styles related to the mechanics of 157 | the editor. You probably shouldn't touch them. */ 158 | 159 | .CodeMirror { 160 | position: relative; 161 | overflow: hidden; 162 | background: white; 163 | border: 1px solid #e1e1e1; 164 | } 165 | 166 | .CodeMirror-scroll { 167 | overflow: scroll !important; /* Things will break if this is overridden */ 168 | /* 30px is the magic margin used to hide the element's real scrollbars */ 169 | /* See overflow: hidden in .CodeMirror */ 170 | margin-bottom: -30px; margin-right: -30px; 171 | padding-bottom: 30px; 172 | height: 100%; 173 | outline: none; /* Prevent dragging from highlighting the element */ 174 | position: relative; 175 | } 176 | .CodeMirror-sizer { 177 | position: relative; 178 | border-right: 30px solid transparent; 179 | } 180 | 181 | /* The fake, visible scrollbars. Used to force redraw during scrolling 182 | before actual scrolling happens, thus preventing shaking and 183 | flickering artifacts. */ 184 | .CodeMirror-vscrollbar, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler { 185 | position: absolute; 186 | z-index: 6; 187 | display: none; 188 | } 189 | .CodeMirror-vscrollbar { 190 | right: 0; top: 0; 191 | overflow-x: hidden; 192 | overflow-y: scroll; 193 | } 194 | .CodeMirror-hscrollbar { 195 | bottom: 0; left: 0; 196 | overflow-y: hidden; 197 | overflow-x: scroll; 198 | } 199 | .CodeMirror-scrollbar-filler { 200 | right: 0; bottom: 0; 201 | } 202 | .CodeMirror-gutter-filler { 203 | left: 0; bottom: 0; 204 | } 205 | 206 | .CodeMirror-gutters { 207 | position: absolute; left: 0; top: 0; 208 | min-height: 100%; 209 | z-index: 3; 210 | } 211 | .CodeMirror-gutter { 212 | white-space: normal; 213 | height: 100%; 214 | display: inline-block; 215 | vertical-align: top; 216 | margin-bottom: -30px; 217 | } 218 | .CodeMirror-gutter-wrapper { 219 | position: absolute; 220 | z-index: 4; 221 | background: none !important; 222 | border: none !important; 223 | } 224 | .CodeMirror-gutter-background { 225 | position: absolute; 226 | top: 0; bottom: 0; 227 | z-index: 4; 228 | } 229 | .CodeMirror-gutter-elt { 230 | position: absolute; 231 | cursor: default; 232 | z-index: 4; 233 | } 234 | .CodeMirror-gutter-wrapper ::selection { background-color: transparent } 235 | .CodeMirror-gutter-wrapper ::-moz-selection { background-color: transparent } 236 | 237 | .CodeMirror-lines { 238 | cursor: text; 239 | min-height: 1px; /* prevents collapsing before first draw */ 240 | } 241 | .CodeMirror pre { 242 | /* Reset some styles that the rest of the page might have set */ 243 | -moz-border-radius: 0; -webkit-border-radius: 0; border-radius: 0; 244 | border-width: 0; 245 | background: transparent; 246 | font-family: inherit; 247 | font-size: inherit; 248 | margin: 0; 249 | white-space: pre; 250 | word-wrap: normal; 251 | line-height: inherit; 252 | color: inherit; 253 | z-index: 2; 254 | position: relative; 255 | overflow: visible; 256 | -webkit-tap-highlight-color: transparent; 257 | -webkit-font-variant-ligatures: contextual; 258 | font-variant-ligatures: contextual; 259 | } 260 | .CodeMirror-wrap pre { 261 | word-wrap: break-word; 262 | white-space: pre-wrap; 263 | word-break: normal; 264 | } 265 | 266 | .CodeMirror-linebackground { 267 | position: absolute; 268 | left: 0; right: 0; top: 0; bottom: 0; 269 | z-index: 0; 270 | } 271 | 272 | .CodeMirror-linewidget { 273 | position: relative; 274 | z-index: 2; 275 | overflow: auto; 276 | } 277 | 278 | .CodeMirror-widget {} 279 | 280 | .CodeMirror-rtl pre { direction: rtl; } 281 | 282 | .CodeMirror-code { 283 | outline: none; 284 | } 285 | 286 | /* Force content-box sizing for the elements where we expect it */ 287 | .CodeMirror-scroll, 288 | .CodeMirror-sizer, 289 | .CodeMirror-gutter, 290 | .CodeMirror-gutters, 291 | .CodeMirror-linenumber { 292 | -moz-box-sizing: content-box; 293 | box-sizing: content-box; 294 | } 295 | 296 | .CodeMirror-measure { 297 | position: absolute; 298 | width: 100%; 299 | height: 0; 300 | overflow: hidden; 301 | visibility: hidden; 302 | } 303 | 304 | .CodeMirror-cursor { 305 | position: absolute; 306 | pointer-events: none; 307 | } 308 | .CodeMirror-measure pre { position: static; } 309 | 310 | div.CodeMirror-cursors { 311 | visibility: hidden; 312 | position: relative; 313 | z-index: 3; 314 | } 315 | div.CodeMirror-dragcursors { 316 | visibility: visible; 317 | } 318 | 319 | .CodeMirror-focused div.CodeMirror-cursors { 320 | visibility: visible; 321 | } 322 | 323 | .CodeMirror-selected { background: #d9d9d9; } 324 | .CodeMirror-focused .CodeMirror-selected { background: #d7d4f0; } 325 | .CodeMirror-crosshair { cursor: crosshair; } 326 | .CodeMirror-line::selection, .CodeMirror-line > span::selection, .CodeMirror-line > span > span::selection { background: #d7d4f0; } 327 | .CodeMirror-line::-moz-selection, .CodeMirror-line > span::-moz-selection, .CodeMirror-line > span > span::-moz-selection { background: #d7d4f0; } 328 | 329 | .cm-searching { 330 | background-color: #ffa; 331 | background-color: rgba(255, 255, 0, .4); 332 | } 333 | 334 | /* Used to force a border model for a node */ 335 | .cm-force-border { padding-right: .1px; } 336 | 337 | @media print { 338 | /* Hide the cursor when printing */ 339 | .CodeMirror div.CodeMirror-cursors { 340 | visibility: hidden; 341 | } 342 | } 343 | 344 | /* See issue #2901 */ 345 | .cm-tab-wrap-hack:after { content: ''; } 346 | 347 | /* Help users use markselection to safely style text background */ 348 | span.CodeMirror-selectedtext { background: none; } 349 | -------------------------------------------------------------------------------- /codemirror/docs.css: -------------------------------------------------------------------------------- 1 | @font-face { 2 | font-family: 'Source Sans Pro'; 3 | font-style: normal; 4 | font-weight: 400; 5 | src: local('Source Sans Pro'), local('SourceSansPro-Regular'), url(../font/SourceSansPro-Regular.woff) format('woff'); 6 | } 7 | 8 | body, html { margin: 0; padding: 0; height: 100%; } 9 | section, article { display: block; padding: 0; } 10 | 11 | body { 12 | background: #f8f8f8; 13 | font-family: 'Source Sans Pro', Helvetica, Arial, sans-serif; 14 | line-height: 1.5; 15 | } 16 | 17 | p { margin-top: 0; } 18 | 19 | h2, h3, h1 { 20 | font-weight: normal; 21 | margin-bottom: .7em; 22 | } 23 | h1 { font-size: 140%; } 24 | h2 { font-size: 120%; } 25 | h3 { font-size: 110%; } 26 | article > h2:first-child, section:first-child > h2 { margin-top: 0; } 27 | 28 | #nav h1 { 29 | margin-right: 12px; 30 | margin-top: 0; 31 | margin-bottom: 2px; 32 | color: #d30707; 33 | letter-spacing: .5px; 34 | } 35 | 36 | a, a:visited, a:link, .quasilink { 37 | color: #333; 38 | text-decoration: none; 39 | } 40 | 41 | em { 42 | padding-right: 2px; 43 | } 44 | 45 | .quasilink { 46 | cursor: pointer; 47 | } 48 | 49 | article { 50 | max-width: 700px; 51 | margin: 0 0 0 160px; 52 | border-left: 2px solid #E30808; 53 | border-right: 1px solid #ddd; 54 | padding: 30px 50px 100px 50px; 55 | background: white; 56 | z-index: 2; 57 | position: relative; 58 | min-height: 100%; 59 | box-sizing: border-box; 60 | -moz-box-sizing: border-box; 61 | } 62 | 63 | #nav { 64 | position: fixed; 65 | padding-top: 30px; 66 | max-height: 100%; 67 | box-sizing: -moz-border-box; 68 | box-sizing: border-box; 69 | overflow-y: auto; 70 | left: 0; right: none; 71 | width: 160px; 72 | text-align: right; 73 | z-index: 1; 74 | } 75 | 76 | @media screen and (min-width: 1000px) { 77 | article { 78 | margin: 0 auto; 79 | } 80 | #nav { 81 | right: 50%; 82 | width: auto; 83 | border-right: 349px solid transparent; 84 | } 85 | } 86 | 87 | #nav ul { 88 | display: block; 89 | margin: 0; padding: 0; 90 | margin-bottom: 32px; 91 | } 92 | 93 | #nav li { 94 | display: block; 95 | margin-bottom: 4px; 96 | } 97 | 98 | #nav li ul { 99 | font-size: 80%; 100 | margin-bottom: 0; 101 | display: none; 102 | } 103 | 104 | #nav li.active ul { 105 | display: block; 106 | } 107 | 108 | #nav li li a { 109 | padding-right: 20px; 110 | display: inline-block; 111 | } 112 | 113 | #nav ul a { 114 | color: black; 115 | padding: 0 7px 1px 11px; 116 | } 117 | 118 | #nav ul a.active, #nav ul a:hover { 119 | border-bottom: 1px solid #E30808; 120 | margin-bottom: -1px; 121 | color: #E30808; 122 | } 123 | 124 | #logo { 125 | border: 0; 126 | margin-right: 12px; 127 | margin-bottom: 25px; 128 | } 129 | 130 | section { 131 | margin: 1.5em 0; 132 | } 133 | 134 | section.first { 135 | border: none; 136 | margin-top: 0; 137 | } 138 | 139 | #demo { 140 | position: relative; 141 | } 142 | 143 | #demolist { 144 | position: absolute; 145 | right: 5px; 146 | top: 5px; 147 | z-index: 25; 148 | } 149 | 150 | .yinyang { 151 | position: absolute; 152 | top: -10px; 153 | left: 0; right: 0; 154 | margin: auto; 155 | display: block; 156 | height: 120px; 157 | } 158 | 159 | .actions { 160 | margin: 1em 0 0; 161 | min-height: 100px; 162 | position: relative; 163 | } 164 | 165 | .actionspicture { 166 | pointer-events: none; 167 | position: absolute; 168 | height: 100px; 169 | top: 0; left: 0; right: 0; 170 | } 171 | 172 | .actionlink { 173 | pointer-events: auto; 174 | font-family: arial; 175 | font-size: 80%; 176 | font-weight: bold; 177 | position: absolute; 178 | top: 0; bottom: 0; 179 | line-height: 1; 180 | height: 1em; 181 | margin: auto; 182 | } 183 | 184 | .actionlink.download { 185 | color: white; 186 | right: 50%; 187 | margin-right: 13px; 188 | text-shadow: -1px 1px 3px #b00, -1px -1px 3px #b00, 1px 0px 3px #b00; 189 | } 190 | 191 | .actionlink.fund { 192 | color: #b00; 193 | left: 50%; 194 | margin-left: 15px; 195 | } 196 | 197 | .actionlink:hover { 198 | text-decoration: underline; 199 | } 200 | 201 | .actionlink a { 202 | color: inherit; 203 | } 204 | 205 | .actionsleft { 206 | float: left; 207 | } 208 | 209 | .actionsright { 210 | float: right; 211 | text-align: right; 212 | } 213 | 214 | @media screen and (max-width: 800px) { 215 | .actions { 216 | padding-top: 120px; 217 | } 218 | .actionsleft, .actionsright { 219 | float: none; 220 | text-align: left; 221 | margin-bottom: 1em; 222 | } 223 | } 224 | 225 | th { 226 | text-decoration: underline; 227 | font-weight: normal; 228 | text-align: left; 229 | } 230 | 231 | #features ul { 232 | list-style: none; 233 | margin: 0 0 1em; 234 | padding: 0 0 0 1.2em; 235 | } 236 | 237 | #features li:before { 238 | content: "-"; 239 | width: 1em; 240 | display: inline-block; 241 | padding: 0; 242 | margin: 0; 243 | margin-left: -1em; 244 | } 245 | 246 | .rel { 247 | margin-bottom: 0; 248 | } 249 | .rel-note { 250 | margin-top: 0; 251 | color: #555; 252 | } 253 | 254 | pre { 255 | padding-left: 15px; 256 | border-left: 2px solid #ddd; 257 | } 258 | 259 | code { 260 | padding: 0 2px; 261 | } 262 | 263 | strong { 264 | text-decoration: underline; 265 | font-weight: normal; 266 | } 267 | 268 | .field { 269 | border: 1px solid #A21313; 270 | } 271 | -------------------------------------------------------------------------------- /codemirror/javascript.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: http://codemirror.net/LICENSE 3 | 4 | (function(mod) { 5 | if (typeof exports == "object" && typeof module == "object") // CommonJS 6 | mod(require("../../lib/codemirror")); 7 | else if (typeof define == "function" && define.amd) // AMD 8 | define(["../../lib/codemirror"], mod); 9 | else // Plain browser env 10 | mod(CodeMirror); 11 | })(function(CodeMirror) { 12 | "use strict"; 13 | 14 | CodeMirror.defineMode("javascript", function(config, parserConfig) { 15 | var indentUnit = config.indentUnit; 16 | var statementIndent = parserConfig.statementIndent; 17 | var jsonldMode = parserConfig.jsonld; 18 | var jsonMode = parserConfig.json || jsonldMode; 19 | var isTS = parserConfig.typescript; 20 | var wordRE = parserConfig.wordCharacters || /[\w$\xa1-\uffff]/; 21 | 22 | // Tokenizer 23 | 24 | var keywords = function(){ 25 | function kw(type) {return {type: type, style: "keyword"};} 26 | var A = kw("keyword a"), B = kw("keyword b"), C = kw("keyword c"), D = kw("keyword d"); 27 | var operator = kw("operator"), atom = {type: "atom", style: "atom"}; 28 | 29 | var jsKeywords = { 30 | "if": kw("if"), "while": A, "with": A, "else": B, "do": B, "try": B, "finally": B, 31 | "return": D, "break": D, "continue": D, "new": kw("new"), "delete": C, "void": C, "throw": C, 32 | "debugger": kw("debugger"), "var": kw("var"), "const": kw("var"), "let": kw("var"), 33 | "function": kw("function"), "catch": kw("catch"), 34 | "for": kw("for"), "switch": kw("switch"), "case": kw("case"), "default": kw("default"), 35 | "in": operator, "typeof": operator, "instanceof": operator, 36 | "true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom, 37 | "this": kw("this"), "class": kw("class"), "super": kw("atom"), 38 | "yield": C, "export": kw("export"), "import": kw("import"), "extends": C, 39 | "await": C 40 | }; 41 | 42 | // Extend the 'normal' keywords with the TypeScript language extensions 43 | if (isTS) { 44 | var type = {type: "variable", style: "type"}; 45 | var tsKeywords = { 46 | // object-like things 47 | "interface": kw("class"), 48 | "implements": C, 49 | "namespace": C, 50 | "module": kw("module"), 51 | "enum": kw("module"), 52 | 53 | // scope modifiers 54 | "public": kw("modifier"), 55 | "private": kw("modifier"), 56 | "protected": kw("modifier"), 57 | "abstract": kw("modifier"), 58 | "readonly": kw("modifier"), 59 | 60 | // types 61 | "string": type, "number": type, "boolean": type, "any": type 62 | }; 63 | 64 | for (var attr in tsKeywords) { 65 | jsKeywords[attr] = tsKeywords[attr]; 66 | } 67 | } 68 | 69 | return jsKeywords; 70 | }(); 71 | 72 | var isOperatorChar = /[+\-*&%=<>!?|~^@]/; 73 | var isJsonldKeyword = /^@(context|id|value|language|type|container|list|set|reverse|index|base|vocab|graph)"/; 74 | 75 | function readRegexp(stream) { 76 | var escaped = false, next, inSet = false; 77 | while ((next = stream.next()) != null) { 78 | if (!escaped) { 79 | if (next == "/" && !inSet) return; 80 | if (next == "[") inSet = true; 81 | else if (inSet && next == "]") inSet = false; 82 | } 83 | escaped = !escaped && next == "\\"; 84 | } 85 | } 86 | 87 | // Used as scratch variables to communicate multiple values without 88 | // consing up tons of objects. 89 | var type, content; 90 | function ret(tp, style, cont) { 91 | type = tp; content = cont; 92 | return style; 93 | } 94 | function tokenBase(stream, state) { 95 | var ch = stream.next(); 96 | if (ch == '"' || ch == "'") { 97 | state.tokenize = tokenString(ch); 98 | return state.tokenize(stream, state); 99 | } else if (ch == "." && stream.match(/^\d+(?:[eE][+\-]?\d+)?/)) { 100 | return ret("number", "number"); 101 | } else if (ch == "." && stream.match("..")) { 102 | return ret("spread", "meta"); 103 | } else if (/[\[\]{}\(\),;\:\.]/.test(ch)) { 104 | return ret(ch); 105 | } else if (ch == "=" && stream.eat(">")) { 106 | return ret("=>", "operator"); 107 | } else if (ch == "0" && stream.eat(/x/i)) { 108 | stream.eatWhile(/[\da-f]/i); 109 | return ret("number", "number"); 110 | } else if (ch == "0" && stream.eat(/o/i)) { 111 | stream.eatWhile(/[0-7]/i); 112 | return ret("number", "number"); 113 | } else if (ch == "0" && stream.eat(/b/i)) { 114 | stream.eatWhile(/[01]/i); 115 | return ret("number", "number"); 116 | } else if (/\d/.test(ch)) { 117 | stream.match(/^\d*(?:\.\d*)?(?:[eE][+\-]?\d+)?/); 118 | return ret("number", "number"); 119 | } else if (ch == "/") { 120 | if (stream.eat("*")) { 121 | state.tokenize = tokenComment; 122 | return tokenComment(stream, state); 123 | } else if (stream.eat("/")) { 124 | stream.skipToEnd(); 125 | return ret("comment", "comment"); 126 | } else if (expressionAllowed(stream, state, 1)) { 127 | readRegexp(stream); 128 | stream.match(/^\b(([gimyu])(?![gimyu]*\2))+\b/); 129 | return ret("regexp", "string-2"); 130 | } else { 131 | stream.eat("="); 132 | return ret("operator", "operator", stream.current()); 133 | } 134 | } else if (ch == "`") { 135 | state.tokenize = tokenQuasi; 136 | return tokenQuasi(stream, state); 137 | } else if (ch == "#") { 138 | stream.skipToEnd(); 139 | return ret("error", "error"); 140 | } else if (isOperatorChar.test(ch)) { 141 | if (ch != ">" || !state.lexical || state.lexical.type != ">") { 142 | if (stream.eat("=")) { 143 | if (ch == "!" || ch == "=") stream.eat("=") 144 | } else if (/[<>*+\-]/.test(ch)) { 145 | stream.eat(ch) 146 | if (ch == ">") stream.eat(ch) 147 | } 148 | } 149 | return ret("operator", "operator", stream.current()); 150 | } else if (wordRE.test(ch)) { 151 | stream.eatWhile(wordRE); 152 | var word = stream.current() 153 | if (state.lastType != ".") { 154 | if (keywords.propertyIsEnumerable(word)) { 155 | var kw = keywords[word] 156 | return ret(kw.type, kw.style, word) 157 | } 158 | if (word == "async" && stream.match(/^\s*[\(\w]/, false)) 159 | return ret("async", "keyword", word) 160 | } 161 | return ret("variable", "variable", word) 162 | } 163 | } 164 | 165 | function tokenString(quote) { 166 | return function(stream, state) { 167 | var escaped = false, next; 168 | if (jsonldMode && stream.peek() == "@" && stream.match(isJsonldKeyword)){ 169 | state.tokenize = tokenBase; 170 | return ret("jsonld-keyword", "meta"); 171 | } 172 | while ((next = stream.next()) != null) { 173 | if (next == quote && !escaped) break; 174 | escaped = !escaped && next == "\\"; 175 | } 176 | if (!escaped) state.tokenize = tokenBase; 177 | return ret("string", "string"); 178 | }; 179 | } 180 | 181 | function tokenComment(stream, state) { 182 | var maybeEnd = false, ch; 183 | while (ch = stream.next()) { 184 | if (ch == "/" && maybeEnd) { 185 | state.tokenize = tokenBase; 186 | break; 187 | } 188 | maybeEnd = (ch == "*"); 189 | } 190 | return ret("comment", "comment"); 191 | } 192 | 193 | function tokenQuasi(stream, state) { 194 | var escaped = false, next; 195 | while ((next = stream.next()) != null) { 196 | if (!escaped && (next == "`" || next == "$" && stream.eat("{"))) { 197 | state.tokenize = tokenBase; 198 | break; 199 | } 200 | escaped = !escaped && next == "\\"; 201 | } 202 | return ret("quasi", "string-2", stream.current()); 203 | } 204 | 205 | var brackets = "([{}])"; 206 | // This is a crude lookahead trick to try and notice that we're 207 | // parsing the argument patterns for a fat-arrow function before we 208 | // actually hit the arrow token. It only works if the arrow is on 209 | // the same line as the arguments and there's no strange noise 210 | // (comments) in between. Fallback is to only notice when we hit the 211 | // arrow, and not declare the arguments as locals for the arrow 212 | // body. 213 | function findFatArrow(stream, state) { 214 | if (state.fatArrowAt) state.fatArrowAt = null; 215 | var arrow = stream.string.indexOf("=>", stream.start); 216 | if (arrow < 0) return; 217 | 218 | if (isTS) { // Try to skip TypeScript return type declarations after the arguments 219 | var m = /:\s*(?:\w+(?:<[^>]*>|\[\])?|\{[^}]*\})\s*$/.exec(stream.string.slice(stream.start, arrow)) 220 | if (m) arrow = m.index 221 | } 222 | 223 | var depth = 0, sawSomething = false; 224 | for (var pos = arrow - 1; pos >= 0; --pos) { 225 | var ch = stream.string.charAt(pos); 226 | var bracket = brackets.indexOf(ch); 227 | if (bracket >= 0 && bracket < 3) { 228 | if (!depth) { ++pos; break; } 229 | if (--depth == 0) { if (ch == "(") sawSomething = true; break; } 230 | } else if (bracket >= 3 && bracket < 6) { 231 | ++depth; 232 | } else if (wordRE.test(ch)) { 233 | sawSomething = true; 234 | } else if (/["'\/]/.test(ch)) { 235 | return; 236 | } else if (sawSomething && !depth) { 237 | ++pos; 238 | break; 239 | } 240 | } 241 | if (sawSomething && !depth) state.fatArrowAt = pos; 242 | } 243 | 244 | // Parser 245 | 246 | var atomicTypes = {"atom": true, "number": true, "variable": true, "string": true, "regexp": true, "this": true, "jsonld-keyword": true}; 247 | 248 | function JSLexical(indented, column, type, align, prev, info) { 249 | this.indented = indented; 250 | this.column = column; 251 | this.type = type; 252 | this.prev = prev; 253 | this.info = info; 254 | if (align != null) this.align = align; 255 | } 256 | 257 | function inScope(state, varname) { 258 | for (var v = state.localVars; v; v = v.next) 259 | if (v.name == varname) return true; 260 | for (var cx = state.context; cx; cx = cx.prev) { 261 | for (var v = cx.vars; v; v = v.next) 262 | if (v.name == varname) return true; 263 | } 264 | } 265 | 266 | function parseJS(state, style, type, content, stream) { 267 | var cc = state.cc; 268 | // Communicate our context to the combinators. 269 | // (Less wasteful than consing up a hundred closures on every call.) 270 | cx.state = state; cx.stream = stream; cx.marked = null, cx.cc = cc; cx.style = style; 271 | 272 | if (!state.lexical.hasOwnProperty("align")) 273 | state.lexical.align = true; 274 | 275 | while(true) { 276 | var combinator = cc.length ? cc.pop() : jsonMode ? expression : statement; 277 | if (combinator(type, content)) { 278 | while(cc.length && cc[cc.length - 1].lex) 279 | cc.pop()(); 280 | if (cx.marked) return cx.marked; 281 | if (type == "variable" && inScope(state, content)) return "variable-2"; 282 | return style; 283 | } 284 | } 285 | } 286 | 287 | // Combinator utils 288 | 289 | var cx = {state: null, column: null, marked: null, cc: null}; 290 | function pass() { 291 | for (var i = arguments.length - 1; i >= 0; i--) cx.cc.push(arguments[i]); 292 | } 293 | function cont() { 294 | pass.apply(null, arguments); 295 | return true; 296 | } 297 | function register(varname) { 298 | function inList(list) { 299 | for (var v = list; v; v = v.next) 300 | if (v.name == varname) return true; 301 | return false; 302 | } 303 | var state = cx.state; 304 | cx.marked = "def"; 305 | if (state.context) { 306 | if (inList(state.localVars)) return; 307 | state.localVars = {name: varname, next: state.localVars}; 308 | } else { 309 | if (inList(state.globalVars)) return; 310 | if (parserConfig.globalVars) 311 | state.globalVars = {name: varname, next: state.globalVars}; 312 | } 313 | } 314 | 315 | // Combinators 316 | 317 | var defaultVars = {name: "this", next: {name: "arguments"}}; 318 | function pushcontext() { 319 | cx.state.context = {prev: cx.state.context, vars: cx.state.localVars}; 320 | cx.state.localVars = defaultVars; 321 | } 322 | function popcontext() { 323 | cx.state.localVars = cx.state.context.vars; 324 | cx.state.context = cx.state.context.prev; 325 | } 326 | function pushlex(type, info) { 327 | var result = function() { 328 | var state = cx.state, indent = state.indented; 329 | if (state.lexical.type == "stat") indent = state.lexical.indented; 330 | else for (var outer = state.lexical; outer && outer.type == ")" && outer.align; outer = outer.prev) 331 | indent = outer.indented; 332 | state.lexical = new JSLexical(indent, cx.stream.column(), type, null, state.lexical, info); 333 | }; 334 | result.lex = true; 335 | return result; 336 | } 337 | function poplex() { 338 | var state = cx.state; 339 | if (state.lexical.prev) { 340 | if (state.lexical.type == ")") 341 | state.indented = state.lexical.indented; 342 | state.lexical = state.lexical.prev; 343 | } 344 | } 345 | poplex.lex = true; 346 | 347 | function expect(wanted) { 348 | function exp(type) { 349 | if (type == wanted) return cont(); 350 | else if (wanted == ";") return pass(); 351 | else return cont(exp); 352 | }; 353 | return exp; 354 | } 355 | 356 | function statement(type, value) { 357 | if (type == "var") return cont(pushlex("vardef", value.length), vardef, expect(";"), poplex); 358 | if (type == "keyword a") return cont(pushlex("form"), parenExpr, statement, poplex); 359 | if (type == "keyword b") return cont(pushlex("form"), statement, poplex); 360 | if (type == "keyword d") return cx.stream.match(/^\s*$/, false) ? cont() : cont(pushlex("stat"), maybeexpression, expect(";"), poplex); 361 | if (type == "debugger") return cont(expect(";")); 362 | if (type == "{") return cont(pushlex("}"), block, poplex); 363 | if (type == ";") return cont(); 364 | if (type == "if") { 365 | if (cx.state.lexical.info == "else" && cx.state.cc[cx.state.cc.length - 1] == poplex) 366 | cx.state.cc.pop()(); 367 | return cont(pushlex("form"), parenExpr, statement, poplex, maybeelse); 368 | } 369 | if (type == "function") return cont(functiondef); 370 | if (type == "for") return cont(pushlex("form"), forspec, statement, poplex); 371 | if (type == "variable") { 372 | if (isTS && value == "type") { 373 | cx.marked = "keyword" 374 | return cont(typeexpr, expect("operator"), typeexpr, expect(";")); 375 | } if (isTS && value == "declare") { 376 | cx.marked = "keyword" 377 | return cont(statement) 378 | } else { 379 | return cont(pushlex("stat"), maybelabel); 380 | } 381 | } 382 | if (type == "switch") return cont(pushlex("form"), parenExpr, expect("{"), pushlex("}", "switch"), 383 | block, poplex, poplex); 384 | if (type == "case") return cont(expression, expect(":")); 385 | if (type == "default") return cont(expect(":")); 386 | if (type == "catch") return cont(pushlex("form"), pushcontext, expect("("), funarg, expect(")"), 387 | statement, poplex, popcontext); 388 | if (type == "class") return cont(pushlex("form"), className, poplex); 389 | if (type == "export") return cont(pushlex("stat"), afterExport, poplex); 390 | if (type == "import") return cont(pushlex("stat"), afterImport, poplex); 391 | if (type == "module") return cont(pushlex("form"), pattern, expect("{"), pushlex("}"), block, poplex, poplex) 392 | if (type == "async") return cont(statement) 393 | if (value == "@") return cont(expression, statement) 394 | return pass(pushlex("stat"), expression, expect(";"), poplex); 395 | } 396 | function expression(type) { 397 | return expressionInner(type, false); 398 | } 399 | function expressionNoComma(type) { 400 | return expressionInner(type, true); 401 | } 402 | function parenExpr(type) { 403 | if (type != "(") return pass() 404 | return cont(pushlex(")"), expression, expect(")"), poplex) 405 | } 406 | function expressionInner(type, noComma) { 407 | if (cx.state.fatArrowAt == cx.stream.start) { 408 | var body = noComma ? arrowBodyNoComma : arrowBody; 409 | if (type == "(") return cont(pushcontext, pushlex(")"), commasep(funarg, ")"), poplex, expect("=>"), body, popcontext); 410 | else if (type == "variable") return pass(pushcontext, pattern, expect("=>"), body, popcontext); 411 | } 412 | 413 | var maybeop = noComma ? maybeoperatorNoComma : maybeoperatorComma; 414 | if (atomicTypes.hasOwnProperty(type)) return cont(maybeop); 415 | if (type == "function") return cont(functiondef, maybeop); 416 | if (type == "class") return cont(pushlex("form"), classExpression, poplex); 417 | if (type == "keyword c" || type == "async") return cont(noComma ? expressionNoComma : expression); 418 | if (type == "(") return cont(pushlex(")"), maybeexpression, expect(")"), poplex, maybeop); 419 | if (type == "operator" || type == "spread") return cont(noComma ? expressionNoComma : expression); 420 | if (type == "[") return cont(pushlex("]"), arrayLiteral, poplex, maybeop); 421 | if (type == "{") return contCommasep(objprop, "}", null, maybeop); 422 | if (type == "quasi") return pass(quasi, maybeop); 423 | if (type == "new") return cont(maybeTarget(noComma)); 424 | return cont(); 425 | } 426 | function maybeexpression(type) { 427 | if (type.match(/[;\}\)\],]/)) return pass(); 428 | return pass(expression); 429 | } 430 | 431 | function maybeoperatorComma(type, value) { 432 | if (type == ",") return cont(expression); 433 | return maybeoperatorNoComma(type, value, false); 434 | } 435 | function maybeoperatorNoComma(type, value, noComma) { 436 | var me = noComma == false ? maybeoperatorComma : maybeoperatorNoComma; 437 | var expr = noComma == false ? expression : expressionNoComma; 438 | if (type == "=>") return cont(pushcontext, noComma ? arrowBodyNoComma : arrowBody, popcontext); 439 | if (type == "operator") { 440 | if (/\+\+|--/.test(value) || isTS && value == "!") return cont(me); 441 | if (value == "?") return cont(expression, expect(":"), expr); 442 | return cont(expr); 443 | } 444 | if (type == "quasi") { return pass(quasi, me); } 445 | if (type == ";") return; 446 | if (type == "(") return contCommasep(expressionNoComma, ")", "call", me); 447 | if (type == ".") return cont(property, me); 448 | if (type == "[") return cont(pushlex("]"), maybeexpression, expect("]"), poplex, me); 449 | if (isTS && value == "as") { cx.marked = "keyword"; return cont(typeexpr, me) } 450 | if (type == "regexp") { 451 | cx.state.lastType = cx.marked = "operator" 452 | cx.stream.backUp(cx.stream.pos - cx.stream.start - 1) 453 | return cont(expr) 454 | } 455 | } 456 | function quasi(type, value) { 457 | if (type != "quasi") return pass(); 458 | if (value.slice(value.length - 2) != "${") return cont(quasi); 459 | return cont(expression, continueQuasi); 460 | } 461 | function continueQuasi(type) { 462 | if (type == "}") { 463 | cx.marked = "string-2"; 464 | cx.state.tokenize = tokenQuasi; 465 | return cont(quasi); 466 | } 467 | } 468 | function arrowBody(type) { 469 | findFatArrow(cx.stream, cx.state); 470 | return pass(type == "{" ? statement : expression); 471 | } 472 | function arrowBodyNoComma(type) { 473 | findFatArrow(cx.stream, cx.state); 474 | return pass(type == "{" ? statement : expressionNoComma); 475 | } 476 | function maybeTarget(noComma) { 477 | return function(type) { 478 | if (type == ".") return cont(noComma ? targetNoComma : target); 479 | else if (type == "variable" && isTS) return cont(maybeTypeArgs, noComma ? maybeoperatorNoComma : maybeoperatorComma) 480 | else return pass(noComma ? expressionNoComma : expression); 481 | }; 482 | } 483 | function target(_, value) { 484 | if (value == "target") { cx.marked = "keyword"; return cont(maybeoperatorComma); } 485 | } 486 | function targetNoComma(_, value) { 487 | if (value == "target") { cx.marked = "keyword"; return cont(maybeoperatorNoComma); } 488 | } 489 | function maybelabel(type) { 490 | if (type == ":") return cont(poplex, statement); 491 | return pass(maybeoperatorComma, expect(";"), poplex); 492 | } 493 | function property(type) { 494 | if (type == "variable") {cx.marked = "property"; return cont();} 495 | } 496 | function objprop(type, value) { 497 | if (type == "async") { 498 | cx.marked = "property"; 499 | return cont(objprop); 500 | } else if (type == "variable" || cx.style == "keyword") { 501 | cx.marked = "property"; 502 | if (value == "get" || value == "set") return cont(getterSetter); 503 | var m // Work around fat-arrow-detection complication for detecting typescript typed arrow params 504 | if (isTS && cx.state.fatArrowAt == cx.stream.start && (m = cx.stream.match(/^\s*:\s*/, false))) 505 | cx.state.fatArrowAt = cx.stream.pos + m[0].length 506 | return cont(afterprop); 507 | } else if (type == "number" || type == "string") { 508 | cx.marked = jsonldMode ? "property" : (cx.style + " property"); 509 | return cont(afterprop); 510 | } else if (type == "jsonld-keyword") { 511 | return cont(afterprop); 512 | } else if (type == "modifier") { 513 | return cont(objprop) 514 | } else if (type == "[") { 515 | return cont(expression, expect("]"), afterprop); 516 | } else if (type == "spread") { 517 | return cont(expression, afterprop); 518 | } else if (value == "*") { 519 | cx.marked = "keyword"; 520 | return cont(objprop); 521 | } else if (type == ":") { 522 | return pass(afterprop) 523 | } 524 | } 525 | function getterSetter(type) { 526 | if (type != "variable") return pass(afterprop); 527 | cx.marked = "property"; 528 | return cont(functiondef); 529 | } 530 | function afterprop(type) { 531 | if (type == ":") return cont(expressionNoComma); 532 | if (type == "(") return pass(functiondef); 533 | } 534 | function commasep(what, end, sep) { 535 | function proceed(type, value) { 536 | if (sep ? sep.indexOf(type) > -1 : type == ",") { 537 | var lex = cx.state.lexical; 538 | if (lex.info == "call") lex.pos = (lex.pos || 0) + 1; 539 | return cont(function(type, value) { 540 | if (type == end || value == end) return pass() 541 | return pass(what) 542 | }, proceed); 543 | } 544 | if (type == end || value == end) return cont(); 545 | return cont(expect(end)); 546 | } 547 | return function(type, value) { 548 | if (type == end || value == end) return cont(); 549 | return pass(what, proceed); 550 | }; 551 | } 552 | function contCommasep(what, end, info) { 553 | for (var i = 3; i < arguments.length; i++) 554 | cx.cc.push(arguments[i]); 555 | return cont(pushlex(end, info), commasep(what, end), poplex); 556 | } 557 | function block(type) { 558 | if (type == "}") return cont(); 559 | return pass(statement, block); 560 | } 561 | function maybetype(type, value) { 562 | if (isTS) { 563 | if (type == ":") return cont(typeexpr); 564 | if (value == "?") return cont(maybetype); 565 | } 566 | } 567 | function typeexpr(type, value) { 568 | if (type == "variable" || value == "void") { 569 | if (value == "keyof") { 570 | cx.marked = "keyword" 571 | return cont(typeexpr) 572 | } else { 573 | cx.marked = "type" 574 | return cont(afterType) 575 | } 576 | } 577 | if (type == "string" || type == "number" || type == "atom") return cont(afterType); 578 | if (type == "[") return cont(pushlex("]"), commasep(typeexpr, "]", ","), poplex, afterType) 579 | if (type == "{") return cont(pushlex("}"), commasep(typeprop, "}", ",;"), poplex, afterType) 580 | if (type == "(") return cont(commasep(typearg, ")"), maybeReturnType) 581 | } 582 | function maybeReturnType(type) { 583 | if (type == "=>") return cont(typeexpr) 584 | } 585 | function typeprop(type, value) { 586 | if (type == "variable" || cx.style == "keyword") { 587 | cx.marked = "property" 588 | return cont(typeprop) 589 | } else if (value == "?") { 590 | return cont(typeprop) 591 | } else if (type == ":") { 592 | return cont(typeexpr) 593 | } else if (type == "[") { 594 | return cont(expression, maybetype, expect("]"), typeprop) 595 | } 596 | } 597 | function typearg(type) { 598 | if (type == "variable") return cont(typearg) 599 | else if (type == ":") return cont(typeexpr) 600 | } 601 | function afterType(type, value) { 602 | if (value == "<") return cont(pushlex(">"), commasep(typeexpr, ">"), poplex, afterType) 603 | if (value == "|" || type == ".") return cont(typeexpr) 604 | if (type == "[") return cont(expect("]"), afterType) 605 | if (value == "extends") return cont(typeexpr) 606 | } 607 | function maybeTypeArgs(_, value) { 608 | if (value == "<") return cont(pushlex(">"), commasep(typeexpr, ">"), poplex, afterType) 609 | } 610 | function vardef() { 611 | return pass(pattern, maybetype, maybeAssign, vardefCont); 612 | } 613 | function pattern(type, value) { 614 | if (type == "modifier") return cont(pattern) 615 | if (type == "variable") { register(value); return cont(); } 616 | if (type == "spread") return cont(pattern); 617 | if (type == "[") return contCommasep(pattern, "]"); 618 | if (type == "{") return contCommasep(proppattern, "}"); 619 | } 620 | function proppattern(type, value) { 621 | if (type == "variable" && !cx.stream.match(/^\s*:/, false)) { 622 | register(value); 623 | return cont(maybeAssign); 624 | } 625 | if (type == "variable") cx.marked = "property"; 626 | if (type == "spread") return cont(pattern); 627 | if (type == "}") return pass(); 628 | return cont(expect(":"), pattern, maybeAssign); 629 | } 630 | function maybeAssign(_type, value) { 631 | if (value == "=") return cont(expressionNoComma); 632 | } 633 | function vardefCont(type) { 634 | if (type == ",") return cont(vardef); 635 | } 636 | function maybeelse(type, value) { 637 | if (type == "keyword b" && value == "else") return cont(pushlex("form", "else"), statement, poplex); 638 | } 639 | function forspec(type) { 640 | if (type == "(") return cont(pushlex(")"), forspec1, expect(")"), poplex); 641 | } 642 | function forspec1(type) { 643 | if (type == "var") return cont(vardef, expect(";"), forspec2); 644 | if (type == ";") return cont(forspec2); 645 | if (type == "variable") return cont(formaybeinof); 646 | return pass(expression, expect(";"), forspec2); 647 | } 648 | function formaybeinof(_type, value) { 649 | if (value == "in" || value == "of") { cx.marked = "keyword"; return cont(expression); } 650 | return cont(maybeoperatorComma, forspec2); 651 | } 652 | function forspec2(type, value) { 653 | if (type == ";") return cont(forspec3); 654 | if (value == "in" || value == "of") { cx.marked = "keyword"; return cont(expression); } 655 | return pass(expression, expect(";"), forspec3); 656 | } 657 | function forspec3(type) { 658 | if (type != ")") cont(expression); 659 | } 660 | function functiondef(type, value) { 661 | if (value == "*") {cx.marked = "keyword"; return cont(functiondef);} 662 | if (type == "variable") {register(value); return cont(functiondef);} 663 | if (type == "(") return cont(pushcontext, pushlex(")"), commasep(funarg, ")"), poplex, maybetype, statement, popcontext); 664 | if (isTS && value == "<") return cont(pushlex(">"), commasep(typeexpr, ">"), poplex, functiondef) 665 | } 666 | function funarg(type, value) { 667 | if (value == "@") cont(expression, funarg) 668 | if (type == "spread" || type == "modifier") return cont(funarg); 669 | return pass(pattern, maybetype, maybeAssign); 670 | } 671 | function classExpression(type, value) { 672 | // Class expressions may have an optional name. 673 | if (type == "variable") return className(type, value); 674 | return classNameAfter(type, value); 675 | } 676 | function className(type, value) { 677 | if (type == "variable") {register(value); return cont(classNameAfter);} 678 | } 679 | function classNameAfter(type, value) { 680 | if (value == "<") return cont(pushlex(">"), commasep(typeexpr, ">"), poplex, classNameAfter) 681 | if (value == "extends" || value == "implements" || (isTS && type == ",")) 682 | return cont(isTS ? typeexpr : expression, classNameAfter); 683 | if (type == "{") return cont(pushlex("}"), classBody, poplex); 684 | } 685 | function classBody(type, value) { 686 | if (type == "modifier" || type == "async" || 687 | (type == "variable" && 688 | (value == "static" || value == "get" || value == "set") && 689 | cx.stream.match(/^\s+[\w$\xa1-\uffff]/, false))) { 690 | cx.marked = "keyword"; 691 | return cont(classBody); 692 | } 693 | if (type == "variable" || cx.style == "keyword") { 694 | cx.marked = "property"; 695 | return cont(isTS ? classfield : functiondef, classBody); 696 | } 697 | if (type == "[") 698 | return cont(expression, expect("]"), isTS ? classfield : functiondef, classBody) 699 | if (value == "*") { 700 | cx.marked = "keyword"; 701 | return cont(classBody); 702 | } 703 | if (type == ";") return cont(classBody); 704 | if (type == "}") return cont(); 705 | if (value == "@") return cont(expression, classBody) 706 | } 707 | function classfield(type, value) { 708 | if (value == "?") return cont(classfield) 709 | if (type == ":") return cont(typeexpr, maybeAssign) 710 | if (value == "=") return cont(expressionNoComma) 711 | return pass(functiondef) 712 | } 713 | function afterExport(type, value) { 714 | if (value == "*") { cx.marked = "keyword"; return cont(maybeFrom, expect(";")); } 715 | if (value == "default") { cx.marked = "keyword"; return cont(expression, expect(";")); } 716 | if (type == "{") return cont(commasep(exportField, "}"), maybeFrom, expect(";")); 717 | return pass(statement); 718 | } 719 | function exportField(type, value) { 720 | if (value == "as") { cx.marked = "keyword"; return cont(expect("variable")); } 721 | if (type == "variable") return pass(expressionNoComma, exportField); 722 | } 723 | function afterImport(type) { 724 | if (type == "string") return cont(); 725 | return pass(importSpec, maybeMoreImports, maybeFrom); 726 | } 727 | function importSpec(type, value) { 728 | if (type == "{") return contCommasep(importSpec, "}"); 729 | if (type == "variable") register(value); 730 | if (value == "*") cx.marked = "keyword"; 731 | return cont(maybeAs); 732 | } 733 | function maybeMoreImports(type) { 734 | if (type == ",") return cont(importSpec, maybeMoreImports) 735 | } 736 | function maybeAs(_type, value) { 737 | if (value == "as") { cx.marked = "keyword"; return cont(importSpec); } 738 | } 739 | function maybeFrom(_type, value) { 740 | if (value == "from") { cx.marked = "keyword"; return cont(expression); } 741 | } 742 | function arrayLiteral(type) { 743 | if (type == "]") return cont(); 744 | return pass(commasep(expressionNoComma, "]")); 745 | } 746 | 747 | function isContinuedStatement(state, textAfter) { 748 | return state.lastType == "operator" || state.lastType == "," || 749 | isOperatorChar.test(textAfter.charAt(0)) || 750 | /[,.]/.test(textAfter.charAt(0)); 751 | } 752 | 753 | function expressionAllowed(stream, state, backUp) { 754 | return state.tokenize == tokenBase && 755 | /^(?:operator|sof|keyword [bcd]|case|new|export|default|spread|[\[{}\(,;:]|=>)$/.test(state.lastType) || 756 | (state.lastType == "quasi" && /\{\s*$/.test(stream.string.slice(0, stream.pos - (backUp || 0)))) 757 | } 758 | 759 | // Interface 760 | 761 | return { 762 | startState: function(basecolumn) { 763 | var state = { 764 | tokenize: tokenBase, 765 | lastType: "sof", 766 | cc: [], 767 | lexical: new JSLexical((basecolumn || 0) - indentUnit, 0, "block", false), 768 | localVars: parserConfig.localVars, 769 | context: parserConfig.localVars && {vars: parserConfig.localVars}, 770 | indented: basecolumn || 0 771 | }; 772 | if (parserConfig.globalVars && typeof parserConfig.globalVars == "object") 773 | state.globalVars = parserConfig.globalVars; 774 | return state; 775 | }, 776 | 777 | token: function(stream, state) { 778 | if (stream.sol()) { 779 | if (!state.lexical.hasOwnProperty("align")) 780 | state.lexical.align = false; 781 | state.indented = stream.indentation(); 782 | findFatArrow(stream, state); 783 | } 784 | if (state.tokenize != tokenComment && stream.eatSpace()) return null; 785 | var style = state.tokenize(stream, state); 786 | if (type == "comment") return style; 787 | state.lastType = type == "operator" && (content == "++" || content == "--") ? "incdec" : type; 788 | return parseJS(state, style, type, content, stream); 789 | }, 790 | 791 | indent: function(state, textAfter) { 792 | if (state.tokenize == tokenComment) return CodeMirror.Pass; 793 | if (state.tokenize != tokenBase) return 0; 794 | var firstChar = textAfter && textAfter.charAt(0), lexical = state.lexical, top 795 | // Kludge to prevent 'maybelse' from blocking lexical scope pops 796 | if (!/^\s*else\b/.test(textAfter)) for (var i = state.cc.length - 1; i >= 0; --i) { 797 | var c = state.cc[i]; 798 | if (c == poplex) lexical = lexical.prev; 799 | else if (c != maybeelse) break; 800 | } 801 | while ((lexical.type == "stat" || lexical.type == "form") && 802 | (firstChar == "}" || ((top = state.cc[state.cc.length - 1]) && 803 | (top == maybeoperatorComma || top == maybeoperatorNoComma) && 804 | !/^[,\.=+\-*:?[\(]/.test(textAfter)))) 805 | lexical = lexical.prev; 806 | if (statementIndent && lexical.type == ")" && lexical.prev.type == "stat") 807 | lexical = lexical.prev; 808 | var type = lexical.type, closing = firstChar == type; 809 | 810 | if (type == "vardef") return lexical.indented + (state.lastType == "operator" || state.lastType == "," ? lexical.info + 1 : 0); 811 | else if (type == "form" && firstChar == "{") return lexical.indented; 812 | else if (type == "form") return lexical.indented + indentUnit; 813 | else if (type == "stat") 814 | return lexical.indented + (isContinuedStatement(state, textAfter) ? statementIndent || indentUnit : 0); 815 | else if (lexical.info == "switch" && !closing && parserConfig.doubleIndentSwitch != false) 816 | return lexical.indented + (/^(?:case|default)\b/.test(textAfter) ? indentUnit : 2 * indentUnit); 817 | else if (lexical.align) return lexical.column + (closing ? 0 : 1); 818 | else return lexical.indented + (closing ? 0 : indentUnit); 819 | }, 820 | 821 | electricInput: /^\s*(?:case .*?:|default:|\{|\})$/, 822 | blockCommentStart: jsonMode ? null : "/*", 823 | blockCommentEnd: jsonMode ? null : "*/", 824 | blockCommentContinue: jsonMode ? null : " * ", 825 | lineComment: jsonMode ? null : "//", 826 | fold: "brace", 827 | closeBrackets: "()[]{}''\"\"``", 828 | 829 | helperType: jsonMode ? "json" : "javascript", 830 | jsonldMode: jsonldMode, 831 | jsonMode: jsonMode, 832 | 833 | expressionAllowed: expressionAllowed, 834 | 835 | skipExpression: function(state) { 836 | var top = state.cc[state.cc.length - 1] 837 | if (top == expression || top == expressionNoComma) state.cc.pop() 838 | } 839 | }; 840 | }); 841 | 842 | CodeMirror.registerHelper("wordChars", "javascript", /[\w$]/); 843 | 844 | CodeMirror.defineMIME("text/javascript", "javascript"); 845 | CodeMirror.defineMIME("text/ecmascript", "javascript"); 846 | CodeMirror.defineMIME("application/javascript", "javascript"); 847 | CodeMirror.defineMIME("application/x-javascript", "javascript"); 848 | CodeMirror.defineMIME("application/ecmascript", "javascript"); 849 | CodeMirror.defineMIME("application/json", {name: "javascript", json: true}); 850 | CodeMirror.defineMIME("application/x-json", {name: "javascript", json: true}); 851 | CodeMirror.defineMIME("application/ld+json", {name: "javascript", jsonld: true}); 852 | CodeMirror.defineMIME("text/typescript", { name: "javascript", typescript: true }); 853 | CodeMirror.defineMIME("application/typescript", { name: "javascript", typescript: true }); 854 | 855 | }); 856 | -------------------------------------------------------------------------------- /codemirror/json-lint.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: http://codemirror.net/LICENSE 3 | 4 | // Depends on jsonlint.js from https://github.com/zaach/jsonlint 5 | 6 | // declare global: jsonlint 7 | 8 | (function(mod) { 9 | if (typeof exports == "object" && typeof module == "object") // CommonJS 10 | mod(require("../../lib/codemirror")); 11 | else if (typeof define == "function" && define.amd) // AMD 12 | define(["../../lib/codemirror"], mod); 13 | else // Plain browser env 14 | mod(CodeMirror); 15 | })(function(CodeMirror) { 16 | "use strict"; 17 | 18 | CodeMirror.registerHelper("lint", "json", function(text) { 19 | var found = []; 20 | if (!window.jsonlint) { 21 | if (window.console) { 22 | window.console.error("Error: window.jsonlint not defined, CodeMirror JSON linting cannot run."); 23 | } 24 | return found; 25 | } 26 | jsonlint.parseError = function(str, hash) { 27 | var loc = hash.loc; 28 | found.push({from: CodeMirror.Pos(loc.first_line - 1, loc.first_column), 29 | to: CodeMirror.Pos(loc.last_line - 1, loc.last_column), 30 | message: str}); 31 | }; 32 | try { 33 | var tmpresult = jsonlint.parse(text); 34 | if (tmpresult){ 35 | text = JSON.stringify(tmpresult, null, " "); 36 | } 37 | jsonlint.parse(text); } 38 | catch(e) {} 39 | return found; 40 | }); 41 | 42 | }); 43 | -------------------------------------------------------------------------------- /codemirror/lint.css: -------------------------------------------------------------------------------- 1 | /* The lint marker gutter */ 2 | .CodeMirror-lint-markers { 3 | width: 16px; 4 | } 5 | 6 | .CodeMirror-lint-tooltip { 7 | background-color: #ffd; 8 | border: 1px solid black; 9 | border-radius: 4px 4px 4px 4px; 10 | color: black; 11 | font-family: monospace; 12 | font-size: 10pt; 13 | overflow: hidden; 14 | padding: 2px 5px; 15 | position: fixed; 16 | white-space: pre; 17 | white-space: pre-wrap; 18 | z-index: 100; 19 | max-width: 600px; 20 | opacity: 0; 21 | transition: opacity .4s; 22 | -moz-transition: opacity .4s; 23 | -webkit-transition: opacity .4s; 24 | -o-transition: opacity .4s; 25 | -ms-transition: opacity .4s; 26 | } 27 | 28 | .CodeMirror-lint-mark-error, .CodeMirror-lint-mark-warning { 29 | background-position: left bottom; 30 | background-repeat: repeat-x; 31 | } 32 | 33 | .CodeMirror-lint-mark-error { 34 | background-image: 35 | url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAADCAYAAAC09K7GAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sJDw4cOCW1/KIAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAHElEQVQI12NggIL/DAz/GdA5/xkY/qPKMDAwAADLZwf5rvm+LQAAAABJRU5ErkJggg==") 36 | ; 37 | } 38 | 39 | .CodeMirror-lint-mark-warning { 40 | background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAADCAYAAAC09K7GAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sJFhQXEbhTg7YAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAMklEQVQI12NkgIIvJ3QXMjAwdDN+OaEbysDA4MPAwNDNwMCwiOHLCd1zX07o6kBVGQEAKBANtobskNMAAAAASUVORK5CYII="); 41 | } 42 | 43 | .CodeMirror-lint-marker-error, .CodeMirror-lint-marker-warning { 44 | background-position: center center; 45 | background-repeat: no-repeat; 46 | cursor: pointer; 47 | display: inline-block; 48 | height: 16px; 49 | width: 16px; 50 | vertical-align: middle; 51 | position: relative; 52 | } 53 | 54 | .CodeMirror-lint-message-error, .CodeMirror-lint-message-warning { 55 | padding-left: 18px; 56 | background-position: top left; 57 | background-repeat: no-repeat; 58 | } 59 | 60 | .CodeMirror-lint-marker-error, .CodeMirror-lint-message-error { 61 | background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAHlBMVEW7AAC7AACxAAC7AAC7AAAAAAC4AAC5AAD///+7AAAUdclpAAAABnRSTlMXnORSiwCK0ZKSAAAATUlEQVR42mWPOQ7AQAgDuQLx/z8csYRmPRIFIwRGnosRrpamvkKi0FTIiMASR3hhKW+hAN6/tIWhu9PDWiTGNEkTtIOucA5Oyr9ckPgAWm0GPBog6v4AAAAASUVORK5CYII="); 62 | } 63 | 64 | .CodeMirror-lint-marker-warning, .CodeMirror-lint-message-warning { 65 | background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAANlBMVEX/uwDvrwD/uwD/uwD/uwD/uwD/uwD/uwD/uwD6twD/uwAAAADurwD2tQD7uAD+ugAAAAD/uwDhmeTRAAAADHRSTlMJ8mN1EYcbmiixgACm7WbuAAAAVklEQVR42n3PUQqAIBBFUU1LLc3u/jdbOJoW1P08DA9Gba8+YWJ6gNJoNYIBzAA2chBth5kLmG9YUoG0NHAUwFXwO9LuBQL1giCQb8gC9Oro2vp5rncCIY8L8uEx5ZkAAAAASUVORK5CYII="); 66 | } 67 | 68 | .CodeMirror-lint-marker-multiple { 69 | background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAcAAAAHCAMAAADzjKfhAAAACVBMVEUAAAAAAAC/v7914kyHAAAAAXRSTlMAQObYZgAAACNJREFUeNo1ioEJAAAIwmz/H90iFFSGJgFMe3gaLZ0od+9/AQZ0ADosbYraAAAAAElFTkSuQmCC"); 70 | background-repeat: no-repeat; 71 | background-position: right bottom; 72 | width: 100%; height: 100%; 73 | } 74 | -------------------------------------------------------------------------------- /codemirror/lint.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: http://codemirror.net/LICENSE 3 | 4 | (function(mod) { 5 | if (typeof exports == "object" && typeof module == "object") // CommonJS 6 | mod(require("../../lib/codemirror")); 7 | else if (typeof define == "function" && define.amd) // AMD 8 | define(["../../lib/codemirror"], mod); 9 | else // Plain browser env 10 | mod(CodeMirror); 11 | })(function(CodeMirror) { 12 | "use strict"; 13 | var GUTTER_ID = "CodeMirror-lint-markers"; 14 | 15 | function showTooltip(e, content) { 16 | var tt = document.createElement("div"); 17 | tt.className = "CodeMirror-lint-tooltip"; 18 | tt.appendChild(content.cloneNode(true)); 19 | document.body.appendChild(tt); 20 | 21 | function position(e) { 22 | if (!tt.parentNode) return CodeMirror.off(document, "mousemove", position); 23 | tt.style.top = Math.max(0, e.clientY - tt.offsetHeight - 5) + "px"; 24 | tt.style.left = (e.clientX + 5) + "px"; 25 | } 26 | CodeMirror.on(document, "mousemove", position); 27 | position(e); 28 | if (tt.style.opacity != null) tt.style.opacity = 1; 29 | return tt; 30 | } 31 | function rm(elt) { 32 | if (elt.parentNode) elt.parentNode.removeChild(elt); 33 | } 34 | function hideTooltip(tt) { 35 | if (!tt.parentNode) return; 36 | if (tt.style.opacity == null) rm(tt); 37 | tt.style.opacity = 0; 38 | setTimeout(function() { rm(tt); }, 600); 39 | } 40 | 41 | function showTooltipFor(e, content, node) { 42 | var tooltip = showTooltip(e, content); 43 | function hide() { 44 | CodeMirror.off(node, "mouseout", hide); 45 | if (tooltip) { hideTooltip(tooltip); tooltip = null; } 46 | } 47 | var poll = setInterval(function() { 48 | if (tooltip) for (var n = node;; n = n.parentNode) { 49 | if (n && n.nodeType == 11) n = n.host; 50 | if (n == document.body) return; 51 | if (!n) { hide(); break; } 52 | } 53 | if (!tooltip) return clearInterval(poll); 54 | }, 400); 55 | CodeMirror.on(node, "mouseout", hide); 56 | } 57 | 58 | function LintState(cm, options, hasGutter) { 59 | this.marked = []; 60 | this.options = options; 61 | this.timeout = null; 62 | this.hasGutter = hasGutter; 63 | this.onMouseOver = function(e) { onMouseOver(cm, e); }; 64 | this.waitingFor = 0 65 | } 66 | 67 | function parseOptions(_cm, options) { 68 | if (options instanceof Function) return {getAnnotations: options}; 69 | if (!options || options === true) options = {}; 70 | return options; 71 | } 72 | 73 | function clearMarks(cm) { 74 | var state = cm.state.lint; 75 | if (state.hasGutter) cm.clearGutter(GUTTER_ID); 76 | for (var i = 0; i < state.marked.length; ++i) 77 | state.marked[i].clear(); 78 | state.marked.length = 0; 79 | } 80 | 81 | function makeMarker(labels, severity, multiple, tooltips) { 82 | var marker = document.createElement("div"), inner = marker; 83 | marker.className = "CodeMirror-lint-marker-" + severity; 84 | if (multiple) { 85 | inner = marker.appendChild(document.createElement("div")); 86 | inner.className = "CodeMirror-lint-marker-multiple"; 87 | } 88 | 89 | if (tooltips != false) CodeMirror.on(inner, "mouseover", function(e) { 90 | showTooltipFor(e, labels, inner); 91 | }); 92 | 93 | return marker; 94 | } 95 | 96 | function getMaxSeverity(a, b) { 97 | if (a == "error") return a; 98 | else return b; 99 | } 100 | 101 | function groupByLine(annotations) { 102 | var lines = []; 103 | for (var i = 0; i < annotations.length; ++i) { 104 | var ann = annotations[i], line = ann.from.line; 105 | (lines[line] || (lines[line] = [])).push(ann); 106 | } 107 | return lines; 108 | } 109 | 110 | function annotationTooltip(ann) { 111 | var severity = ann.severity; 112 | if (!severity) severity = "error"; 113 | var tip = document.createElement("div"); 114 | tip.className = "CodeMirror-lint-message-" + severity; 115 | if (typeof ann.messageHTML != 'undefined') { 116 | tip.innerHTML = ann.messageHTML; 117 | } else { 118 | tip.appendChild(document.createTextNode(ann.message)); 119 | } 120 | return tip; 121 | } 122 | 123 | function lintAsync(cm, getAnnotations, passOptions) { 124 | var state = cm.state.lint 125 | var id = ++state.waitingFor 126 | function abort() { 127 | id = -1 128 | cm.off("change", abort) 129 | } 130 | cm.on("change", abort) 131 | getAnnotations(cm.getValue(), function(annotations, arg2) { 132 | cm.off("change", abort) 133 | if (state.waitingFor != id) return 134 | if (arg2 && annotations instanceof CodeMirror) annotations = arg2 135 | updateLinting(cm, annotations) 136 | }, passOptions, cm); 137 | } 138 | 139 | function startLinting(cm) { 140 | var state = cm.state.lint, options = state.options; 141 | /* 142 | * Passing rules in `options` property prevents JSHint (and other linters) from complaining 143 | * about unrecognized rules like `onUpdateLinting`, `delay`, `lintOnChange`, etc. 144 | */ 145 | var passOptions = options.options || options; 146 | var getAnnotations = options.getAnnotations || cm.getHelper(CodeMirror.Pos(0, 0), "lint"); 147 | if (!getAnnotations) return; 148 | if (options.async || getAnnotations.async) { 149 | lintAsync(cm, getAnnotations, passOptions) 150 | } else { 151 | var annotations = getAnnotations(cm.getValue(), passOptions, cm); 152 | if (!annotations) return; 153 | if (annotations.then) annotations.then(function(issues) { 154 | updateLinting(cm, issues); 155 | }); 156 | else updateLinting(cm, annotations); 157 | } 158 | } 159 | 160 | function updateLinting(cm, annotationsNotSorted) { 161 | clearMarks(cm); 162 | var state = cm.state.lint, options = state.options; 163 | 164 | var annotations = groupByLine(annotationsNotSorted); 165 | 166 | for (var line = 0; line < annotations.length; ++line) { 167 | var anns = annotations[line]; 168 | if (!anns) continue; 169 | 170 | var maxSeverity = null; 171 | var tipLabel = state.hasGutter && document.createDocumentFragment(); 172 | 173 | for (var i = 0; i < anns.length; ++i) { 174 | var ann = anns[i]; 175 | var severity = ann.severity; 176 | if (!severity) severity = "error"; 177 | maxSeverity = getMaxSeverity(maxSeverity, severity); 178 | 179 | if (options.formatAnnotation) ann = options.formatAnnotation(ann); 180 | if (state.hasGutter) tipLabel.appendChild(annotationTooltip(ann)); 181 | 182 | if (ann.to) state.marked.push(cm.markText(ann.from, ann.to, { 183 | className: "CodeMirror-lint-mark-" + severity, 184 | __annotation: ann 185 | })); 186 | } 187 | 188 | if (state.hasGutter) 189 | cm.setGutterMarker(line, GUTTER_ID, makeMarker(tipLabel, maxSeverity, anns.length > 1, 190 | state.options.tooltips)); 191 | } 192 | if (options.onUpdateLinting) options.onUpdateLinting(annotationsNotSorted, annotations, cm); 193 | } 194 | 195 | function onChange(cm) { 196 | var state = cm.state.lint; 197 | if (!state) return; 198 | clearTimeout(state.timeout); 199 | state.timeout = setTimeout(function(){startLinting(cm);}, state.options.delay || 500); 200 | } 201 | 202 | function popupTooltips(annotations, e) { 203 | var target = e.target || e.srcElement; 204 | var tooltip = document.createDocumentFragment(); 205 | for (var i = 0; i < annotations.length; i++) { 206 | var ann = annotations[i]; 207 | tooltip.appendChild(annotationTooltip(ann)); 208 | } 209 | showTooltipFor(e, tooltip, target); 210 | } 211 | 212 | function onMouseOver(cm, e) { 213 | var target = e.target || e.srcElement; 214 | if (!/\bCodeMirror-lint-mark-/.test(target.className)) return; 215 | var box = target.getBoundingClientRect(), x = (box.left + box.right) / 2, y = (box.top + box.bottom) / 2; 216 | var spans = cm.findMarksAt(cm.coordsChar({left: x, top: y}, "client")); 217 | 218 | var annotations = []; 219 | for (var i = 0; i < spans.length; ++i) { 220 | var ann = spans[i].__annotation; 221 | if (ann) annotations.push(ann); 222 | } 223 | if (annotations.length) popupTooltips(annotations, e); 224 | } 225 | 226 | CodeMirror.defineOption("lint", false, function(cm, val, old) { 227 | if (old && old != CodeMirror.Init) { 228 | clearMarks(cm); 229 | if (cm.state.lint.options.lintOnChange !== false) 230 | cm.off("change", onChange); 231 | CodeMirror.off(cm.getWrapperElement(), "mouseover", cm.state.lint.onMouseOver); 232 | clearTimeout(cm.state.lint.timeout); 233 | delete cm.state.lint; 234 | } 235 | 236 | if (val) { 237 | var gutters = cm.getOption("gutters"), hasLintGutter = false; 238 | for (var i = 0; i < gutters.length; ++i) if (gutters[i] == GUTTER_ID) hasLintGutter = true; 239 | var state = cm.state.lint = new LintState(cm, parseOptions(cm, val), hasLintGutter); 240 | if (state.options.lintOnChange !== false) 241 | cm.on("change", onChange); 242 | if (state.options.tooltips != false && state.options.tooltips != "gutter") 243 | CodeMirror.on(cm.getWrapperElement(), "mouseover", state.onMouseOver); 244 | 245 | startLinting(cm); 246 | } 247 | }); 248 | 249 | CodeMirror.defineExtension("performLint", function() { 250 | if (this.state.lint) startLinting(this); 251 | }); 252 | }); 253 | -------------------------------------------------------------------------------- /codepretty/prettify.css: -------------------------------------------------------------------------------- 1 | .pln{color:#000}@media screen{.str{color:#080}.kwd{color:#008}.com{color:#800}.typ{color:#606}.lit{color:#066}.pun,.opn,.clo{color:#660}.tag{color:#008}.atn{color:#606}.atv{color:#080}.dec,.var{color:#606}.fun{color:red}}@media print,projection{.str{color:#060}.kwd{color:#006;font-weight:bold}.com{color:#600;font-style:italic}.typ{color:#404;font-weight:bold}.lit{color:#044}.pun,.opn,.clo{color:#440}.tag{color:#006;font-weight:bold}.atn{color:#404}.atv{color:#060}}pre.prettyprint{padding:2px;border:1px solid #888}ol.linenums{margin-top:0;margin-bottom:0}li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8{list-style-type:none}li.L1,li.L3,li.L5,li.L7,li.L9{background:#eee} -------------------------------------------------------------------------------- /codepretty/prettify.js: -------------------------------------------------------------------------------- 1 | !function(){/* 2 | 3 | Copyright (C) 2006 Google Inc. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | */ 17 | window.PR_SHOULD_USE_CONTINUATION=!0; 18 | (function(){function T(a){function d(e){var b=e.charCodeAt(0);if(92!==b)return b;var a=e.charAt(1);return(b=w[a])?b:"0"<=a&&"7">=a?parseInt(e.substring(1),8):"u"===a||"x"===a?parseInt(e.substring(2),16):e.charCodeAt(1)}function f(e){if(32>e)return(16>e?"\\x0":"\\x")+e.toString(16);e=String.fromCharCode(e);return"\\"===e||"-"===e||"]"===e||"^"===e?"\\"+e:e}function b(e){var b=e.substring(1,e.length-1).match(/\\u[0-9A-Fa-f]{4}|\\x[0-9A-Fa-f]{2}|\\[0-3][0-7]{0,2}|\\[0-7]{1,2}|\\[\s\S]|-|[^-\\]/g);e= 19 | [];var a="^"===b[0],c=["["];a&&c.push("^");for(var a=a?1:0,g=b.length;ak||122k||90k||122h[0]&&(h[1]+1>h[0]&&c.push("-"),c.push(f(h[1])));c.push("]");return c.join("")}function v(e){for(var a=e.source.match(/(?:\[(?:[^\x5C\x5D]|\\[\s\S])*\]|\\u[A-Fa-f0-9]{4}|\\x[A-Fa-f0-9]{2}|\\[0-9]+|\\[^ux0-9]|\(\?[:!=]|[\(\)\^]|[^\x5B\x5C\(\)\^]+)/g),c=a.length,d=[],g=0,h=0;g/,null])):d.push(["com",/^#[^\r\n]*/,null,"#"]));a.cStyleComments&&(f.push(["com",/^\/\/[^\r\n]*/,null]),f.push(["com",/^\/\*[\s\S]*?(?:\*\/|$)/,null]));if(b=a.regexLiterals){var v=(b=1|\\/=?|::?|<>?>?=?|,|;|\\?|@|\\[|~|{|\\^\\^?=?|\\|\\|?=?|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\\s*("+ 28 | ("/(?=[^/*"+b+"])(?:[^/\\x5B\\x5C"+b+"]|\\x5C"+v+"|\\x5B(?:[^\\x5C\\x5D"+b+"]|\\x5C"+v+")*(?:\\x5D|$))+/")+")")])}(b=a.types)&&f.push(["typ",b]);b=(""+a.keywords).replace(/^ | $/g,"");b.length&&f.push(["kwd",new RegExp("^(?:"+b.replace(/[\s,]+/g,"|")+")\\b"),null]);d.push(["pln",/^\s+/,null," \r\n\t\u00a0"]);b="^.[^\\s\\w.$@'\"`/\\\\]*";a.regexLiterals&&(b+="(?!s*/)");f.push(["lit",/^@[a-z_$][a-z_$@0-9]*/i,null],["typ",/^(?:[@_]?[A-Z]+[a-z][A-Za-z_$@0-9]*|\w+_t\b)/,null],["pln",/^[a-z_$][a-z_$@0-9]*/i, 29 | null],["lit",/^(?:0x[a-f0-9]+|(?:\d(?:_\d+)*\d*(?:\.\d*)?|\.\d\+)(?:e[+\-]?\d+)?)[a-z]*/i,null,"0123456789"],["pln",/^\\[\s\S]?/,null],["pun",new RegExp(b),null]);return G(d,f)}function L(a,d,f){function b(a){var c=a.nodeType;if(1==c&&!A.test(a.className))if("br"===a.nodeName)v(a),a.parentNode&&a.parentNode.removeChild(a);else for(a=a.firstChild;a;a=a.nextSibling)b(a);else if((3==c||4==c)&&f){var d=a.nodeValue,q=d.match(n);q&&(c=d.substring(0,q.index),a.nodeValue=c,(d=d.substring(q.index+q[0].length))&& 30 | a.parentNode.insertBefore(l.createTextNode(d),a.nextSibling),v(a),c||a.parentNode.removeChild(a))}}function v(a){function b(a,c){var d=c?a.cloneNode(!1):a,k=a.parentNode;if(k){var k=b(k,1),e=a.nextSibling;k.appendChild(d);for(var f=e;f;f=e)e=f.nextSibling,k.appendChild(f)}return d}for(;!a.nextSibling;)if(a=a.parentNode,!a)return;a=b(a.nextSibling,0);for(var d;(d=a.parentNode)&&1===d.nodeType;)a=d;c.push(a)}for(var A=/(?:^|\s)nocode(?:\s|$)/,n=/\r\n?|\n/,l=a.ownerDocument,m=l.createElement("li");a.firstChild;)m.appendChild(a.firstChild); 31 | for(var c=[m],p=0;p=+v[1],d=/\n/g,A=a.a,n=A.length,f=0,l=a.c,m=l.length,b=0,c=a.g,p=c.length,w=0;c[p]=n;var r,e;for(e=r=0;e=h&&(b+=2);f>=k&&(w+=2)}}finally{g&&(g.style.display=a)}}catch(x){E.console&&console.log(x&&x.stack||x)}}var E=window,C=["break,continue,do,else,for,if,return,while"], 34 | F=[[C,"auto,case,char,const,default,double,enum,extern,float,goto,inline,int,long,register,restrict,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"],"catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"],H=[F,"alignas,alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,delegate,dynamic_cast,explicit,export,friend,generic,late_check,mutable,namespace,noexcept,noreturn,nullptr,property,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"], 35 | O=[F,"abstract,assert,boolean,byte,extends,finally,final,implements,import,instanceof,interface,null,native,package,strictfp,super,synchronized,throws,transient"],P=[F,"abstract,add,alias,as,ascending,async,await,base,bool,by,byte,checked,decimal,delegate,descending,dynamic,event,finally,fixed,foreach,from,get,global,group,implicit,in,interface,internal,into,is,join,let,lock,null,object,out,override,orderby,params,partial,readonly,ref,remove,sbyte,sealed,select,set,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,value,var,virtual,where,yield"], 36 | F=[F,"abstract,async,await,constructor,debugger,enum,eval,export,function,get,implements,instanceof,interface,let,null,set,undefined,var,with,yield,Infinity,NaN"],Q=[C,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"],R=[C,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"],C=[C,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"], 37 | S=/^(DIR|FILE|array|vector|(de|priority_)?queue|(forward_)?list|stack|(const_)?(reverse_)?iterator|(unordered_)?(multi)?(set|map)|bitset|u?(int|float)\d*)\b/,W=/\S/,X=y({keywords:[H,P,O,F,"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END",Q,R,C],hashComments:!0,cStyleComments:!0,multiLineStrings:!0,regexLiterals:!0}),I={};t(X,["default-code"]);t(G([],[["pln",/^[^]*(?:>|$)/],["com",/^<\!--[\s\S]*?(?:-\->|$)/],["lang-",/^<\?([\s\S]+?)(?:\?>|$)/],["lang-",/^<%([\s\S]+?)(?:%>|$)/],["pun",/^(?:<[%?]|[%?]>)/],["lang-",/^]*>([\s\S]+?)<\/xmp\b[^>]*>/i],["lang-js",/^]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\s\S]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]),"default-markup htm html mxml xhtml xml xsl".split(" "));t(G([["pln",/^[\s]+/,null," \t\r\n"],["atv",/^(?:\"[^\"]*\"?|\'[^\']*\'?)/,null, 39 | "\"'"]],[["tag",/^^<\/?[a-z](?:[\w.:-]*\w)?|\/?>$/i],["atn",/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^>\'\"\s]*(?:[^>\'\"\s\/]|\/(?=\s)))/],["pun",/^[=<>\/]+/],["lang-js",/^on\w+\s*=\s*\"([^\"]+)\"/i],["lang-js",/^on\w+\s*=\s*\'([^\']+)\'/i],["lang-js",/^on\w+\s*=\s*([^\"\'>\s]+)/i],["lang-css",/^style\s*=\s*\"([^\"]+)\"/i],["lang-css",/^style\s*=\s*\'([^\']+)\'/i],["lang-css",/^style\s*=\s*([^\"\'>\s]+)/i]]),["in.tag"]);t(G([],[["atv",/^[\s\S]+/]]),["uq.val"]);t(y({keywords:H, 40 | hashComments:!0,cStyleComments:!0,types:S}),"c cc cpp cxx cyc m".split(" "));t(y({keywords:"null,true,false"}),["json"]);t(y({keywords:P,hashComments:!0,cStyleComments:!0,verbatimStrings:!0,types:S}),["cs"]);t(y({keywords:O,cStyleComments:!0}),["java"]);t(y({keywords:C,hashComments:!0,multiLineStrings:!0}),["bash","bsh","csh","sh"]);t(y({keywords:Q,hashComments:!0,multiLineStrings:!0,tripleQuotedStrings:!0}),["cv","py","python"]);t(y({keywords:"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END", 41 | hashComments:!0,multiLineStrings:!0,regexLiterals:2}),["perl","pl","pm"]);t(y({keywords:R,hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["rb","ruby"]);t(y({keywords:F,cStyleComments:!0,regexLiterals:!0}),["javascript","js","ts","typescript"]);t(y({keywords:"all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,throw,true,try,unless,until,when,while,yes",hashComments:3,cStyleComments:!0,multilineStrings:!0,tripleQuotedStrings:!0, 42 | regexLiterals:!0}),["coffee"]);t(G([],[["str",/^[\s\S]+/]]),["regex"]);var Y=E.PR={createSimpleLexer:G,registerLangHandler:t,sourceDecorator:y,PR_ATTRIB_NAME:"atn",PR_ATTRIB_VALUE:"atv",PR_COMMENT:"com",PR_DECLARATION:"dec",PR_KEYWORD:"kwd",PR_LITERAL:"lit",PR_NOCODE:"nocode",PR_PLAIN:"pln",PR_PUNCTUATION:"pun",PR_SOURCE:"src",PR_STRING:"str",PR_TAG:"tag",PR_TYPE:"typ",prettyPrintOne:E.prettyPrintOne=function(a,d,f){f=f||!1;d=d||null;var b=document.createElement("div");b.innerHTML="
"+a+"
"; 43 | b=b.firstChild;f&&L(b,f,!0);M({j:d,m:f,h:b,l:1,a:null,i:null,c:null,g:null});return b.innerHTML},prettyPrint:E.prettyPrint=function(a,d){function f(){for(var b=E.PR_SHOULD_USE_CONTINUATION?c.now()+250:Infinity;p 2 | 3 | 4 | 5 | ModelEnd 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 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 |
70 |
71 | 90 |
91 |
92 | 93 | 101 |
102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 |
115 |
116 |
117 |

Results

118 |

119 |     
120 | 121 |
122 |
123 |

JSONLint Partners

124 | Check out their products! 125 |
126 |
127 |
128 | 129 |
130 |

About JSONModel?

131 |

JSONModel is a tool to translate json directly to Object-c model file or Java Bean file.

132 |

Common Errors

133 |
    134 |
  • Expecting 'STRING' - You probably have an extra comma at the end of your collection. Something like { "a": "b", }
  • 135 |
  • Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '[' - You probably have an extra comma at the end of your list. Something like: ["a", "b", ]
  • 136 |
  • Enclosing your collection keys in quotes. Proper format for a collection is { "key": "value" }
  • 137 |
  • Make sure you follow JSON's syntax properly. For example, always use double quotes, always quotify your keys, and remove all callback functions.
  • 138 |
139 |

Credits

140 |

Maintained by CircleCell. Thanks to JSONLint of JSON and JS Lint, and Zach Carter, who built a pure JavaScript implementation.

141 |
142 |
143 | © 2017 modelend.com 版权所有
鄂ICP备15010065号 144 | 145 |
146 |
147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | -------------------------------------------------------------------------------- /res/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/y500/json2model/1e0283b4b705f6ecc84356d4679c6b8a376e2034/res/favicon.ico -------------------------------------------------------------------------------- /res/icon-128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/y500/json2model/1e0283b4b705f6ecc84356d4679c6b8a376e2034/res/icon-128.png -------------------------------------------------------------------------------- /res/icon-180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/y500/json2model/1e0283b4b705f6ecc84356d4679c6b8a376e2034/res/icon-180.png -------------------------------------------------------------------------------- /res/json2.js: -------------------------------------------------------------------------------- 1 | 2 | /*jslint evil: true, strict: false */ 3 | 4 | /*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply, 5 | call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours, 6 | getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join, 7 | lastIndex, length, parse, prototype, push, replace, slice, stringify, 8 | test, toJSON, toString, valueOf 9 | */ 10 | 11 | 12 | // Create a JSON object only if one does not already exist. We create the 13 | // methods in a closure to avoid creating global variables. 14 | 15 | if (!this.JSON) { 16 | this.JSON = {}; 17 | } 18 | 19 | (function () { 20 | 21 | function f(n) { 22 | // Format integers to have at least two digits. 23 | return n < 10 ? '0' + n : n; 24 | } 25 | 26 | if (typeof Date.prototype.toJSON !== 'function') { 27 | 28 | Date.prototype.toJSON = function (key) { 29 | 30 | return isFinite(this.valueOf()) ? 31 | this.getUTCFullYear() + '-' + 32 | f(this.getUTCMonth() + 1) + '-' + 33 | f(this.getUTCDate()) + 'T' + 34 | f(this.getUTCHours()) + ':' + 35 | f(this.getUTCMinutes()) + ':' + 36 | f(this.getUTCSeconds()) + 'Z' : null; 37 | }; 38 | 39 | String.prototype.toJSON = 40 | Number.prototype.toJSON = 41 | Boolean.prototype.toJSON = function (key) { 42 | return this.valueOf(); 43 | }; 44 | } 45 | 46 | var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, 47 | escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, 48 | gap, 49 | indent, 50 | meta = { // table of character substitutions 51 | '\b': '\\b', 52 | '\t': '\\t', 53 | '\n': '\\n', 54 | '\f': '\\f', 55 | '\r': '\\r', 56 | '"' : '\\"', 57 | '\\': '\\\\' 58 | }, 59 | rep; 60 | 61 | 62 | function quote(string) { 63 | 64 | // If the string contains no control characters, no quote characters, and no 65 | // backslash characters, then we can safely slap some quotes around it. 66 | // Otherwise we must also replace the offending characters with safe escape 67 | // sequences. 68 | 69 | escapable.lastIndex = 0; 70 | return escapable.test(string) ? 71 | '"' + string.replace(escapable, function (a) { 72 | var c = meta[a]; 73 | return typeof c === 'string' ? c : 74 | '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4); 75 | }) + '"' : 76 | '"' + string + '"'; 77 | } 78 | 79 | 80 | function str(key, holder) { 81 | 82 | // Produce a string from holder[key]. 83 | 84 | var i, // The loop counter. 85 | k, // The member key. 86 | v, // The member value. 87 | length, 88 | mind = gap, 89 | partial, 90 | value = holder[key]; 91 | 92 | // If the value has a toJSON method, call it to obtain a replacement value. 93 | 94 | if (value && typeof value === 'object' && 95 | typeof value.toJSON === 'function') { 96 | value = value.toJSON(key); 97 | } 98 | 99 | // If we were called with a replacer function, then call the replacer to 100 | // obtain a replacement value. 101 | 102 | if (typeof rep === 'function') { 103 | value = rep.call(holder, key, value); 104 | } 105 | 106 | // What happens next depends on the value's type. 107 | 108 | switch (typeof value) { 109 | case 'string': 110 | return quote(value); 111 | 112 | case 'number': 113 | 114 | // JSON numbers must be finite. Encode non-finite numbers as null. 115 | 116 | return isFinite(value) ? String(value) : 'null'; 117 | 118 | case 'boolean': 119 | case 'null': 120 | 121 | // If the value is a boolean or null, convert it to a string. Note: 122 | // typeof null does not produce 'null'. The case is included here in 123 | // the remote chance that this gets fixed someday. 124 | 125 | return String(value); 126 | 127 | // If the type is 'object', we might be dealing with an object or an array or 128 | // null. 129 | 130 | case 'object': 131 | 132 | // Due to a specification blunder in ECMAScript, typeof null is 'object', 133 | // so watch out for that case. 134 | 135 | if (!value) { 136 | return 'null'; 137 | } 138 | 139 | // Make an array to hold the partial results of stringifying this object value. 140 | 141 | gap += indent; 142 | partial = []; 143 | 144 | // Is the value an array? 145 | 146 | if (Object.prototype.toString.apply(value) === '[object Array]') { 147 | 148 | // The value is an array. Stringify every element. Use null as a placeholder 149 | // for non-JSON values. 150 | 151 | length = value.length; 152 | for (i = 0; i < length; i += 1) { 153 | partial[i] = str(i, value) || 'null'; 154 | } 155 | 156 | // Join all of the elements together, separated with commas, and wrap them in 157 | // brackets. 158 | 159 | v = partial.length === 0 ? '[]' : 160 | gap ? '[\n' + gap + 161 | partial.join(',\n' + gap) + '\n' + 162 | mind + ']' : 163 | '[' + partial.join(',') + ']'; 164 | gap = mind; 165 | return v; 166 | } 167 | 168 | // If the replacer is an array, use it to select the members to be stringified. 169 | 170 | if (rep && typeof rep === 'object') { 171 | length = rep.length; 172 | for (i = 0; i < length; i += 1) { 173 | k = rep[i]; 174 | if (typeof k === 'string') { 175 | v = str(k, value); 176 | if (v) { 177 | partial.push(quote(k) + (gap ? ': ' : ':') + v); 178 | } 179 | } 180 | } 181 | } else { 182 | 183 | // Otherwise, iterate through all of the keys in the object. 184 | 185 | for (k in value) { 186 | if (Object.hasOwnProperty.call(value, k)) { 187 | v = str(k, value); 188 | if (v) { 189 | partial.push(quote(k) + (gap ? ': ' : ':') + v); 190 | } 191 | } 192 | } 193 | } 194 | 195 | // Join all of the member texts together, separated with commas, 196 | // and wrap them in braces. 197 | 198 | v = partial.length === 0 ? '{}' : 199 | gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' + 200 | mind + '}' : '{' + partial.join(',') + '}'; 201 | gap = mind; 202 | return v; 203 | } 204 | } 205 | 206 | // If the JSON object does not yet have a stringify method, give it one. 207 | 208 | if (typeof JSON.stringify !== 'function') { 209 | JSON.stringify = function (value, replacer, space) { 210 | 211 | // The stringify method takes a value and an optional replacer, and an optional 212 | // space parameter, and returns a JSON text. The replacer can be a function 213 | // that can replace values, or an array of strings that will select the keys. 214 | // A default replacer method can be provided. Use of the space parameter can 215 | // produce text that is more easily readable. 216 | 217 | var i; 218 | gap = ''; 219 | indent = ''; 220 | 221 | // If the space parameter is a number, make an indent string containing that 222 | // many spaces. 223 | 224 | if (typeof space === 'number') { 225 | for (i = 0; i < space; i += 1) { 226 | indent += ' '; 227 | } 228 | 229 | // If the space parameter is a string, it will be used as the indent string. 230 | 231 | } else if (typeof space === 'string') { 232 | indent = space; 233 | } 234 | 235 | // If there is a replacer, it must be a function or an array. 236 | // Otherwise, throw an error. 237 | 238 | rep = replacer; 239 | if (replacer && typeof replacer !== 'function' && 240 | (typeof replacer !== 'object' || 241 | typeof replacer.length !== 'number')) { 242 | throw new Error('JSON.stringify'); 243 | } 244 | 245 | // Make a fake root object containing our value under the key of ''. 246 | // Return the result of stringifying the value. 247 | 248 | return str('', {'': value}); 249 | }; 250 | } 251 | 252 | 253 | // If the JSON object does not yet have a parse method, give it one. 254 | 255 | if (typeof JSON.parse !== 'function') { 256 | JSON.parse = function (text, reviver) { 257 | 258 | // The parse method takes a text and an optional reviver function, and returns 259 | // a JavaScript value if the text is a valid JSON text. 260 | 261 | var j; 262 | 263 | function walk(holder, key) { 264 | 265 | // The walk method is used to recursively walk the resulting structure so 266 | // that modifications can be made. 267 | 268 | var k, v, value = holder[key]; 269 | if (value && typeof value === 'object') { 270 | for (k in value) { 271 | if (Object.hasOwnProperty.call(value, k)) { 272 | v = walk(value, k); 273 | if (v !== undefined) { 274 | value[k] = v; 275 | } else { 276 | delete value[k]; 277 | } 278 | } 279 | } 280 | } 281 | return reviver.call(holder, key, value); 282 | } 283 | 284 | 285 | // Parsing happens in four stages. In the first stage, we replace certain 286 | // Unicode characters with escape sequences. JavaScript handles many characters 287 | // incorrectly, either silently deleting them, or treating them as line endings. 288 | 289 | cx.lastIndex = 0; 290 | if (cx.test(text)) { 291 | text = text.replace(cx, function (a) { 292 | return '\\u' + 293 | ('0000' + a.charCodeAt(0).toString(16)).slice(-4); 294 | }); 295 | } 296 | 297 | // In the second stage, we run the text against regular expressions that look 298 | // for non-JSON patterns. We are especially concerned with '()' and 'new' 299 | // because they can cause invocation, and '=' because it can cause mutation. 300 | // But just to be safe, we want to reject all unexpected forms. 301 | 302 | // We split the second stage into 4 regexp operations in order to work around 303 | // crippling inefficiencies in IE's and Safari's regexp engines. First we 304 | // replace the JSON backslash pairs with '@' (a non-JSON character). Second, we 305 | // replace all simple value tokens with ']' characters. Third, we delete all 306 | // open brackets that follow a colon or comma or that begin the text. Finally, 307 | // we look to see that the remaining characters are only whitespace or ']' or 308 | // ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval. 309 | 310 | if (/^[\],:{}\s]*$/. 311 | test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@'). 312 | replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']'). 313 | replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) { 314 | 315 | // In the third stage we use the eval function to compile the text into a 316 | // JavaScript structure. The '{' operator is subject to a syntactic ambiguity 317 | // in JavaScript: it can begin a block or an object literal. We wrap the text 318 | // in parens to eliminate the ambiguity. 319 | 320 | j = eval('(' + text + ')'); 321 | 322 | // In the optional fourth stage, we recursively walk the new structure, passing 323 | // each name/value pair to a reviver function for possible transformation. 324 | 325 | return typeof reviver === 'function' ? 326 | walk({'': j}, '') : j; 327 | } 328 | 329 | // If the text is not JSON parseable, then a SyntaxError is thrown. 330 | 331 | throw new SyntaxError('JSON.parse'); 332 | }; 333 | } 334 | }()); 335 | -------------------------------------------------------------------------------- /res/jsonlint.js: -------------------------------------------------------------------------------- 1 | var jsonlint=function(){var a=!0,b=!1,c={},d=function(){var a={trace:function(){},yy:{},symbols_:{error:2,JSONString:3,STRING:4,JSONNumber:5,NUMBER:6,JSONNullLiteral:7,NULL:8,JSONBooleanLiteral:9,TRUE:10,FALSE:11,JSONText:12,JSONValue:13,EOF:14,JSONObject:15,JSONArray:16,"{":17,"}":18,JSONMemberList:19,JSONMember:20,":":21,",":22,"[":23,"]":24,JSONElementList:25,$accept:0,$end:1},terminals_:{2:"error",4:"STRING",6:"NUMBER",8:"NULL",10:"TRUE",11:"FALSE",14:"EOF",17:"{",18:"}",21:":",22:",",23:"[",24:"]"},productions_:[0,[3,1],[5,1],[7,1],[9,1],[9,1],[12,2],[13,1],[13,1],[13,1],[13,1],[13,1],[13,1],[15,2],[15,3],[20,3],[19,1],[19,3],[16,2],[16,3],[25,1],[25,3]],performAction:function(b,c,d,e,f,g,h){var i=g.length-1;switch(f){case 1:this.$=b.replace(/\\(\\|")/g,"$1").replace(/\\n/g,"\n").replace(/\\r/g,"\r").replace(/\\t/g," ").replace(/\\v/g," ").replace(/\\f/g,"\f").replace(/\\b/g,"\b");break;case 2:this.$=Number(b);break;case 3:this.$=null;break;case 4:this.$=!0;break;case 5:this.$=!1;break;case 6:return this.$=g[i-1];case 13:this.$={};break;case 14:this.$=g[i-1];break;case 15:this.$=[g[i-2],g[i]];break;case 16:this.$={},this.$[g[i][0]]=g[i][1];break;case 17:this.$=g[i-2],g[i-2][g[i][0]]=g[i][1];break;case 18:this.$=[];break;case 19:this.$=g[i-1];break;case 20:this.$=[g[i]];break;case 21:this.$=g[i-2],g[i-2].push(g[i])}},table:[{3:5,4:[1,12],5:6,6:[1,13],7:3,8:[1,9],9:4,10:[1,10],11:[1,11],12:1,13:2,15:7,16:8,17:[1,14],23:[1,15]},{1:[3]},{14:[1,16]},{14:[2,7],18:[2,7],22:[2,7],24:[2,7]},{14:[2,8],18:[2,8],22:[2,8],24:[2,8]},{14:[2,9],18:[2,9],22:[2,9],24:[2,9]},{14:[2,10],18:[2,10],22:[2,10],24:[2,10]},{14:[2,11],18:[2,11],22:[2,11],24:[2,11]},{14:[2,12],18:[2,12],22:[2,12],24:[2,12]},{14:[2,3],18:[2,3],22:[2,3],24:[2,3]},{14:[2,4],18:[2,4],22:[2,4],24:[2,4]},{14:[2,5],18:[2,5],22:[2,5],24:[2,5]},{14:[2,1],18:[2,1],21:[2,1],22:[2,1],24:[2,1]},{14:[2,2],18:[2,2],22:[2,2],24:[2,2]},{3:20,4:[1,12],18:[1,17],19:18,20:19},{3:5,4:[1,12],5:6,6:[1,13],7:3,8:[1,9],9:4,10:[1,10],11:[1,11],13:23,15:7,16:8,17:[1,14],23:[1,15],24:[1,21],25:22},{1:[2,6]},{14:[2,13],18:[2,13],22:[2,13],24:[2,13]},{18:[1,24],22:[1,25]},{18:[2,16],22:[2,16]},{21:[1,26]},{14:[2,18],18:[2,18],22:[2,18],24:[2,18]},{22:[1,28],24:[1,27]},{22:[2,20],24:[2,20]},{14:[2,14],18:[2,14],22:[2,14],24:[2,14]},{3:20,4:[1,12],20:29},{3:5,4:[1,12],5:6,6:[1,13],7:3,8:[1,9],9:4,10:[1,10],11:[1,11],13:30,15:7,16:8,17:[1,14],23:[1,15]},{14:[2,19],18:[2,19],22:[2,19],24:[2,19]},{3:5,4:[1,12],5:6,6:[1,13],7:3,8:[1,9],9:4,10:[1,10],11:[1,11],13:31,15:7,16:8,17:[1,14],23:[1,15]},{18:[2,17],22:[2,17]},{18:[2,15],22:[2,15]},{22:[2,21],24:[2,21]}],defaultActions:{16:[2,6]},parseError:function(b,c){throw new Error(b)},parse:function(b){function o(a){d.length=d.length-2*a,e.length=e.length-a,f.length=f.length-a}function p(){var a;return a=c.lexer.lex()||1,typeof a!="number"&&(a=c.symbols_[a]||a),a}var c=this,d=[0],e=[null],f=[],g=this.table,h="",i=0,j=0,k=0,l=2,m=1;this.lexer.setInput(b),this.lexer.yy=this.yy,this.yy.lexer=this.lexer,typeof this.lexer.yylloc=="undefined"&&(this.lexer.yylloc={});var n=this.lexer.yylloc;f.push(n),typeof this.yy.parseError=="function"&&(this.parseError=this.yy.parseError);var q,r,s,t,u,v,w={},x,y,z,A;for(;;){s=d[d.length-1],this.defaultActions[s]?t=this.defaultActions[s]:(q==null&&(q=p()),t=g[s]&&g[s][q]);if(typeof t=="undefined"||!t.length||!t[0]){if(!k){A=[];for(x in g[s])this.terminals_[x]&&x>2&&A.push("'"+this.terminals_[x]+"'");var B="";this.lexer.showPosition?B="Parse error on line "+(i+1)+":\n"+this.lexer.showPosition()+"\nExpecting "+A.join(", ")+", got '"+this.terminals_[q]+"'":B="Parse error on line "+(i+1)+": Unexpected "+(q==1?"end of input":"'"+(this.terminals_[q]||q)+"'"),this.parseError(B,{text:this.lexer.match,token:this.terminals_[q]||q,line:this.lexer.yylineno,loc:n,expected:A})}if(k==3){if(q==m)throw new Error(B||"Parsing halted.");j=this.lexer.yyleng,h=this.lexer.yytext,i=this.lexer.yylineno,n=this.lexer.yylloc,q=p()}for(;;){if(l.toString()in g[s])break;if(s==0)throw new Error(B||"Parsing halted.");o(1),s=d[d.length-1]}r=q,q=l,s=d[d.length-1],t=g[s]&&g[s][l],k=3}if(t[0]instanceof Array&&t.length>1)throw new Error("Parse Error: multiple actions possible at state: "+s+", token: "+q);switch(t[0]){case 1:d.push(q),e.push(this.lexer.yytext),f.push(this.lexer.yylloc),d.push(t[1]),q=null,r?(q=r,r=null):(j=this.lexer.yyleng,h=this.lexer.yytext,i=this.lexer.yylineno,n=this.lexer.yylloc,k>0&&k--);break;case 2:y=this.productions_[t[1]][1],w.$=e[e.length-y],w._$={first_line:f[f.length-(y||1)].first_line,last_line:f[f.length-1].last_line,first_column:f[f.length-(y||1)].first_column,last_column:f[f.length-1].last_column},v=this.performAction.call(w,h,j,i,this.yy,t[1],e,f);if(typeof v!="undefined")return v;y&&(d=d.slice(0,-1*y*2),e=e.slice(0,-1*y),f=f.slice(0,-1*y)),d.push(this.productions_[t[1]][0]),e.push(w.$),f.push(w._$),z=g[d[d.length-2]][d[d.length-1]],d.push(z);break;case 3:return!0}}return!0}},b=function(){var a={EOF:1,parseError:function(b,c){if(!this.yy.parseError)throw new Error(b);this.yy.parseError(b,c)},setInput:function(a){return this._input=a,this._more=this._less=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this},input:function(){var a=this._input[0];this.yytext+=a,this.yyleng++,this.match+=a,this.matched+=a;var b=a.match(/\n/);return b&&this.yylineno++,this._input=this._input.slice(1),a},unput:function(a){return this._input=a+this._input,this},more:function(){return this._more=!0,this},less:function(a){this._input=this.match.slice(a)+this._input},pastInput:function(){var a=this.matched.substr(0,this.matched.length-this.match.length);return(a.length>20?"...":"")+a.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var a=this.match;return a.length<20&&(a+=this._input.substr(0,20-a.length)),(a.substr(0,20)+(a.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var a=this.pastInput(),b=(new Array(a.length+1)).join("-");return a+this.upcomingInput()+"\n"+b+"^"},next:function(){if(this.done)return this.EOF;this._input||(this.done=!0);var a,b,c,d,e,f;this._more||(this.yytext="",this.match="");var g=this._currentRules();for(var h=0;hb[0].length)){b=c,d=h;if(!this.options.flex)break}}if(b){f=b[0].match(/\n.*/g),f&&(this.yylineno+=f.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:f?f[f.length-1].length-1:this.yylloc.last_column+b[0].length},this.yytext+=b[0],this.match+=b[0],this.yyleng=this.yytext.length,this._more=!1,this._input=this._input.slice(b[0].length),this.matched+=b[0],a=this.performAction.call(this,this.yy,this,g[d],this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1);if(a)return a;return}if(this._input==="")return this.EOF;this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){var b=this.next();return typeof b!="undefined"?b:this.lex()},begin:function(b){this.conditionStack.push(b)},popState:function(){return this.conditionStack.pop()},_currentRules:function(){return this.conditions[this.conditionStack[this.conditionStack.length-1]].rules},topState:function(){return this.conditionStack[this.conditionStack.length-2]},pushState:function(b){this.begin(b)}};return a.options={},a.performAction=function(b,c,d,e){var f=e;switch(d){case 0:break;case 1:return 6;case 2:return c.yytext=c.yytext.substr(1,c.yyleng-2),4;case 3:return 17;case 4:return 18;case 5:return 23;case 6:return 24;case 7:return 22;case 8:return 21;case 9:return 10;case 10:return 11;case 11:return 8;case 12:return 14;case 13:return"INVALID"}},a.rules=[/^(?:\s+)/,/^(?:(-?([0-9]|[1-9][0-9]+))(\.[0-9]+)?([eE][-+]?[0-9]+)?\b)/,/^(?:"(?:\\[\\"bfnrt/]|\\u[a-fA-F0-9]{4}|[^\\\0-\x09\x0a-\x1f"])*")/,/^(?:\{)/,/^(?:\})/,/^(?:\[)/,/^(?:\])/,/^(?:,)/,/^(?::)/,/^(?:true\b)/,/^(?:false\b)/,/^(?:null\b)/,/^(?:$)/,/^(?:.)/],a.conditions={INITIAL:{rules:[0,1,2,3,4,5,6,7,8,9,10,11,12,13],inclusive:!0}},a}();return a.lexer=b,a}();return typeof a!="undefined"&&typeof c!="undefined"&&(c.parser=d,c.parse=function(){return d.parse.apply(d,arguments)},c.main=function(d){if(!d[1])throw new Error("Usage: "+d[0]+" FILE");if(typeof process!="undefined")var e=a("fs").readFileSync(a("path").join(process.cwd(),d[1]),"utf8");else var f=a("file").path(a("file").cwd()),e=f.join(d[1]).read({charset:"utf-8"});return c.parser.parse(e)},typeof b!="undefined"&&a.main===b&&c.main(typeof process!="undefined"?process.argv.slice(1):a("system").args)),c}(); -------------------------------------------------------------------------------- /res/jsonmodel.js: -------------------------------------------------------------------------------- 1 | var jsonModel=function(){var k="",l="",v="",m="",w="",n="",p=function(a){return a.replace(/\b[a-z]/g,function(a){return a.toUpperCase()})},B=function(a){return a.replace(/\b[a-z]/g,function(a){return a.toLowerCase()})},q=function(a){return a instanceof Object?a.constructor.prototype.hasOwnProperty("push"):!1},r=function(a){return a instanceof Object?!a.constructor.prototype.hasOwnProperty("push"):!1},C=function(){n=w=m=v=l=k=""},D=function(){var a=editor_json.getValue().trim();try{var d=jsonlint.parse(a); 2 | if(d){document.getElementById("result-container").setAttribute("class","shown");document.getElementById("result").innerHTML="JSON is valid!";document.getElementById("result").setAttribute("class","success");var c=JSON.stringify(d,null," ");editor_json.setValue(c);return!0}}catch(e){return document.getElementById("result-container").setAttribute("class","shown"),document.getElementById("result").innerHTML=e,document.getElementById("result").className="error",!1}},t=function(a,d){return"@interface "+ 3 | a+" :NSObject\n"+d+"\n@end\n"},u=function(a){return"@implement "+a+"\n@end\n"},E=function(a,d){return"@property (nonatomic , assign) "+a+" "+d+";\n"},x=function(a,d){return"@property (nonatomic , strong) "+a+" * "+d+";\n"},F=function(a){return"public static class "+a+" {\r\n"},G=function(a){return"class "+a+" : NSObject {\r\n"},H=function(a,d){C();0==d.length&&(d="ModelName");var c=y(a,d);k=0e.length&&(e=b):r(b)&&Object.keys(b).length>Object.keys(e).length&&(e=b)}c+=y(e,d)}}else if(r(a))for(e in a){b=a[e];var h=p(e);f=B(e);if(q(b)){var g;0",f):"number"===typeof g||"boolean"===typeof g?c+=x("NSArray ",f):"object"===typeof g&&(h+="Item",c+=x("NSArray <"+h+" *>",f),b=y(b,e),k=0e.length&&(e=b):r(b)&&Object.keys(b).length>Object.keys(e).length&&(e=b)}c+=z(e,d)}}else if(r(a))for(e in a){b=a[e];var h=p(e),g=B(e);q(b)?(0 "+g+";\r\n",b=F(h)+z(b,e)+"}\r\n",m=0e.length&&(e=b):r(b)&&Object.keys(b).length>Object.keys(e).length&&(e=b)}c+=A(e, 10 | d)}}else if(r(a))for(e in a){b=a[e];var h=p(e),g=B(e);q(b)?(0ul { 169 | display: inherit; 170 | } 171 | 172 | nav ul ul li { 173 | width: 240px; 174 | float: none; 175 | display: list-item; 176 | position: relative; 177 | border-bottom: 1px solid #f0f0f0; 178 | padding: 7px 0; 179 | line-height: 20px; 180 | } 181 | 182 | nav ul ul li.jscompress { 183 | border-left: 5px solid #F8DC3C; 184 | } 185 | 186 | nav ul ul li.json { 187 | border-left: 5px solid #1E8BC3; 188 | } 189 | 190 | nav ul ul li.compare { 191 | border-left: 5px solid #446CB3; 192 | } 193 | 194 | nav ul ul li.dns { 195 | border-left: 5px solid #26A65B; 196 | } 197 | 198 | nav ul ul li.comp { 199 | border-left: 5px solid #3498DB; 200 | } 201 | 202 | nav ul ul li.keygen { 203 | border-left: 5px solid #EB9532; 204 | } 205 | 206 | nav ul ul li.jsvalidate { 207 | border-left: 5px solid #FFCF4B; 208 | } 209 | 210 | nav ul ul ul li { 211 | position: relative; 212 | top: -60px; 213 | left: 300px; 214 | } 215 | 216 | .tagline-title { 217 | font-size: 11px 218 | } 219 | 220 | li>a:only-child:after { 221 | content: ''; 222 | } 223 | 224 | .three-lines { 225 | position: relative; 226 | display: inline-block; 227 | width: 0.8em; 228 | height: 0.8em; 229 | margin: 7px 10px 0 0; 230 | border-top: 0.1em solid #333; 231 | border-bottom: 0.1em solid #333; 232 | } 233 | 234 | .three-lines:before { 235 | content: ""; 236 | position: absolute; 237 | top: 0.3em; 238 | left: 0; 239 | width: 100%; 240 | border-top: 0.1em solid #333; 241 | } 242 | 243 | .hide { 244 | display: none; 245 | } 246 | 247 | .container { 248 | display: block; 249 | margin: 0 auto; 250 | max-width: 1100px; 251 | padding: 10px 15px; 252 | text-align: left; 253 | } 254 | 255 | footer { 256 | text-align: center; 257 | max-width: 1100px; 258 | padding: 15px; 259 | margin: 0 auto 0; 260 | border-top: 1px solid #eee; 261 | font-size: 12px; 262 | font-weight: 700; 263 | } 264 | 265 | main { 266 | display: block; 267 | width: 100%; 268 | max-width: 950px; 269 | margin: 0 auto; 270 | padding: 1.5em 0; 271 | } 272 | 273 | #model { 274 | width: 100%; 275 | height: 380px; 276 | border: 1px solid #e1e1e1; 277 | margin-bottom: 1em; 278 | font-size: 14px; 279 | } 280 | 281 | .line-error { 282 | background-color: #FBE3E4; 283 | } 284 | 285 | button[type="submit"] { 286 | background-color: #fff; 287 | padding: 10px 15px; 288 | text-decoration: none; 289 | border: 1px solid #e1e1e1; 290 | font-size: 14px; 291 | font-family: Open Sans, sans-serif; 292 | font-weight: 700; 293 | color: #333; 294 | margin: 10px 10px 0 0; 295 | } 296 | 297 | button[class="model"] { 298 | background-color: #fff; 299 | padding: 10px 15px; 300 | text-decoration: none; 301 | border: 1px solid #e1e1e1; 302 | font-size: 14px; 303 | font-family: Open Sans, sans-serif; 304 | font-weight: 700; 305 | color: #333; 306 | margin: 10px 10px 10px 10px; 307 | } 308 | 309 | input[id="fileName"] { 310 | background-color: #fff; 311 | padding: 10px 15px; 312 | text-decoration: none; 313 | border: 1px solid #e1e1e1; 314 | font-size: 14px; 315 | font-family: Open Sans, sans-serif; 316 | font-weight: 700; 317 | color: #333; 318 | margin: 10px 10px 10px 0; 319 | vetical-align:middle; 320 | } 321 | 322 | button[type="reset"], button.copy { 323 | background-color: rgba(255, 0, 0, 0.5); 324 | padding: 10px 15px; 325 | text-decoration: none; 326 | border: 1px solid #ddd; 327 | font-size: 14px; 328 | font-family: Open Sans, sans-serif; 329 | font-weight: 700; 330 | color: #fff; 331 | margin-top: 10px; 332 | margin-left: 30px; 333 | } 334 | 335 | button[type="reset"]:hover { 336 | cursor: pointer; 337 | background: #ddd; 338 | border: 1px solid #ccc; 339 | } 340 | 341 | button[type="reset"]:active { 342 | } 343 | 344 | @media all and (min-width: 541px) { 345 | button.copy { 346 | display: none; 347 | } 348 | } 349 | 350 | #result-container { 351 | display: none; 352 | padding-top: 15px; 353 | } 354 | 355 | #result-container.shown { 356 | display: block; 357 | } 358 | 359 | #result-container h3 { 360 | font-size: 1.3em; 361 | } 362 | 363 | #result { 364 | border: 1px solid transparent; 365 | margin: 1.6em 0; 366 | padding: 0.8em; 367 | } 368 | 369 | #result:empty { 370 | display: none; 371 | } 372 | 373 | #result.error { 374 | background: #FBE3E4; 375 | color: #D12F19; 376 | border-color: #FBC2C4; 377 | } 378 | 379 | #result.success { 380 | background: #E6EFC2; 381 | color: #529214; 382 | border-color: #C6D880; 383 | } 384 | 385 | #implementCode, #headCode { 386 | border: 1px solid transparent; 387 | margin: 1.6em 0; 388 | padding: 0.8em; 389 | } 390 | 391 | #implementCode.model-result { 392 | background: #f6f8fa; 393 | color: #529214; 394 | border-color: #C6D880; 395 | } 396 | 397 | #headCode.model-result { 398 | background: #f6f8fa; 399 | color: #529214; 400 | border-color: #C6D880; 401 | } 402 | 403 | .partner { 404 | display: block; 405 | flex-direction: column; 406 | width: 100%; 407 | padding: 0 15px 15px; 408 | justify-content: center; 409 | } 410 | 411 | .partner p { 412 | margin-bottom: .3em; 413 | font-size: 1.5em; 414 | } 415 | 416 | .partner strong { 417 | padding: .1em .4em; 418 | background-color: #1E8BC3; 419 | color: #fff; 420 | } 421 | 422 | .partner sub { 423 | font-weight: 200; 424 | font-size: 1.3em; 425 | } 426 | 427 | footer { 428 | padding-bottom: 3.5em !important; 429 | } 430 | 431 | /* ====================================== */ 432 | 433 | .bsa-ad { 434 | display: none; 435 | margin: 2em 0 1em; 436 | padding: 1.5em 1em; 437 | background-color: hsl(210, 25%, 92%); 438 | border-radius: 3px; 439 | flex-flow: row nowrap; 440 | } 441 | 442 | .partner { 443 | display: flex; 444 | flex-direction: column; 445 | width: 44%; 446 | justify-content: center; 447 | } 448 | 449 | .partner p { 450 | margin-bottom: .3em; 451 | line-height: 1.5; 452 | font-size: 1.5em; 453 | } 454 | 455 | .partner strong { 456 | color: #fff; 457 | background-color: #1E8BC3; 458 | border-radius: 3px; 459 | padding: .1em .3em; 460 | } 461 | 462 | .partner sub { 463 | font-weight: 200; 464 | font-size: 1.3em; 465 | } 466 | 467 | .bsa-cpc #_default_ { 468 | position: relative; 469 | display: flex; 470 | font-size: 14px; 471 | line-height: 1.5; 472 | } 473 | 474 | .bsa-cpc .default-ad { 475 | display: none; 476 | } 477 | 478 | .bsa-cpc ._default_ { 479 | position: relative; 480 | display: block; 481 | overflow: hidden; 482 | margin: 0 1em; 483 | padding: 1em; 484 | width: 50%; 485 | border-radius: 3px; 486 | background-color: #fff; 487 | line-height: 1.5; 488 | } 489 | 490 | .bsa-cpc a { 491 | color: inherit; 492 | text-decoration: none; 493 | transition: background-color .15s ease-in-out; 494 | } 495 | 496 | .bsa-cpc a:hover { 497 | color: #fff; 498 | background-color: #1E8BC3; 499 | } 500 | 501 | .bsa-cpc .default-image img { 502 | display: block; 503 | float: left; 504 | margin-right: 10px; 505 | width: 36px; 506 | border-radius: 7.5%; 507 | } 508 | 509 | .bsa-cpc .default-title, 510 | .bsa-cpc .default-description { 511 | display: block; 512 | margin-left: 46px; 513 | max-width: calc(100% - 36px); 514 | } 515 | 516 | .bsa-cpc .default-title { 517 | font-weight: 600; 518 | } 519 | 520 | @media only screen and (min-width: 320px) and (max-width: 759px) { 521 | .bsa-cpc #_default_ { 522 | flex-wrap: wrap; 523 | } 524 | .bsa-cpc ._default_ { 525 | margin: .2em 1em; 526 | width: 100%; 527 | } 528 | } 529 | 530 | @media all and (max-width: 775px) { 531 | .description-title { 532 | display: none 533 | } 534 | .more-dev { 535 | display: none 536 | } 537 | .three-lines { 538 | margin:7px 5px 539 | } 540 | } 541 | 542 | @media all and (max-width: 460px) { 543 | .sub-title{ 544 | display: none 545 | } 546 | } 547 | 548 | @media all and (max-width: 360px) { 549 | .more-tools{ 550 | display: none 551 | } 552 | } 553 | --------------------------------------------------------------------------------