Created
March 16, 2025 15:08
-
-
Save eral/d24e78ee122a055bcd6b475605720f00 to your computer and use it in GitHub Desktop.
1関数Stringify
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function oneFunctionStringify(obj) { | |
var result = ""; | |
if (obj instanceof Array) { | |
result += "["; | |
var splitChar = ""; | |
for (var i = 0; i < obj.length; ++i) { | |
result += splitChar + oneFunctionStringify(obj[i]); | |
splitChar = ","; | |
} | |
result += "]"; | |
} else if (obj instanceof Object) { | |
result += "{"; | |
var splitChar = ""; | |
for (var i in obj) { | |
result += splitChar + oneFunctionStringify(i) + ":" + oneFunctionStringify(obj[i]); | |
splitChar = ","; | |
} | |
result += "}"; | |
} else if (typeof(obj) === "string") { | |
result += '"' + obj.replace(/((?:\\\\)*)([\\"])/g, '$1\\$2') + '"'; | |
} else { | |
result += obj; | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment