punycode
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Punycode.js is a powerful JavaScript library that serves as a Punycode converter, fully adhering to both RFC 3492 and RFC 5891 standards. This robust script operates efficiently across nearly all JavaScript platforms. Punycode performs encoding and decoding, transforming a string of Unicode symbols into a Punycode string of ASCII symbols and vice versa. For instance, using its functionality, 'mañana' can be encoded into 'maana-pta' or decoded back into its original form.
To begin utilizing Punycode.js, install the package via npm using npm install punycode --save
. Be aware that within Node.js, to import the userland Punycode module (rather than core one), use require('punycode/')
. You can then efficiently use punycode.decode(string)
, punycode.encode(string)
, punycode.toUnicode(input)
, and punycode.toASCII(input)
functions to handle the conversions between Unicode and Punycode. Here's a quick example of how to use punycode.decode and punycode.encode:
const punycode = require('punycode/');
// decode a domain name part
console.log(punycode.decode('maana-pta')); // outputs 'mañana'
// encode a domain name part
console.log(punycode.encode('mañana')); // outputs 'maana-pta'
For domain name conversions, use the punycode.toUnicode(input)
and punycode.toASCII(input)
functions.
// decode a domain name
console.log(punycode.toUnicode('xn--maana-pta.com')); // outputs 'mañana.com'
// encode a domain name
console.log(punycode.toASCII('mañana.com')); // outputs 'xn--maana-pta.com'
The library also features punycode.ucs2.decode(string)
and punycode.ucs2.encode(codePoints)
functions for operations involving Unicode code points.
For comprehensive details on usage, consult the library's API section in the Punycode.js GitHub page. The page offers complete documentation, providing insightful explanations and code samples for each function and feature. This open-source project is actively maintained, ensuring up-to-date information and prompt responses to issues and inquiries.