tr46
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
punycode | 2.3.1 | 7.42 kB | MIT | prod |
TR46 is a JavaScript implementation of the Unicode Technical Standard #46: Unicode IDNA Compatibility Processing. It is used to convert a string of Unicode symbols to a case-folded Punycode string of ASCII symbols and vice versa. Therefore, this popular npm package is the key to making your non-latin domain names compatible with the all-ASCII character constraints of the Domain Name System (DNS).
The TR46 package can be incorporated into your JavaScript project relatively easily. After installation, you have access to two key methods: toASCII(domainName[, options])
and toUnicode(domainName[, options])
. Here's a simple implementation example:
const tr46 = require('tr46');
let ascii = tr46.toASCII('example.com', {
checkBidi: true,
checkHyphens: true,
checkJoiners: true,
processingOption: 'nontransitional',
useSTD3ASCIIRules: true,
verifyDNSLength: true
});
let unicode = tr46.toUnicode('example.com', {
checkBidi: true,
checkHyphens: true,
checkJoiners: true,
processingOption: 'nontransitional',
useSTD3ASCIIRules: true,
verifyDNSLength: true
});
In this code, you use the toASCII()
and toUnicode()
methods to convert domain names. The methods receive two arguments: a domain name and an optional object with options for conversion.
The official documentation for the TR46 npm package is hosted on the official TR46 GitHub repository. It provides detailed descriptions of the API, including the list of available methods and options for conversion. The GitHub page is an excellent source of the most recent updates and usage examples for the TR46 package.