philiprehberger_string_ext 0.1.1
philiprehberger_string_ext: ^0.1.1 copied to clipboard
String extension methods for case conversion, truncation, masking, and validation
philiprehberger_string_ext #
String extension methods for case conversion, truncation, masking, and validation
Requirements #
- Dart >= 3.6
Installation #
Add to your pubspec.yaml:
dependencies:
philiprehberger_string_ext: ^0.1.0
Then run:
dart pub get
Usage #
import 'package:philiprehberger_string_ext/string_ext.dart';
print('hello world'.titleCase); // Hello World
print('helloWorld'.snakeCase); // hello_world
print('Hello World'.truncate(5)); // Hello...
print('user@example.com'.isEmail); // true
Case Conversion #
'hello'.capitalized // => 'Hello'
'hello world'.titleCase // => 'Hello World'
'hello world'.camelCase // => 'helloWorld'
'helloWorld'.snakeCase // => 'hello_world'
'helloWorld'.kebabCase // => 'hello-world'
Truncation & Masking #
'Hello World'.truncate(5) // => 'Hello...'
'Hello World'.truncate(5, ellipsis: '…') // => 'Hello…'
'4111111111111111'.mask(start: 4, end: 12) // => '4111********1111'
'hello'.reversed // => 'olleh'
'hello world foo'.words // => ['hello', 'world', 'foo']
Validation #
'user@example.com'.isEmail // => true
'https://example.com'.isUrl // => true
'12345'.isNumeric // => true
' '.isBlank // => true
API #
| Member | Type | Description |
|---|---|---|
capitalized |
String |
Capitalize the first letter |
titleCase |
String |
Capitalize first letter of each word |
camelCase |
String |
Convert to camelCase |
snakeCase |
String |
Convert to snake_case |
kebabCase |
String |
Convert to kebab-case |
truncate(maxLength, {ellipsis}) |
String |
Truncate with ellipsis |
mask({start, end, char}) |
String |
Mask characters in range |
reversed |
String |
Reverse the string |
words |
List<String> |
Split into words by whitespace |
isEmail |
bool |
Whether string is a valid email |
isUrl |
bool |
Whether string is a valid URL |
isNumeric |
bool |
Whether string is numeric only |
isBlank |
bool |
Whether string is empty or whitespace |
Development #
dart pub get
dart analyze --fatal-infos
dart test
Support #
If you find this project useful: