kopia lustrzana https://github.com/simonw/datasette
Ran Prettier, refs #1871
rodzic
0b166befc0
commit
042881a522
|
@ -4,40 +4,53 @@ From https://unpkg.com/json-format-highlight@1.0.1/dist/json-format-highlight.js
|
||||||
MIT Licensed
|
MIT Licensed
|
||||||
*/
|
*/
|
||||||
(function (global, factory) {
|
(function (global, factory) {
|
||||||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
typeof exports === "object" && typeof module !== "undefined"
|
||||||
typeof define === 'function' && define.amd ? define(factory) :
|
? (module.exports = factory())
|
||||||
(global.jsonFormatHighlight = factory());
|
: typeof define === "function" && define.amd
|
||||||
}(this, (function () { 'use strict';
|
? define(factory)
|
||||||
|
: (global.jsonFormatHighlight = factory());
|
||||||
|
})(this, function () {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
var defaultColors = {
|
var defaultColors = {
|
||||||
keyColor: 'dimgray',
|
keyColor: "dimgray",
|
||||||
numberColor: 'lightskyblue',
|
numberColor: "lightskyblue",
|
||||||
stringColor: 'lightcoral',
|
stringColor: "lightcoral",
|
||||||
trueColor: 'lightseagreen',
|
trueColor: "lightseagreen",
|
||||||
falseColor: '#f66578',
|
falseColor: "#f66578",
|
||||||
nullColor: 'cornflowerblue'
|
nullColor: "cornflowerblue",
|
||||||
};
|
};
|
||||||
|
|
||||||
function index (json, colorOptions) {
|
function index(json, colorOptions) {
|
||||||
if ( colorOptions === void 0 ) colorOptions = {};
|
if (colorOptions === void 0) colorOptions = {};
|
||||||
|
|
||||||
if (!json) { return; }
|
if (!json) {
|
||||||
if (typeof json !== 'string') {
|
return;
|
||||||
json = JSON.stringify(json, null, 2);
|
|
||||||
}
|
|
||||||
var colors = Object.assign({}, defaultColors, colorOptions);
|
|
||||||
json = json.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
||||||
return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+]?\d+)?)/g, function (match) {
|
|
||||||
var color = colors.numberColor;
|
|
||||||
if (/^"/.test(match)) {
|
|
||||||
color = /:$/.test(match) ? colors.keyColor : colors.stringColor;
|
|
||||||
} else {
|
|
||||||
color = /true/.test(match) ? colors.trueColor : /false/.test(match) ? colors.falseColor : /null/.test(match) ? colors.nullColor : color;
|
|
||||||
}
|
}
|
||||||
return ("<span style=\"color: " + color + "\">" + match + "</span>");
|
if (typeof json !== "string") {
|
||||||
});
|
json = JSON.stringify(json, null, 2);
|
||||||
}
|
}
|
||||||
|
var colors = Object.assign({}, defaultColors, colorOptions);
|
||||||
|
json = json.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
||||||
|
return json.replace(
|
||||||
|
/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+]?\d+)?)/g,
|
||||||
|
function (match) {
|
||||||
|
var color = colors.numberColor;
|
||||||
|
if (/^"/.test(match)) {
|
||||||
|
color = /:$/.test(match) ? colors.keyColor : colors.stringColor;
|
||||||
|
} else {
|
||||||
|
color = /true/.test(match)
|
||||||
|
? colors.trueColor
|
||||||
|
: /false/.test(match)
|
||||||
|
? colors.falseColor
|
||||||
|
: /null/.test(match)
|
||||||
|
? colors.nullColor
|
||||||
|
: color;
|
||||||
|
}
|
||||||
|
return '<span style="color: ' + color + '">' + match + "</span>";
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return index;
|
return index;
|
||||||
|
});
|
||||||
})));
|
|
||||||
|
|
Ładowanie…
Reference in New Issue