String extension methods for case conversion, truncation, masking, and validation
dart pub add philiprehberger_string_extString extension methods for case conversion, truncation, masking, and validation
Add to your pubspec.yaml:
dependencies:
philiprehberger_string_ext: ^0.1.1
Then run:
dart pub get
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
'hello'.capitalized // => 'Hello'
'hello world'.titleCase // => 'Hello World'
'hello world'.camelCase // => 'helloWorld'
'helloWorld'.snakeCase // => 'hello_world'
'helloWorld'.kebabCase // => 'hello-world'
'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']
'user@example.com'.isEmail // => true
'https://example.com'.isUrl // => true
'12345'.isNumeric // => true
' '.isBlank // => true
| 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 |
dart pub get
dart analyze --fatal-infos
dart test
If you find this project useful: