搜索插件、代码仓与 APP 分类

GitHub 代码仓dropbear-software/punycoder

punycoder

Punycoder 是一个经过充分测试的 Dart 实现,符合 RFC 3492 Punycode 规范

punycoder 项目封面
星标
3
复刻
2
最近推送(UTC)
2026年2月26日
项目状态
未归档

原始 README

以下为英文项目原文快照,最新内容请访问 GitHub。

pub package License: MIT Open in Firebase Studio

Punycoder

A pure Dart implementation of Punycode (RFC 3492) with support for mixed-case annotation and technical errata.

Punycoder provides an idiomatic and high-performance way to encode and decode Punycode strings, which are essential for Internationalized Domain Names in Applications (IDNA).

Features

  • Standard Compliant: Faithful implementation of the Bootstring algorithm specifically for Punycode.
  • Mixed-Case Annotation: Full support for Appendix A, preserving original character casing during the encoding process.
  • Cross-Platform: Fully compatible with both the Dart VM and Web (transpiled via dart2js or ddc).
  • Native Performance: Uses StringBuffer and Unicode-aware Runes for efficient processing.
  • Idiomatic API: Implements Codec<String, String> for seamless integration with dart:convert.

Getting started

Add punycoder to your pubspec.yaml dependencies:

dependencies:
  punycoder: ^0.3.0

Then, import the library in your Dart code:

import 'package:punycoder/punycoder.dart';

Usage

Basic Encoding and Decoding
// Encode a Unicode string to Punycode
final encoded = punycode.encode('münchen'); // mnchen-3ya

// Decode a Punycode string back to Unicode
final decoded = punycode.decode('mnchen-3ya'); // münchen
IDNA Helpers (Domains and Emails)

Punycoder provides high-level helpers for handling Internationalized Domain Names (IDN) and email addresses.

// Convert a Unicode domain to ASCII (Punycode)
final domainAscii = domainToAscii('mañana.com'); // xn--maana-pta.com

// Convert back to Unicode
final domainUnicode = domainToUnicode('xn--maana-pta.com'); // mañana.com

// Supports IDNA2003 separators (。 . 。)
final alternative = domainToAscii('mañana\u3002com'); // xn--maana-pta.com

// Convert an email address
final emailAscii = emailToAscii('джумла@джpумлатест.bрфa'); 
// джумла@xn--p-8sbkgc5ag7bhce.xn--ba-lmcq

By default, domainToAscii and emailToAscii perform validation (label length, domain length, invalid characters). You can disable this if needed:

final raw = domainToAscii('ab--c.com', validate: false);
Preserving Mixed Case

By default, Punycoder uses Appendix A annotations to preserve casing:

final encoded = punycode.encode('MÜnchen'); // Mnchen-3yA
final decoded = punycode.decode('Mnchen-3yA'); // MÜnchen

Additional information

Contributions

Contributions are welcome! Please feel free to open issues or submit pull requests on the GitHub repository.

Reporting Issues

If you encounter any bugs or have feature requests, please file them through the issue tracker.

License

This project is licensed under the MIT License - see the LICENSE file for details.

dropbear-software GitHub avatar
GitHub 作者

dropbear-software ↗

语言DartNix

分类

此仓库发布的插件

如何选择适合项目的代码仓?

先按使用场景筛选,再比较项目活跃情况,最后到原始仓库核对使用要求。

  1. 通过仓库名、作者或描述搜索,再按技术分类缩小范围。
  2. 结合星标、复刻与最近推送比较项目;星标反映社区关注,不代表质量保证。
  3. 使用前在 GitHub 核对 README、许可证与 Issues。

来源与维护

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗