@qelos/assets
Version:
manage assets like images and static files on remote servers
13 lines (11 loc) • 446 B
JavaScript
// Based on CGI::unescape. In addition does not escape / :
// smart_escape = (string)->
// encodeURIComponent(string).replace(/%3A/g, ":").replace(/%2F/g, "/")
function smart_escape(string, unsafe = /([^a-zA-Z0-9_.\-\/:]+)/g) {
return string.replace(unsafe, function (match) {
return match.split("").map(function (c) {
return "%" + c.charCodeAt(0).toString(16).toUpperCase();
}).join("");
});
}
module.exports = smart_escape;