How to use the punycode.js.toUnicode function in punycode

To help you get started, we’ve selected a few punycode examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hexojs / hexo-util / lib / decode_url.js View on Github external
const decodeURL = str => {
  if (parse(str).protocol) {
    const parsed = new URL(str);

    // Exit if input is a data url
    if (parsed.origin === 'null') return str;

    // TODO: refactor to `url.format()` once Node 8 is dropped
    const url = parsed.toString().replace(parsed.hostname, toUnicode(parsed.hostname));
    return safeDecodeURI(url);
  }

  return safeDecodeURI(str);
};
github hexojs / hexo-util / lib / encode_url.js View on Github external
const encodeURL = str => {
  if (parse(str).protocol) {
    const parsed = new URL(str);

    // Exit if input is a data url
    if (parsed.origin === 'null') return str;

    parsed.search = encodeURI(safeDecodeURI(parsed.search));
    // preserve IDN
    // TODO: refactor to url.format() once Node 8 EOL
    return parsed.toString().replace(parsed.hostname, toUnicode(parsed.hostname));
  }

  return encodeURI(safeDecodeURI(str));
};

punycode

A robust Punycode converter that fully complies to RFC 3492 and RFC 5891, and works on nearly all JavaScript platforms.

MIT
Latest version published 1 year ago

Package Health Score

74 / 100
Full package analysis