Strings is a collection of Dart string utilities. It adds methods to non-null String values and provides static methods on Strings for values that may be null. The package builds on work originally produced by Andrew Mezoni.
import 'package:strings/strings.dart';Use an extension method when you already have a non-null String:
'hello world'.toProperCase(); // 'Hello World'
'report.txt'.right(3); // 'txt'
'dart_vm'.toCamelCase(); // 'DartVm'Use the corresponding Strings static method when the value may be null:
String? value = null;
Strings.toProperCase(value); // ''
Strings.right(value, 4, pad: Pad.left); // ' '
Strings.isBlank(value); // trueMethods such as Strings.trim also wrap core String methods for nullable input. String already has its own non-null trim method:
Strings.trim(value); // ''
' Dart '.trim(); // 'Dart'isEmpty checks for null or zero length. isBlank also considers whitespace-only strings blank. Use orElseOnBlank when a display value needs a fallback.
Strings.isEmpty(' '); // false
Strings.isBlank(' '); // true
' '.isBlank(); // true
Strings.orElseOnBlank(' ', 'Guest'); // 'Guest'
Strings.orElse(null, 'Guest'); // 'Guest'left and right take characters from either end. Pad controls whether a short result is padded with spaces. join accepts nullable lists and elements.
'abcdef'.left(3); // 'abc'
Strings.right('one', 4, pad: Pad.left); // ' one'
Strings.join(['red', 'green'], separator: ', '); // 'red, green''hello world'.toProperCase(); // 'Hello World'
Strings.toSnakeCase('camelCase'); // 'camel_case'
'dart_vm'.toCamelCase(lower: true); // 'dartVm'
'hello'.reverse(); // 'olleh'The same import exposes other helpers for literal boundaries, counting, whitespace normalization, line endings, and nullable wrappers for core String methods. The Strings manual groups them by task and gives their null and edge-case behavior. Some operations can throw for invalid indexes or missing delimiters; consult the relevant method page.
The package is hosted at github.com/onepub-dev/strings. Contributions are welcome.
Strings is sponsored by OnePub, the private Dart repository service.