Socket
Socket
Sign inDemoInstall

punycode

Package Overview
Dependencies
0
Maintainers
2
Versions
31
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    punycode

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


Version published
Maintainers
2
Install size
398 kB
Created

Package description

What is punycode?

The punycode npm package is a robust library for encoding and decoding Unicode with Punycode. It's useful for internationalization and handling Unicode domain names and email addresses.

What are punycode's main functionalities?

Encoding to Punycode

Converts a Unicode string to a Punycode string (ASCII). Mainly used for domain names.

punycode.encode('mañana') // => 'maana-pta'

Decoding from Punycode

Converts a Punycode string (ASCII) back to a Unicode string. Useful for displaying human-readable text.

punycode.decode('maana-pta') // => 'mañana'

Unicode to ASCII conversion for domain names

Converts a Unicode domain name to an ASCII-compatible encoding (ACE) domain name.

punycode.toASCII('español.example.com') // => 'xn--espaol-zwa.example.com'

ASCII to Unicode conversion for domain names

Converts an ASCII-compatible encoding (ACE) domain name back to a Unicode domain name.

punycode.toUnicode('xn--espaol-zwa.example.com') // => 'español.example.com'

Other packages similar to punycode

Readme

Source

Punycode.js

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

This JavaScript library is the result of comparing, optimizing and documenting different open-source implementations of the Punycode algorithm:

This project is bundled with Node.js v0.6.2+.

Installation and usage

In a browser:

<script src="punycode.js"></script>

Via npm (only required for Node.js releases older than v0.6.2):

npm install punycode

In Narwhal, Node.js, and RingoJS:

var punycode = require('punycode');

In Rhino:

load('punycode.js');

Using an AMD loader like RequireJS:

require(
  {
    'paths': {
      'punycode': 'path/to/punycode'
    }
  },
  ['punycode'],
  function(punycode) {
    console.log(punycode);
  }
);

Usage example:

// encode/decode domain names
punycode.toASCII('mañana.com'); // 'xn--maana-pta.com'
punycode.toUnicode('xn--maana-pta.com'); // 'mañana.com'
punycode.toASCII('☃-⌘.com'); // 'xn----dqo34k.com'
punycode.toUnicode('xn----dqo34k.com'); // '☃-⌘.com'

// encode/decode domain name parts
punycode.encode('mañana'); // 'maana-pta'
punycode.decode('maana-pta'); // 'mañana'
punycode.encode('☃-⌘'); // '--dqo34k'
punycode.decode('--dqo34k'); // '☃-⌘'

Full API documentation is available.

Feel free to fork if you see possible improvements!

Unit tests & code coverage

After cloning this repository, run npm install --dev to install the dependencies needed for Punycode.js development and testing. You may want to install Istanbul globally using npm install istanbul -g.

Once that’s done, you can run the unit tests in Node using npm test or node tests/tests.js. To run the tests in Rhino, Ringo, Narwhal, and web browsers as well, use grunt test.

To generate the code coverage report, use grunt cover.

Authors

Contributors

License

Punycode.js is dual licensed under the MIT and GPL licenses.

Keywords

FAQs

Last updated on 31 Mar 2013

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc