What is @types/punycode?
@types/punycode provides TypeScript type definitions for the punycode library, which is used for encoding and decoding Unicode strings to and from the ASCII-compatible Punycode representation. This is particularly useful for handling internationalized domain names (IDNs).
What are @types/punycode's main functionalities?
Encode a Unicode string to Punycode
This feature allows you to encode a Unicode string into its Punycode representation. This is useful for converting internationalized domain names to a format that can be used in DNS queries.
const punycode = require('punycode');
const input = 'mañana';
const output = punycode.encode(input);
console.log(output); // 'maana-pta'
Decode a Punycode string to Unicode
This feature allows you to decode a Punycode string back into its original Unicode representation. This is useful for converting Punycode domain names back to their readable form.
const punycode = require('punycode');
const input = 'maana-pta';
const output = punycode.decode(input);
console.log(output); // 'mañana'
Convert a domain name to ASCII
This feature converts a Unicode domain name to its ASCII-compatible Punycode representation. This is useful for preparing internationalized domain names for DNS resolution.
const punycode = require('punycode');
const input = 'mañana.com';
const output = punycode.toASCII(input);
console.log(output); // 'xn--maana-pta.com'
Convert a domain name to Unicode
This feature converts a Punycode domain name back to its Unicode representation. This is useful for displaying internationalized domain names in a readable format.
const punycode = require('punycode');
const input = 'xn--maana-pta.com';
const output = punycode.toUnicode(input);
console.log(output); // 'mañana.com'
Other packages similar to @types/punycode
idna-uts46-hx
The idna-uts46-hx package provides similar functionality for handling internationalized domain names (IDNs) by implementing the UTS #46 standard. It offers more comprehensive handling of IDNs compared to punycode, including normalization and validation.
Installation
npm install --save @types/punycode
Summary
This package contains type definitions for punycode (https://mths.be/punycode).
Details
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/punycode.
export function decode(input: string): string;
export function encode(input: string): string;
export function toUnicode(input: string): string;
export function toASCII(input: string): string;
export namespace ucs2 {
function decode(string: string): number[];
function encode(array: ReadonlyArray<number>): string;
}
export const version: string;
Additional Details
- Last updated: Tue, 07 Nov 2023 09:09:39 GMT
- Dependencies: none
Credits
These definitions were written by Dmitry Guketlev.