Skip to content

Instantly share code, notes, and snippets.

@eral
Created March 16, 2025 15:08
Show Gist options
  • Save eral/d24e78ee122a055bcd6b475605720f00 to your computer and use it in GitHub Desktop.
Save eral/d24e78ee122a055bcd6b475605720f00 to your computer and use it in GitHub Desktop.
1関数Stringify
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