Created
August 2, 2015 23:15
-
-
Save JavaScript-Packer/1c1944cd64f57a8569d1 to your computer and use it in GitHub Desktop.
Escape HTML entities, JS safe escaping, URL encoding, etc. SOme functions used on http://www.whak.ca/packer/LZMA.htm
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 esc_HTML(n) { | |
return n.replace(/[&\n\r "'<>\v\0]/g, function(n) { | |
return "&#" + n.charCodeAt(0) + ";"; | |
}); | |
} | |
function esc_URL(n) { | |
return n.replace(/[^\w\d]/g, function(n) { | |
return "%" + function(n, r, t) { | |
return t = t || "0", n += "", n.length < r ? Array(r - n.length + 1).join(t) + n : n; | |
}(n.charCodeAt(0).toString(16).toUpperCase(), 2, 0); | |
}); | |
} | |
function esc_JS_octal(n) { | |
return n.replace(/[^\w\d]/g, function(n) { | |
return "\\" + function(n, r, t) { | |
return t = t || "0", n += "", n.length < r ? Array(r - n.length + 1).join(t) + n : n; | |
}(n.charCodeAt(0).toString(8).toUpperCase(), 2, 0); | |
}); | |
} | |
function esc_JS_hex(n) { | |
return n.replace(/[^\w\d]/g, function(n) { | |
return "\\x" + function(n, r, t) { | |
return t = t || "0", n += "", n.length < r ? Array(r - n.length + 1).join(t) + n : n; | |
}(n.charCodeAt(0).toString(16).toUpperCase(), 2, 0); | |
}); | |
} | |
function esc_codepoint(n) { | |
return n.replace(/[^]/g, function(n) { | |
return "" + function(n, r, t) { | |
return t = t || "0", n += "", n.length < r ? Array(r - n.length + 1).join(t) + n : n; | |
}(n.charCodeAt(0), 2, 0) + " "; | |
}).trim().replace(/ /g, ","); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment