UNPKG

@cloudinary/url-gen

Version:

You are invited to influence our new SDK [Click here to view github discussion](https://github.com/cloudinary/js-url-gen/discussions/602) =========================

11 lines (10 loc) 438 B
// Based on CGI::unescape. In addition does not escape / : // smart_escape = (string)-> // encodeURIComponent(string).replace(/%3A/g, ":").replace(/%2F/g, "/") export function smartEscape(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(""); }); }