Overview
The Strings package is an evolution of work originally produced by Andrew Mezoni.
The purpose of the Strings package is to provide:
A collection of useful String functions to complement to the core String class.
where viable, directly extend the String class with methods such as String.right, String.left.
provide a safer environment when working with nullable Strings (String?)
wrappers for each of the core String methods which are safe to use with a nullable String?.
A core objective of the Strings package is to never 'throw' or return an error but to make a best effort to process the passed data.
Sponsored by OnePub
Help support Strings by supporting OnePub, the private Dart repository.
OnePub allows you to privately share Dart packages across your Team and with your customers.
Try it for free and publish your first private package in seconds.
Publish a private package in five commands:
flutter pub global activate onepub
onepub login
cd <my package>
onepub pub private
dart pub publish
namespace
Strings takes a slightly non-conventional approach by defining all of the exposed methods as statics in the Strings class rather than defining them as global functions.
We took this approach as it provides better support when using auto-completion in an IDE.
Can't remember the name of a Strings function?
Type Strings.
and your IDE will show you the complete list of methods exposed by the Strings package.
To use a Strings method use Strings.xxxx
NNBD
Dart best practice encourages us to use String rather than String? but the reality is that at times we still need to handle nullable strings.
The Strings package looks to make using String? types as easy as possible whilst reducing bugs and maintenance overheads.
If you need to trim a String? you could write:
or use Strings and write:
The null check operator (!) is dangerous, because if the value is null then our app just crashed.
The Strings method is slightly less verbose than the '??' technique, but more importantly it removes the need for the conditional expression which is both hard to read and like every conditional expression, has the potential to introduce bugs into your code base.
Utility methods
The methods in the Strings package is loosely group into the following types:
Blank - test if a string is blank
Empty - test if a string is empty
Parts - break/merge a string into parts
Style - style a string with different cases etc
Type - check if a string is a given type
Extensions to String
The Strings package also provides a set of extension functions for the String class:
Contributing
We welcome contributions to the Strings package.
The best way to get involved is to head over to the Strings github repository and fork the project.
If you are looking to add a new method please conform to the current code layout.
Unit Tests
Before any new functions are added to the library they need reasonable set of unit tests.
Last updated