source: node_modules/@swagger-api/apidom-json-pointer/es/unescape.mjs

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 641 bytes
Line 
1import { pipe, replace } from 'ramda';
2
3/**
4 * decodeURIComponent can throw URIError in certain cases like 'c%d'.
5 * safeDecodeURIComponent is a safe variant of decodeURIComponent that never trows.
6 *
7 * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Malformed_URI|More info about URIError}
8 */
9const safeDecodeURIComponent = encodedURIComponent => {
10 try {
11 return decodeURIComponent(encodedURIComponent);
12 } catch {
13 return encodedURIComponent;
14 }
15};
16
17// unescape :: String -> String
18const unescape = pipe(replace(/~1/g, '/'), replace(/~0/g, '~'), safeDecodeURIComponent);
19export default unescape;
Note: See TracBrowser for help on using the repository browser.