convertx
Static extension methods for converting between different data representations.
Getting started
Add this to your package's pubspec.yaml file:
dependencies:
convertx: ^0.2.2
Then import the following, so you can use the extensions:
import 'package:convertx/convertx.dart';
Overview
Convertx exposes the most common dart:convert
functionalities.
base64:
final base64String = 'Hello World!'.toUtf8ByteList().toBase64String();
print(base64String); // SGVsbG8gV29ybGQh
final originalString = base64String.toBase64ByteList().toUtf8String();
print(originalString); // Hello World!
JSON:
final jsonString = {'answer': 42}.toJsonString();
print(jsonString); // {"answer":42}
final originalMap = jsonString.toDecodedJson() as Map;
print(originalMap); // {answer: 42}
Escape HTML:
final html = '<strong>Romeo & Juliet</strong>'.escapeHtml();
print(html); // <strong>Romeo & Juliet</strong>
Common string codecs:
// ASCII
print('Hello World!'.toAsciiByteList().toAsciiString()); // Hello World!
// Latin1
print('¡Hola Mundo!'.toLatin1ByteList().toLatin1String()); // ¡Hola Mundo!
// UTF-8
print('你好,世界!'.toUtf8ByteList().toUtf8String()); // 你好,世界!
Contribute
To report a bug or request any feature, please create an issue.