Skip to content

Instantly share code, notes, and snippets.

@excenter
Created January 17, 2019 21:22
Show Gist options
  • Save excenter/055dad5f0a8a09d058e8b24b55ea4115 to your computer and use it in GitHub Desktop.
Save excenter/055dad5f0a8a09d058e8b24b55ea4115 to your computer and use it in GitHub Desktop.
it's like minify, but different in subtle ways important to few people.
function jsonSquish(contents){
// remove all line breaks
// console.log(contents)
contents = contents.replace(/\r?\n|\r/g,"")
contents = contents.replace(/"/g, '\"\"')
// console.log(contents)
// compress all multiple spaces down to one space
change = ""
for(;change !== contents;){
// console.log(contents)
change = contents;
contents = contents.replace(/ /g," ")
}
// console.log(contents)
return contents
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment