How to use the punycode.decode 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 graalvm / graaljs / test / simple / test-punycode.js View on Github external
var common = require('../common');
var punycode = require('punycode');
var assert = require('assert');

assert.equal(punycode.encode('ü'), 'tda');
assert.equal(punycode.encode('Goethe'), 'Goethe-');
assert.equal(punycode.encode('Bücher'), 'Bcher-kva');
assert.equal(punycode.encode(
    'Willst du die Blüthe des frühen, die Früchte des späteren Jahres'),
    'Willst du die Blthe des frhen, die Frchte des spteren Jahres-x9e96lkal');
assert.equal(punycode.encode('日本語'), 'wgv71a119e');

assert.equal(punycode.decode('tda'), 'ü');
assert.equal(punycode.decode('Goethe-'), 'Goethe');
assert.equal(punycode.decode('Bcher-kva'), 'Bücher');
assert.equal(punycode.decode(
    'Willst du die Blthe des frhen, die Frchte des spteren Jahres-x9e96lkal'),
    'Willst du die Blüthe des frühen, die Früchte des späteren Jahres');
assert.equal(punycode.decode('wgv71a119e'), '日本語');

// http://tools.ietf.org/html/rfc3492#section-7.1
var tests = {
  // (A) Arabic (Egyptian)
  'egbpdaj6bu4bxfgehfvwxn':
      '\u0644\u064A\u0647\u0645\u0627\u0628\u062A\u0643\u0644\u0645\u0648' +
      '\u0634\u0639\u0631\u0628\u064A\u061F',

  // (B) Chinese (simplified)
  'ihqwcrb4cv8a8dqg056pqjye':
      '\u4ED6\u4EEC\u4E3A\u4EC0\u4E48\u4E0D\u8BF4\u4E2D\u6587',
github webpack / node-libs-browser / test / suite / node / simple / test-punycode.js View on Github external
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

var common = require('../common');
var punycode = require('punycode');
var assert = require('assert');

assert.equal(punycode.encode('ü'), 'tda');
assert.equal(punycode.encode('Goethe'), 'Goethe-');
assert.equal(punycode.encode('Bücher'), 'Bcher-kva');
assert.equal(punycode.encode(
    'Willst du die Blüthe des frühen, die Früchte des späteren Jahres'),
    'Willst du die Blthe des frhen, die Frchte des spteren Jahres-x9e96lkal');
assert.equal(punycode.encode('日本語'), 'wgv71a119e');

assert.equal(punycode.decode('tda'), 'ü');
assert.equal(punycode.decode('Goethe-'), 'Goethe');
assert.equal(punycode.decode('Bcher-kva'), 'Bücher');
assert.equal(punycode.decode(
    'Willst du die Blthe des frhen, die Frchte des spteren Jahres-x9e96lkal'),
    'Willst du die Blüthe des frühen, die Früchte des späteren Jahres');
assert.equal(punycode.decode('wgv71a119e'), '日本語');

// http://tools.ietf.org/html/rfc3492#section-7.1
var tests = {
  // (A) Arabic (Egyptian)
  'egbpdaj6bu4bxfgehfvwxn':
      '\u0644\u064A\u0647\u0645\u0627\u0628\u062A\u0643\u0644\u0645\u0648' +
      '\u0634\u0639\u0631\u0628\u064A\u061F',

  // (B) Chinese (simplified)
  'ihqwcrb4cv8a8dqg056pqjye':
github webpack / node-libs-browser / test / suite / node / simple / test-punycode.js View on Github external
assert.equal(punycode.encode('ü'), 'tda');
assert.equal(punycode.encode('Goethe'), 'Goethe-');
assert.equal(punycode.encode('Bücher'), 'Bcher-kva');
assert.equal(punycode.encode(
    'Willst du die Blüthe des frühen, die Früchte des späteren Jahres'),
    'Willst du die Blthe des frhen, die Frchte des spteren Jahres-x9e96lkal');
assert.equal(punycode.encode('日本語'), 'wgv71a119e');

assert.equal(punycode.decode('tda'), 'ü');
assert.equal(punycode.decode('Goethe-'), 'Goethe');
assert.equal(punycode.decode('Bcher-kva'), 'Bücher');
assert.equal(punycode.decode(
    'Willst du die Blthe des frhen, die Frchte des spteren Jahres-x9e96lkal'),
    'Willst du die Blüthe des frühen, die Früchte des späteren Jahres');
assert.equal(punycode.decode('wgv71a119e'), '日本語');

// http://tools.ietf.org/html/rfc3492#section-7.1
var tests = {
  // (A) Arabic (Egyptian)
  'egbpdaj6bu4bxfgehfvwxn':
      '\u0644\u064A\u0647\u0645\u0627\u0628\u062A\u0643\u0644\u0645\u0648' +
      '\u0634\u0639\u0631\u0628\u064A\u061F',

  // (B) Chinese (simplified)
  'ihqwcrb4cv8a8dqg056pqjye':
      '\u4ED6\u4EEC\u4E3A\u4EC0\u4E48\u4E0D\u8BF4\u4E2D\u6587',

  // (C) Chinese (traditional)
  'ihqwctvzc91f659drss3x8bo0yb':
      '\u4ED6\u5011\u7232\u4EC0\u9EBD\u4E0D\u8AAA\u4E2D\u6587',
github Sebmaster / tr46.js / index.js View on Github external
let { string, error } = mapChars(domainName, options);

  // 2. Normalize.
  string = string.normalize("NFC");

  // 3. Break.
  const labels = string.split(".");
  const isBidi = isBidiDomain(labels);

  // 4. Convert/Validate.
  for (const [i, origLabel] of labels.entries()) {
    let label = origLabel;
    let curProcessing = processingOption;
    if (label.startsWith("xn--")) {
      try {
        label = punycode.decode(label.substring(4));
        labels[i] = label;
      } catch (err) {
        error = true;
        continue;
      }
      curProcessing = "nontransitional";
    }

    // No need to validate if we already know there is an error.
    if (error) {
      continue;
    }
    const validation = validateLabel(label, Object.assign({}, options, {
      processingOption: curProcessing,
      checkBidi: options.checkBidi && isBidi
    }));
github sx1989827 / DOClever / node_modules / tr46 / index.js View on Github external
let { string, error } = mapChars(domainName, options);

  // 2. Normalize.
  string = string.normalize("NFC");

  // 3. Break.
  const labels = string.split(".");
  const isBidi = isBidiDomain(labels);

  // 4. Convert/Validate.
  for (const [i, origLabel] of labels.entries()) {
    let label = origLabel;
    let curProcessing = processingOption;
    if (label.startsWith("xn--")) {
      try {
        label = punycode.decode(label.substring(4));
        labels[i] = label;
      } catch (err) {
        error = true;
        continue;
      }
      curProcessing = "nontransitional";
    }

    // No need to validate if we already know there is an error.
    if (error) {
      continue;
    }
    const validation = validateLabel(label, Object.assign({}, options, {
      processingOption: curProcessing,
      checkBidi: options.checkBidi && isBidi
    }));
github graalvm / graaljs / test / simple / test-punycode.js View on Github external
'-> $1.00 <--':
      '\u002D\u003E\u0020\u0024\u0031\u002E\u0030\u0030\u0020\u003C\u002D'
};

var errors = 0;

for (var encoded in tests) {
  var decoded = tests[encoded];
  try {
    assert.equal(punycode.encode(decoded), encoded);
  } catch (e) {
    console.error('FAIL: expected %j, got %j', e.expected, e.actual);
    errors++;
  }
  try {
    assert.equal(punycode.decode(encoded), decoded);
  } catch (e) {
    console.error('FAIL: expected %j, got %j', e.expected, e.actual);
    errors++;
  }
}

assert.equal(errors, 0);
github Sebmaster / tr46.js / index.js View on Github external
const domain = labels.map(label => {
    if (label.startsWith("xn--")) {
      try {
        return punycode.decode(label.substring(4));
      } catch (err) {
        return "";
      }
    }
    return label;
  }).join(".");
  return regexes.bidiDomain.test(domain);
github sx1989827 / DOClever / node_modules / tr46 / index.js View on Github external
const domain = labels.map(label => {
    if (label.startsWith("xn--")) {
      try {
        return punycode.decode(label.substring(4));
      } catch (err) {
        return "";
      }
    }
    return label;
  }).join(".");
  return regexes.bidiDomain.test(domain);
github gchq / CyberChef / src / core / operations / Punycode.js View on Github external
runToUnicode: function(input, args) {
        const idn = args[0];

        if (idn) {
            return punycode.toUnicode(input);
        } else {
            return punycode.decode(input);
        }
    },
github eight04 / linkify-plus-plus / build-tlds.js View on Github external
			.map(tld => punycode.decode(tld.substr(4)))
	);

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