package.es.unescape.mjs Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of apidom-json-pointer Show documentation
Show all versions of apidom-json-pointer Show documentation
Evaluate JSON Pointer expressions against ApiDOM.
The newest version!
import { pipe, replace } from 'ramda';
/**
* decodeURIComponent can throw URIError in certain cases like 'c%d'.
* safeDecodeURIComponent is a safe variant of decodeURIComponent that never trows.
*
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Malformed_URI|More info about URIError}
*/
const safeDecodeURIComponent = encodedURIComponent => {
try {
return decodeURIComponent(encodedURIComponent);
} catch {
return encodedURIComponent;
}
};
// unescape :: String -> String
const unescape = pipe(replace(/~1/g, '/'), replace(/~0/g, '~'), safeDecodeURIComponent);
export default unescape;