Skip to main content

convertlib 4.0.0 copy "convertlib: ^4.0.0" to clipboard
convertlib: ^4.0.0 copied to clipboard

Fast, zero-dependency codecs for Base2/8/16/32/36/45/58/62/64/85, Bech32, Punycode, percent (URL), quoted-printable, BigInt, UTF-8, and the PHC/crypt format.

example/convertlib_example.dart

import 'dart:convert' show utf8;

import 'package:convertlib/convertlib.dart';

void main() {
  var inp = [0x3, 0xF1];
  print("input => $inp");
  print('');

  print("binary => ${toBinary(inp)}");
  print('');

  print("octal => ${toOctal(inp)}");
  print('');

  print("hexadecimal => ${toHex(inp)}");
  print("hexadecimal (uppercase) => ${toHex(inp, upper: true)}");
  print('');

  print("base32 => ${toBase32(inp)}");
  print("base32 (lowercase) => ${toBase32(inp, lower: true)}");
  print("base32 (no padding) => ${toBase32(inp, padding: false)}");
  print("base32 (hex) => ${toBase32(inp, codec: Base32Codec.hex)}");
  print("base32 (z-base-32) => ${toBase32(inp, codec: Base32Codec.z)}");
  print("base32 (geohash) => ${toBase32(inp, codec: Base32Codec.geohash)}");
  print("base32 (crockford) => ${toBase32(inp, codec: Base32Codec.crockford)}");
  print("base32 (word-safe) => ${toBase32(inp, codec: Base32Codec.wordSafe)}");
  print('');

  print("base36 => ${toBase36(inp)}");
  print("base36 (upper) => ${toBase36(inp, upper: true)}");
  print("base45 => ${toBase45(inp)}");
  print("base58 => ${toBase58(inp)}");
  print("base58 (flickr) => ${toBase58(inp, codec: Base58Codec.flickr)}");
  print("base58 (ripple) => ${toBase58(inp, codec: Base58Codec.ripple)}");
  print("base62 => ${toBase62(inp)}");
  print("base62 (lowerFirst) => ${toBase62(inp, lowerFirst: true)}");
  print('');

  print("base64 => ${toBase64(inp)}");
  print("base64url => ${toBase64(inp, url: true)}");
  print("base64 (no padding) => ${toBase64(inp, padding: false)}");
  print("bcrypt => ${toBase64(inp, codec: Base64Codec.bcrypt)}");
  print("imap => ${toBase64(inp, codec: Base64Codec.imap)}");
  print("base85 => ${toBase85(inp)}");
  print("base85 (git) => ${toBase85(inp, codec: Base85Codec.git)}");
  print("bech32 => ${toBech32('hi', inp)}");
  print('');

  print("punycode => ${toPunycode('bücher')}");
  print("punycode (domain) => ${toPunycode('münchen.de', domain: true)}");
  print("fromPunycode => ${fromPunycode('xn--mnchen-3ya.de', domain: true)}");
  print("imap utf-7 => ${toImapUtf7('Entwürfe')}");
  print("fromImapUtf7 => ${fromImapUtf7('Entw&APw-rfe')}");
  print("multibase => ${toMultibase(inp, Multibase.base58Btc)}");
  print("fromMultibase => ${fromMultibase('z7paNL19xttacUY')}");
  print('');

  print("percent => ${toPercent(utf8.encode('a b/é'))}");
  print("percent (form) => ${toPercent(utf8.encode('a b+c'), form: true)}");
  print("fromPercent => ${utf8.decode(fromPercent('a%20b%2F%C3%A9'))}");
  print('');

  print("quoted-printable => ${toQuotedPrintable(utf8.encode('café = 1'))}");
  print("quoted-printable (header) => "
      "${toQuotedPrintable(utf8.encode('Grüße, Welt'), header: true)}");
  print("fromQuotedPrintable => "
      "${utf8.decode(fromQuotedPrintable('caf=C3=A9 =3D 1'))}");
  print('');

  print("utf16 => ${toUtf16('héllo')}");
  print("utf16 (BOM) => ${toUtf16('hi', codec: UTF16Codec.standard)}");
  print("fromUtf16 (LE) => "
      "${fromUtf16([0x68, 0, 0x69, 0], littleEndian: true)}");
  print("utf32 => ${toUtf32('hi')}");
  print("fromUtf32 => ${fromUtf32([0, 1, 0xF6, 0])}");
  print('');
}
5
likes
160
points
50k
downloads

Documentation

API reference

Publisher

verified publisherbitanon.dev

Weekly Downloads

Fast, zero-dependency codecs for Base2/8/16/32/36/45/58/62/64/85, Bech32, Punycode, percent (URL), quoted-printable, BigInt, UTF-8, and the PHC/crypt format.

Homepage
Repository (GitHub)
View/report issues

Topics

#encoding #base64 #base58 #base32 #hex

Funding

Consider supporting this project:

paypal.me

License

BSD-3-Clause (license)

More

Packages that depend on convertlib