string_utils_plus 0.0.1
string_utils_plus: ^0.0.1 copied to clipboard
A comprehensive and modern Dart string manipulation library using extension methods.
import 'package:flutter/material.dart';
import 'package:string_utils_plus/string_utils_plus.dart';
void main() {
final testString = 'HelloWorld Example-string_for Testing123';
print('Original: $testString');
// Casing conversions
print('camelToSnake: ${'helloWorldExample'.camelToSnake()}');
print('snakeToCamel: ${'hello_world_example'.snakeToCamel()}');
print('kebabToPascal: ${'example-string-for'.kebabToPascal()}');
print('pascalToKebab: ${'ExampleStringFor'.pascalToKebab()}');
print('titleCase: ${'this is a sample title'.titleCase()}');
// Formatting
print('Slugify: ${testString.slugify()}');
print('Truncate(15): ${testString.truncate(15)}');
print('Remove special chars: ${testString.removeSpecialChars()}');
print('Mask with defaults: ${'1234567890'.mask()}');
print(
'Normalize whitespace: ${' multiple spaces '.normalizeWhitespace()}',
);
// Validation examples
print(
'Is valid email (test@example.com): ${'test@example.com'.isValidEmail()}',
);
print(
'Is valid URL (https://example.com): ${'https://example.com'.isValidUrl()}',
);
print('Is strong password (Aa1!aaaa): ${'Aa1!aaaa'.isStrongPassword()}');
print('Is numeric (12345): ${'12345'.isNumeric()}');
print('Contains word "Example": ${testString.containsWord('Example')}');
print('Word count: ${testString.wordCount()}');
// Pluralize and singularize
print('Pluralize "city": ${'city'.pluralize()}');
print('Singularize "cities": ${'cities'.singularize()}');
// Capitalize and decapitalize
print('Capitalize "flutter": ${'flutter'.capitalize()}');
print('Decapitalize "Flutter": ${'Flutter'.decapitalize()}');
runApp(const MyApp());
}
// void main() {
//
//
//
// runApp(const MyApp());
// }
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
// TRY THIS: Try changing the color here to a specific color (to
// Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
// change color while the other colors stay the same.
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text('You have pushed the button this many times:'),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}