MCPcopy
hub / github.com/methodofaction/Method-Draw / json_encode

Function json_encode

src/js/method-draw.js:1993–2020  ·  view source on GitHub ↗
(obj)

Source from the content-addressed store, hash-verified

1991 // Callback handler for embedapi.js
1992 try{
1993 var json_encode = function(obj){
1994 //simple partial JSON encoder implementation
1995 if(window.JSON && JSON.stringify) return JSON.stringify(obj);
1996 var enc = arguments.callee; //for purposes of recursion
1997 if(typeof obj == "boolean" || typeof obj == "number"){
1998 return obj+'' //should work...
1999 }else if(typeof obj == "string"){
2000 //a large portion of this is stolen from Douglas Crockford's json2.js
2001 return '"'+
2002 obj.replace(
2003 /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g
2004 , function (a) {
2005 return '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
2006 })
2007 +'"'; //note that this isn't quite as purtyful as the usualness
2008 }else if(obj.length){ //simple hackish test for arrayish-ness
2009 for(var i = 0; i < obj.length; i++){
2010 obj[i] = enc(obj[i]); //encode every sub-thingy on top
2011 }
2012 return "["+obj.join(",")+"]";
2013 }else{
2014 var pairs = []; //pairs will be stored here
2015 for(var k in obj){ //loop through thingys
2016 pairs.push(enc(k)+":"+enc(obj[k])); //key: value
2017 }
2018 return "{"+pairs.join(",")+"}" //wrap in the braces
2019 }
2020 }
2021 window.addEventListener("message", function(e){
2022 var cbid = parseInt(e.data.substr(0, e.data.indexOf(";")));
2023 try{

Callers 1

method-draw.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected