iri 0.1.0 copy "iri: ^0.1.0" to clipboard
iri: ^0.1.0 copied to clipboard

A Dart implementation of RFC3987 - Internationalized Resource Identifiers (IRIs)

example/iri_example.dart

import 'dart:io';

import 'package:iri/iri.dart';

void main() {
  // Create an IRI from a string containing non-ASCII characters.
  final iri = IRI('https://例子.com/pȧth?q=1'); // 例子 means "example"

  // Print the original IRI string.
  stdout.writeln('Original IRI: $iri');
  // Output: Original IRI: https://例子.com/pȧth?q=1

  // Convert the IRI to its standard URI representation.
  // The host is Punycode-encoded, and path characters are percent-encoded.
  final uri = iri.toUri();
  stdout.writeln('Converted URI: $uri');
  // Output: Converted URI: http://xn--fsqu00a.com/p%C8%A7th?q=1

  // Access components of the IRI (decoded).
  stdout.writeln('Scheme: ${iri.scheme}'); // Output: Scheme: https
  stdout.writeln('Host: ${iri.host}'); // Output: Host: 例子.com
  stdout.writeln('Path: ${iri.path}'); // Output: Path: /pȧth
  stdout.writeln('Query: ${iri.query}'); // Output: Query: q=1
}
4
likes
160
points
22
downloads

Publisher

verified publisherdropbear.dev

Weekly Downloads

A Dart implementation of RFC3987 - Internationalized Resource Identifiers (IRIs)

Repository (GitHub)
View/report issues

Topics

#rfc3987 #standards #internationalisation #unicode #iri

Documentation

API reference

License

MIT (license)

Dependencies

collection, meta, punycoder

More

Packages that depend on iri