How to use the punycode/.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 brave / browser-laptop / js / lib / baseDomain.js View on Github external
module.exports.getBaseDomain = function (hostname) {
  // decode punycode if exists
  if (hostname.indexOf('xn--') >= 0 &&
    checkASCII(hostname)) {
    try {
      hostname = punycode.toUnicode(hostname)
    } catch (e) {
      console.error('punnycode.toUnicode() failure:', e)
    }
  }

  let baseDomain = cachedBaseDomain.get(hostname)
  if (baseDomain) {
    return baseDomain
  }

  // search through PSL
  var prevDomains = []
  var curDomain = hostname
  var nextDot = curDomain.indexOf('.')
  var tld = 0
  var suffix

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

77 / 100
Full package analysis