温馨提示:本站仅提供公开网络链接索引服务,不存储、不篡改任何第三方内容,所有内容版权归原作者所有
AI智能索引来源:http://www.bun.com/reference/node/punycode
点击访问原文链接

node:punycode module | API Reference | Bun

node:punycode module | API Reference | BunBuildDocsReferenceGuidesBlogDiscord/node:punycodeFdecodeFencodeFtoASCIIFtoUnicode

Search the reference...

/

BuildDocsReferenceGuidesBlogDiscord/node:punycodeFdecodeFencodeFtoASCIIFtoUnicode

Node.js module

node:punycodeThe 'node:punycode' module provides utilities for converting Unicode strings to ASCII using Punycode encoding, as defined by RFC 3492. It enables safe handling of Internationalized Domain Names (IDNs).

Functions include encode, decode, toASCII, and toUnicode.

Works in Bun

Fully implemented. 100% of Node.js's test suite passes. Note: This module is deprecated by Node.js.

function decode(string: string): string;The punycode.decode() method converts a Punycode string of ASCII-only characters to the equivalent string of Unicode codepoints.

punycode.decode('maana-pta'); // 'mañana' punycode.decode('--dqo34k'); // '☃-⌘' function encode(string: string): string;The punycode.encode() method converts a string of Unicode codepoints to a Punycode string of ASCII-only characters.

punycode.encode('mañana'); // 'maana-pta' punycode.encode('☃-⌘'); // '--dqo34k' function toASCII(domain: string): string;The punycode.toASCII() method converts a Unicode string representing an Internationalized Domain Name to Punycode. Only the non-ASCII parts of the domain name will be converted. Calling punycode.toASCII() on a string that already only contains ASCII characters will have no effect.

// encode domain names punycode.toASCII('mañana.com'); // 'xn--maana-pta.com' punycode.toASCII('☃-⌘.com'); // 'xn----dqo34k.com' punycode.toASCII('example.com'); // 'example.com' function toUnicode(domain: string): string;The punycode.toUnicode() method converts a string representing a domain name containing Punycode encoded characters into Unicode. Only the Punycode encoded parts of the domain name are be converted.

// decode domain names punycode.toUnicode('xn--maana-pta.com'); // 'mañana.com' punycode.toUnicode('xn----dqo34k.com'); // '☃-⌘.com' punycode.toUnicode('example.com'); // 'example.com' Type definitionsinterface ucs2

Resources

ReferenceDocsGuidesDiscordMerch StoreGitHubBlog 

Toolkit

RuntimePackage managerTest runnerBundlerPackage runner

Project

Bun 1.0Bun 1.1Bun 1.2Bun 1.3RoadmapContributingLicenseBaked with ❤️ in San Francisco

We're hiring →

智能索引记录