X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=shm_utils%2Fumurmurd-websocket%2Fweb%2Fjs%2Fjson.human.js;fp=shm_utils%2Fumurmurd-websocket%2Fweb%2Fjs%2Fjson.human.js;h=0000000000000000000000000000000000000000;hb=1fbc5db2d0c6168e10b116cb474174d165192530;hp=d0ccd7af7f4237b2c0ea9ab728ac414de07d50e1;hpb=a738ff892738e239ad74f5aa686108298efa7cea;p=umurmur.git diff --git a/shm_utils/umurmurd-websocket/web/js/json.human.js b/shm_utils/umurmurd-websocket/web/js/json.human.js deleted file mode 100644 index d0ccd7a..0000000 --- a/shm_utils/umurmurd-websocket/web/js/json.human.js +++ /dev/null @@ -1,149 +0,0 @@ -/*globals define*/ -(function (root, factory) { - "use strict"; - if (typeof define === 'function' && define.amd) { - define(['crel'], factory); - } else if (typeof module !== 'undefined' && module.exports) { - module.exports = factory(require('../lib/crel')); - } else { - root.JsonHuman = factory(root.crel); - } -}(this, function (crel) { - "use strict"; - var toString = Object.prototype.toString, - ARRAY = 1, - BOOL = 2, - INT = 3, - FLOAT = 4, - STRING = 5, - OBJECT = 6, - FUNCTION = 7, - UNK = 99; - - function makePrefixer(prefix) { - return function (name) { - return prefix + "-" + name; - }; - } - - function getType(obj) { - var type = typeof obj; - - if (type === "boolean") { - return BOOL; - } else if (type === "string") { - return STRING; - } else if (type === "number") { - return (obj % 1 === 0) ? INT : FLOAT; - } else if (type === "function") { - return FUNCTION; - } else if (toString.call(obj) === '[object Array]') { - return ARRAY; - } else if (obj === Object(obj)) { - return OBJECT; - } else { - return UNK; - } - } - - function _format(data, prefixer) { - var result, container, key, keyNode, valNode, - isEmpty = true, - p = prefixer, - accum = [], - type = getType(data); - - switch (type) { - case BOOL: - result = crel("span", {"class": p("type-bool")}, "" + data); - break; - case STRING: - if (data !== "") { - result = crel("span", {"class": p("type-string")}, ""); - result.innerHTML = data - .replace(/&/g, '&') - .replace(/ /g, " ") - .replace(//g, '>') - .replace(/[\r\n]/g, '
') - .replace(/"/g, '"'); // ") - } else { - result = crel("span", - {"class": p("type-string") + " " + p("empty")}, - "(Empty Text)"); - } - break; - case INT: - result = crel("span", - {"class": p("type-int") + " " + p("type-number")}, - "" + data); - break; - case FLOAT: - result = crel("span", - {"class": p("type-float") + " " + p("type-number")}, - "" + data); - break; - case OBJECT: - result = crel("table", {"class": p("type-object")}); - for (key in data) { - isEmpty = false; - keyNode = crel("th", - {"class": p("key") + " " + p("object-key")}, - "" + key); - valNode = crel("td", - {"class": p("value") + " " + p("object-value")}, - _format(data[key], p)); - result.appendChild(crel("tr", keyNode, valNode)); - } - - if (isEmpty) { - result = crel("span", - {"class": p("type-object") + " " + p("empty")}, - "(Empty Object)"); - } - break; - case FUNCTION: - result = crel("span", {"class": p("type-function")}, "" + data); - break; - case ARRAY: - if (data.length > 0) { - result = crel("table", {"class": p("type-array")}); - for (key = 0; key < data.length; key += 1) { - keyNode = crel("th", - {"class": p("key") + " " + p("array-key")}, - "" + key); - valNode = crel("td", - {"class": p("value") + " " + p("array-value")}, - _format(data[key], p)); - result.appendChild(crel("tr", keyNode, valNode)); - } - } else { - result = crel("span", - {"class": p("type-array") + " " + p("empty")}, - "(Empty List)"); - } - break; - default: - result = crel("span", {"class": p("type-unk")}, - "" + data); - break; - } - - return result; - } - - function format(data, options) { - options = options || {}; - var result, - prefixer = makePrefixer(options.prefix || "jh"); - - result = _format(data, prefixer); - result.className = result.className + " " + prefixer("root"); - - return result; - } - - return { - format: format - }; -}));