vy_string_utils 0.3.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 62

A collection of string utilities.

These utilities simplifies some formatting needs. The main methods are:

  • cut() -> Cuts a String at the required length if bigger or returns the origin otherwise.

  • cutAndAlign() -> Cuts a String or pads it right or left with a certain character to the required length if needed

  • preserveOnlyChars() -> returns a String containing only the required characters. Optionally the removed characters can be substituted by a placeholder.

  • splitInLines() -> split a sentence in lines of the required length based on a given separator.

  • capitalize() -> Capitalize the first character of the string and lowercase the others.

  • onlyContainsDigits() -> returns true if the string contains only digits.

  • onlyContainsAlpha() -> returns true if the string only contains alpha characters (RegExp [a-zA-Z])

  • isDartIdentifier() -> returns true if the characters starting at the given position are a valid Dart identifier.

  • getDartIdentifier() -> return the valid Dart identifier (if any) at certain position in a source string.

    All these methods are presented also as extensions.

license.

Usage #

A simple usage example:

import 'package:vy_string_utils/vy_string_utils.dart';

main() {
  print('please cut'.cutAndAlign(15, paddingChar: '*')); // 'please cut*****'

  print('main'.capitalize()); // 'Main'

  print('1953'.onlyContainsDigits()); // true
}

Features and bugs #

Please file feature requests and bugs at the issue tracker.

Changelog #

0.3.2 #

  • Completed all the extension methods

0.3.0 #

  • Moved to Dart 2.7.1
  • Created extension methods

0.2.1 #

  • Fixed a minor error in splitInLines() method

0.2.0 #

  • Removed source analysis classes. They will be part of a new package.
  • Changed the splitInLines() Method. Now it is possible to set a different length for the first line.

0.1.1 #

  • Fixed a minor error during source analysis

0.1.0 #

  • Initial version

example/example.dart

import 'package:vy_string_utils/vy_string_utils.dart';

void main() {
  print('please cut here this string'.cut(15)); //'please cut here'
  print('please cut'.cut(15)); // 'please cut'

  print('please cut here this string'.cutAndAlign(15)); // 'please cut here'

  print('please cut'.cutAndAlign(15)); // 'please cut     '
  print('please cut'.cutAndAlign(15, leftAlign: false)); // '     please cut'
  print('please cut'.cutAndAlign(15, paddingChar: '*')); // 'please cut*****'
  print('please cut'.cutAndAlign(15,
      leftAlign: false, paddingChar: '*')); //   '*****please cut'

  print('5,769.34'.preserveOnlyChars('0123456789')); // '576934'
  print('5,769.34'
      .preserveOnlyChars('0123456789', replacementChar: ' ')); // '5 769 34'

  print('main'.capitalize()); // 'Main'
  print('THETA'.capitalize()); // 'Theta'
  print('jOhN'.capitalize()); // 'John'

  print(unfilled(null)); // true
  print(unfilled('')); // true
  print(unfilled('verify')); // false

  print(filled(null)); // false
  print(filled('')); // false
  print(filled('verify')); // true

  print('27-12'.onlyContainsDigits()); // false
  print('1953'.onlyContainsDigits()); // true

  print(onlyContainsAlpha('Value')); //  true
  print(onlyContainsAlpha('en_US')); // false

  List<String> parts;
  parts = 'mollit est consequatur'.splitInLines(11);
  print(parts.length); // 2
  print(parts.first); // 'mollit est '
  print(parts.last); // 'consequatur'
}

Use this package as a library

1. Depend on it

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


dependencies:
  vy_string_utils: ^0.3.2

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:vy_string_utils/vy_string_utils.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
31
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
62
Learn more about scoring.

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

  • Dart: 2.7.1
  • pana: 0.13.6

Health suggestions

Format lib/src/string_extension.dart.

Run dartfmt to format lib/src/string_extension.dart.

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.1 <3.0.0
Dev dependencies
pedantic ^1.8.0
test ^1.6.0