nemesiscodex/openfonacide

View on GitHub
static/js/jsonh.js

Summary

Maintainability
A
0 mins
Test Coverage
var JSONH,jsonh=JSONH=function(Array,JSON){"use strict";function hpack(list){for(var
length=list.length,keys=Object_keys(length?list[0]:{}),klength=keys.length,result=Array(length*klength),i=0,j=0,ki,o;i<length;++i){for(o=list[i],ki=0;ki<klength;result[j++]=o[keys[ki++]]);}return concat.call([klength],keys,result);}function hunpack(hlist){for(var
length=hlist.length,klength=hlist[0],result=Array(((length-klength-1)/klength)||0),i=1+klength,j=0,ki,o;i<length;){for(result[j++]=(o={}),ki=0;ki<klength;o[hlist[++ki]]=hlist[i++]);}return result;}function iteratingWith(method){return function iterate(item){for(var
path=this,current=item,i=0,length=path.length,j,k,tmp;i<length;++i){if(isArray(tmp=current[k=path[i]])){j=i+1;current[k]=j<length?map.call(tmp,method,path.slice(j)):method(tmp);}current=current[k];}return item;};}function packOrUnpack(method){return function parse(o,schema){for(var
wasArray=isArray(o),result=concat.call(arr,o),path=concat.call(arr,schema),i=0,length=path.length;i<length;++i){result=map.call(result,method,path[i].split("."));}return wasArray?result:result[0];};}function pack(list,schema){return schema?packSchema(list,schema):hpack(list);}function unpack(hlist,schema){return schema?unpackSchema(hlist,schema):hunpack(hlist);}function stringify(list,replacer,space,schema){return JSON_stringify(pack(list,schema),replacer,space);}function parse(hlist,reviver,schema){return unpack(JSON_parse(hlist,reviver),schema);}var
arr=[],concat=arr.concat,Object_keys=Object.keys||function(o){var keys=[],key;for(key in o)o.hasOwnProperty(key)&&keys.push(key);return keys;},isArray=Array.isArray||(function(toString,arrayToString){arrayToString=toString.call(arr);return function isArray(o){return toString.call(o)==arrayToString;};}({}.toString)),map=arr.map||function(callback,context){for(var
self=this,i=self.length,result=Array(i);i--;result[i]=callback.call(context,self[i],i,self));return result;},packSchema=packOrUnpack(iteratingWith(hpack)),unpackSchema=packOrUnpack(iteratingWith(hunpack)),JSON_stringify=JSON.stringify,JSON_parse=JSON.parse;return{pack:pack,parse:parse,stringify:stringify,unpack:unpack};}(Array,JSON);if(typeof module!='undefined'&&module.exports){module.exports=jsonh;}