Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A robust Punycode converter that fully complies to RFC 3492 and RFC 5891.

License

NotificationsYou must be signed in to change notification settings

mathiasbynens/punycode.js

Repository files navigation

Punycode.js is a robust Punycode converter that fully complies toRFC 3492 andRFC 5891.

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

This project wasbundled with Node.js fromv0.6.2+ untilv7 (soft-deprecated).

This project provides a CommonJS module that uses ES2015+ features and JavaScript module, which work in modern Node.js versions and browsers. For the old Punycode.js version that offers the same functionality in a UMD build with support for older pre-ES2015 runtimes, including Rhino, Ringo, and Narwhal, seev1.4.1.

Installation

Vianpm:

npm install punycode --save

InNode.js:

⚠️ Note that userland modules don't hide core modules.For example,require('punycode') still imports the deprecated core module even if you executednpm install punycode.Userequire('punycode/') to import userland modules rather than core modules.

constpunycode=require('punycode/');

API

punycode.decode(string)

Converts a Punycode string of ASCII symbols to a string of Unicode symbols.

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

punycode.encode(string)

Converts a string of Unicode symbols to a Punycode string of ASCII symbols.

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

punycode.toUnicode(input)

Converts a Punycode string representing a domain name or an email address to Unicode. Only the Punycoded parts of the input will be converted, i.e. it doesn’t matter if you call it on a string that has already been converted to Unicode.

// decode domain namespunycode.toUnicode('xn--maana-pta.com');// → 'mañana.com'punycode.toUnicode('xn----dqo34k.com');// → '☃-⌘.com'// decode email addressespunycode.toUnicode('джумла@xn--p-8sbkgc5ag7bhce.xn--ba-lmcq');// → 'джумла@джpумлатест.bрфa'

punycode.toASCII(input)

Converts a lowercased Unicode string representing a domain name or an email address to Punycode. Only the non-ASCII parts of the input will be converted, i.e. it doesn’t matter if you call it with a domain that’s already in ASCII.

// encode domain namespunycode.toASCII('mañana.com');// → 'xn--maana-pta.com'punycode.toASCII('☃-⌘.com');// → 'xn----dqo34k.com'// encode email addressespunycode.toASCII('джумла@джpумлатест.bрфa');// → 'джумла@xn--p-8sbkgc5ag7bhce.xn--ba-lmcq'

punycode.ucs2

punycode.ucs2.decode(string)

Creates an array containing the numeric code point values of each Unicode symbol in the string. WhileJavaScript uses UCS-2 internally, this function will convert a pair of surrogate halves (each of which UCS-2 exposes as separate characters) into a single code point, matching UTF-16.

punycode.ucs2.decode('abc');// → [0x61, 0x62, 0x63]// surrogate pair for U+1D306 TETRAGRAM FOR CENTRE:punycode.ucs2.decode('\uD834\uDF06');// → [0x1D306]

punycode.ucs2.encode(codePoints)

Creates a string based on an array of numeric code point values.

punycode.ucs2.encode([0x61,0x62,0x63]);// → 'abc'punycode.ucs2.encode([0x1D306]);// → '\uD834\uDF06'

punycode.version

A string representing the current Punycode.js version number.

For maintainers

How to publish a new release

  1. On themain branch, bump the version number inpackage.json:

    npm version patch -m'Release v%s'

    Instead ofpatch, useminor ormajoras needed.

    Note that this produces a Git commit + tag.

  2. Push the release commit and tag:

    git push&& git push --tags

    Our CI then automatically publishes the new release to npm, under both thepunycode andpunycode.js names.

Author

twitter/mathias
Mathias Bynens

License

Punycode.js is available under theMIT license.

About

A robust Punycode converter that fully complies to RFC 3492 and RFC 5891.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp