zeba_academy_string_utils 1.0.0
zeba_academy_string_utils: ^1.0.0 copied to clipboard
A collection of dependency-free string manipulation utilities for Dart and Flutter applications.
Zeba Academy String Utils #
A lightweight, dependency-free collection of string manipulation utilities for Dart and Flutter applications.
zeba_academy_string_utils provides practical helpers for whitespace cleanup, truncation, repetition, character validation, word counting, safe substring operations, normalization, and more.
โจ Features #
- ๐งน Trim leading and trailing whitespace
- ๐งฝ Clean and collapse consecutive whitespace
- ๐ซ Remove all whitespace
- โ๏ธ Safely truncate strings
- ๐ Repeat strings
- ๐ค Check alphabetic strings
- ๐ข Check numeric strings
- ๐ค๐ข Check alphanumeric strings
- ๐ Detect uppercase characters
- ๐ก Detect lowercase characters
- ๐ข Detect digits
- โ Detect whitespace
- ๐ Count words
- ๐ก๏ธ Safely extract substrings
- ๐งน Normalize strings
- ๐ก Convert strings to lowercase
- ๐ Convert strings to uppercase
- โฌ Detect blank strings
- ๐งฉ Convenient
Stringextensions - ๐ฆ Zero external runtime dependencies
- ๐ฏ Simple and predictable API
๐ฆ Installation #
Add the package to your pubspec.yaml:
dependencies:
zeba_academy_string_utils: ^1.0.0
Then run:
flutter pub get
๐ Quick Start #
Import the package:
import 'package:zeba_academy_string_utils/zeba_academy_string_utils.dart';
You can use the static utility API:
final cleaned = ZebaStringUtils.cleanWhitespace(
' Hello Flutter World ',
);
print(cleaned);
// Hello Flutter World
Or use the convenient string extensions:
final result = ' HELLO WORLD '.zNormalize();
print(result);
// hello world
๐งฐ API Reference #
Whitespace Utilities #
trim #
Removes leading and trailing whitespace.
final result = ZebaStringUtils.trim(' Hello World ');
print(result);
// Hello World
Extension:
final result = ' Hello World '.zTrim();
cleanWhitespace #
Trims the string and collapses consecutive whitespace characters into a single space.
final result = ZebaStringUtils.cleanWhitespace(
' Hello beautiful world ',
);
print(result);
// Hello beautiful world
Extension:
final result = ' Hello World '.zCleanWhitespace();
removeWhitespace #
Removes all whitespace characters.
final result = ZebaStringUtils.removeWhitespace(
'Hello World',
);
print(result);
// HelloWorld
Extension:
final result = 'Hello World'.zRemoveWhitespace();
โ๏ธ Truncation #
truncate #
Truncates a string to the specified maximum length.
final result = ZebaStringUtils.truncate(
'Hello Flutter Developer',
12,
);
print(result);
// Hello Fl...
The default ellipsis is:
...
You can provide a custom ellipsis:
final result = ZebaStringUtils.truncate(
'Hello Flutter Developer',
12,
ellipsis: 'โฆ',
);
print(result);
// Hello Fluttโฆ
Extension:
final result = 'Hello Flutter Developer'.zTruncate(12);
Edge Cases #
If the string is already within the requested length, it is returned unchanged.
ZebaStringUtils.truncate('Hello', 10);
// Hello
A negative maxLength throws an ArgumentError.
๐ Repetition #
repeat #
Repeats a string the requested number of times.
final result = ZebaStringUtils.repeat(
'ab',
3,
);
print(result);
// ababab
Extension:
final result = 'ab'.zRepeat(3);
A count of zero returns an empty string:
ZebaStringUtils.repeat('Hello', 0);
// ''
A negative count throws an ArgumentError.
๐ค Character Checks #
isAlphabetic #
Checks whether a string contains only alphabetic ASCII characters.
ZebaStringUtils.isAlphabetic('Hello');
// true
ZebaStringUtils.isAlphabetic('Hello123');
// false
Extension:
'Hello'.zIsAlphabetic;
isNumeric #
Checks whether a string contains only numeric ASCII digits.
ZebaStringUtils.isNumeric('12345');
// true
ZebaStringUtils.isNumeric('123abc');
// false
Extension:
'12345'.zIsNumeric;
isAlphanumeric #
Checks whether a string contains only alphabetic and numeric ASCII characters.
ZebaStringUtils.isAlphanumeric('Flutter123');
// true
ZebaStringUtils.isAlphanumeric('Flutter 123');
// false
Extension:
'Flutter123'.zIsAlphanumeric;
hasUppercase #
Checks whether the string contains at least one uppercase character.
ZebaStringUtils.hasUppercase('helloWorld');
// true
ZebaStringUtils.hasUppercase('hello');
// false
Extension:
'helloWorld'.zHasUppercase;
hasLowercase #
Checks whether the string contains at least one lowercase character.
ZebaStringUtils.hasLowercase('HELLOw');
// true
ZebaStringUtils.hasLowercase('HELLO');
// false
Extension:
'HELLOw'.zHasLowercase;
hasDigit #
Checks whether the string contains at least one digit.
ZebaStringUtils.hasDigit('Flutter123');
// true
ZebaStringUtils.hasDigit('Flutter');
// false
Extension:
'Flutter123'.zHasDigit;
hasWhitespace #
Checks whether the string contains at least one whitespace character.
ZebaStringUtils.hasWhitespace('Hello World');
// true
ZebaStringUtils.hasWhitespace('Hello');
// false
Extension:
'Hello World'.zHasWhitespace;
๐ Word Counting #
wordCount #
Counts words separated by whitespace.
final count = ZebaStringUtils.wordCount(
'Hello beautiful Flutter world',
);
print(count);
// 4
Multiple whitespace characters are handled automatically:
ZebaStringUtils.wordCount(
'Hello beautiful\nFlutter\tworld',
);
// 4
Empty or whitespace-only strings return 0.
Extension:
final count = 'Hello Flutter Developer'.zWordCount;
๐ก๏ธ Safe Substring #
safeSubstring #
Extracts a substring without throwing when the requested indexes exceed the string's boundaries.
final result = ZebaStringUtils.safeSubstring(
'Hello World',
0,
100,
);
print(result);
// Hello World
A negative start index is safely clamped:
ZebaStringUtils.safeSubstring(
'Hello',
-10,
3,
);
// Hel
An index beyond the string length returns an empty string:
ZebaStringUtils.safeSubstring(
'Hello',
100,
);
// ''
You can also omit the end index:
ZebaStringUtils.safeSubstring(
'Hello World',
6,
);
// World
Extension:
final result = 'Hello World'.zSafeSubstring(0, 100);
๐งน Normalization #
normalize #
Normalizes a string by:
- Trimming leading whitespace.
- Trimming trailing whitespace.
- Collapsing consecutive whitespace.
- Converting the result to lowercase.
final result = ZebaStringUtils.normalize(
' HELLO Flutter WORLD ',
);
print(result);
// hello flutter world
Extension:
final result = ' HELLO WORLD '.zNormalize();
This is useful when comparing user input:
final first = ZebaStringUtils.normalize(' Hello World ');
final second = ZebaStringUtils.normalize('HELLO WORLD');
print(first == second);
// true
๐ก Case Conversion #
lowercase #
final result = ZebaStringUtils.lowercase('HELLO');
print(result);
// hello
Extension:
'HELLO'.zLowercase();
uppercase #
final result = ZebaStringUtils.uppercase('hello');
print(result);
// HELLO
Extension:
'hello'.zUppercase();
โฌ Blank String Checks #
isBlank #
Checks whether a string is empty after trimming whitespace.
ZebaStringUtils.isBlank('');
// true
ZebaStringUtils.isBlank(' ');
// true
ZebaStringUtils.isBlank('Hello');
// false
Extension:
' '.zIsBlank;
isNotBlank #
The opposite of isBlank.
ZebaStringUtils.isNotBlank('Hello');
// true
ZebaStringUtils.isNotBlank(' ');
// false
Extension:
'Hello'.zIsNotBlank;
๐งฉ Extension API #
The package provides convenient extensions directly on String.
import 'package:zeba_academy_string_utils/zeba_academy_string_utils.dart';
void main() {
final value = ' Hello Flutter 123 ';
print(value.zTrim());
print(value.zCleanWhitespace());
print(value.zRemoveWhitespace());
print(value.zTruncate(10));
print(value.zRepeat(2));
print(value.zIsAlphabetic);
print(value.zIsNumeric);
print(value.zIsAlphanumeric);
print(value.zHasUppercase);
print(value.zHasLowercase);
print(value.zHasDigit);
print(value.zHasWhitespace);
print(value.zWordCount);
print(value.zSafeSubstring(0, 100));
print(value.zNormalize());
print(value.zLowercase());
print(value.zUppercase());
print(value.zIsBlank);
print(value.zIsNotBlank);
}
๐ฏ Static API vs Extensions #
Both styles are supported.
Static API #
Useful when you want an explicit utility class:
ZebaStringUtils.normalize(value);
Extension API #
Useful when working directly with strings:
value.zNormalize();
Choose whichever style fits your project.
๐ Complete API #
| Method | Description |
|---|---|
trim() |
Removes surrounding whitespace |
cleanWhitespace() |
Trims and collapses whitespace |
removeWhitespace() |
Removes all whitespace |
truncate() |
Safely truncates a string |
repeat() |
Repeats a string |
isAlphabetic() |
Checks alphabetic characters |
isNumeric() |
Checks numeric characters |
isAlphanumeric() |
Checks alphanumeric characters |
hasUppercase() |
Checks for uppercase characters |
hasLowercase() |
Checks for lowercase characters |
hasDigit() |
Checks for digits |
hasWhitespace() |
Checks for whitespace |
wordCount() |
Counts words |
safeSubstring() |
Safely extracts a substring |
normalize() |
Normalizes whitespace and case |
lowercase() |
Converts to lowercase |
uppercase() |
Converts to uppercase |
isBlank() |
Checks for blank strings |
isNotBlank() |
Checks for non-blank strings |
๐งช Testing #
The package includes comprehensive tests covering:
- Whitespace handling
- Truncation
- Custom ellipsis
- String repetition
- Character validation
- Uppercase/lowercase detection
- Digit detection
- Word counting
- Safe substring boundaries
- Normalization
- Case conversion
- Blank string detection
- Extension methods
- Edge cases
- Invalid arguments
Run tests with:
flutter test
Run static analysis with:
flutter analyze
Format the project with:
dart format lib test
๐ Dependencies #
zeba_academy_string_utils has zero external runtime dependencies.
It uses only the Dart core libraries and is designed to remain lightweight and easy to integrate into existing Dart and Flutter projects.
๐ฏ Design Goals #
This package follows a few simple principles:
- Simple โ APIs should be easy to understand.
- Predictable โ Edge cases should have consistent behavior.
- Lightweight โ No unnecessary dependencies.
- Reusable โ Utilities should work across Dart and Flutter applications.
- Type-safe โ APIs should leverage Dart's type system.
- Tested โ Common and edge-case behavior should be covered by tests.
- Production-ready โ Suitable for real-world applications.
๐ค Contributing #
Contributions are welcome!
If you discover a bug, have an improvement, or want to suggest a feature:
- Fork the repository.
- Create a feature branch.
- Make your changes.
- Add or update tests.
- Run
dart format. - Run
flutter analyze. - Run
flutter test. - Submit a pull request.
Please keep contributions focused and aligned with the package's goal of providing small, reusable string utilities.
๐ License #
This project is licensed under the GNU General Public License v3.0 (GPL-3.0).
See the LICENSE file for the complete license text.
๐จโ๐ป About Me #
โจ I'm Sufyan bin Uzayr, an open-source developer passionate about building and sharing meaningful projects.
You can learn more about me and my work at sufyanism.com or connect with me on LinkedIn.
๐ Your All-in-One Learning Hub! #
๐ Explore courses and resources in coding, tech, and development at zeba.academy and code.zeba.academy.
Empower yourself with practical skills through curated tutorials, real-world projects, and hands-on experience. Level up your tech game today! ๐ปโจ
Zeba Academy is a learning platform dedicated to coding, technology, and development.
โก Visit our main site: zeba.academy
โก Explore hands-on courses and resources at code.zeba.academy
โก Check out our YouTube for more tutorials: Zeba Academy
โก Follow us on Instagram: Zeba Academy
Thank you for visiting! โค๏ธ
โญ Support #
If you find this package useful, consider giving the project a โญ on GitHub and sharing it with other Dart and Flutter developers.
Built with โค๏ธ for the Dart & Flutter community by Zeba Academy.