All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.es.unescape.mjs Maven / Gradle / Ivy

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;




© 2015 - 2024 Weber Informatics LLC | Privacy Policy