convertx 0.1.4

convertx #

Dart CI codecov pub package dart>=2.6

Static extension methods for converting between different data representations.

Getting started #

Add this to your package's pubspec.yaml file:

dependencies:
  convertx: ^0.1.4

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); // &lt;strong&gt;Romeo &amp; Juliet&lt;&#47;strong&gt;

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.

0.1.4 #

  • Fix non-function-syntax style code.

0.1.3 #

  • Fix README.

0.1.2 #

  • Update test dependency.

0.1.1 #

  • Fix docs.

0.1.0 #

  • First release.

example/convertx_example.dart

import 'package:convertx/convertx.dart';

void main() {
  // 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); // &lt;strong&gt;Romeo &amp; Juliet&lt;&#47;strong&gt;

  // ASCII codec
  print('Hello World!'.toAsciiByteList().toAsciiString()); // Hello World!

  // Latin1 codec
  print('¡Hola Mundo!'.toLatin1ByteList().toLatin1String()); // ¡Hola Mundo!

  // UTF-8 codec
  print('你好,世界!'.toUtf8ByteList().toUtf8String()); // 你好,世界!
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  convertx: ^0.1.4

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:convertx/convertx.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
11
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
55
Learn more about scoring.

We analyzed this package on Feb 12, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.5

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0-dev <3.0.0
Dev dependencies
pedantic ^1.8.0
test ^1.9.4