FFFF GitHub - habiburrahman30/flutter_strings Β· GitHub
[go: up one dir, main page]

Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

1 Commit

Folders and files

Repository files navigation

flutter_strings

pub package License: MIT

A comprehensive Flutter/Dart package that brings Laravel's powerful string manipulation methods to your Flutter applications. With 100+ methods for string transformation, validation, extraction, and manipulation!

✨ Features

  • 🎯 100+ String Methods - Complete implementation of Laravel 12.x Str helper
  • πŸ”— Two APIs - Use static methods or fluent chainable API
  • πŸ’ͺ Type Safe - Full Dart type safety with null safety support
  • πŸ“¦ Zero Configuration - Works out of the box
  • πŸ§ͺ Well Tested - Comprehensive test coverage
  • πŸ“š Well Documented - Every method is documented with examples

πŸ“¦ Installation

Add this to your package's pubspec.yaml file:

dependencies:
  flutter_strings: ^1.0.0

Then run:

flutter pub get

πŸš€ Quick Start

import 'package:flutter_strings/flutter_strings.dart';

void main() {
  // Static API
  final slug = Str.slug('Laravel 5 Framework');
  print(slug); // 'laravel-5-framework'

  // Fluent API (method chaining)
  final result = 'hello world'
      .str
      .title()
      .append('!')
      .toString();
  print(result); // 'Hello World!'
}

πŸ“– Usage Examples

Case Transformations

// Convert to different cases
Str.camel('foo_bar');        // 'fooBar'
Str.snake('fooBar');         // 'foo_bar'
Str.kebab('fooBar');         // 'foo-bar'
Str.studly('foo_bar');       // 'FooBar'
Str.title('a nice title');   // 'A Nice Title'

// Using fluent API
'foo_bar'.str.camel().toString();    // 'fooBar'
'fooBar'.str.snake().toString();     // 'foo_bar'

String Extraction

// Extract parts of strings
Str.after('App\\Http\\Controllers\\Controller', '\\');
// 'Http\\Controllers\\Controller'

Str.afterLast('App\\Http\\Controllers\\Controller', '\\');
// 'Controller'

Str.before('This is my name', 'my name');
// 'This is '

Str.between('This is my name', 'This', 'name');
// ' is my '

Validation Methods

// Check string properties
Str.isJson('{"name":"John"}');              // true
Str.isUuid('a0a2a2d2-0b87-4a18-83f2-2529882be2de');  // true
Str.isUrl('https://flutter.dev');           // true
Str.contains('Hello World', 'World');       // true
Str.startsWith('Hello World', 'Hello');     // true

String Manipulation

// Limit string length
Str.limit('The quick brown fox jumps over the lazy dog', 20);
// 'The quick brown fox...'

// Mask sensitive data
Str.mask('taylor@example.com', '*', 3);
// 'tay****************'

// Generate URL-friendly slugs
Str.slug('Laravel 5 Framework');
// 'laravel-5-framework'

// Pad strings
Str.padLeft('James', 10, '-');   // '-----James'
Str.padRight('James', 10, '-');  // 'James-----'

Real-World Examples

Email Processing

final email = 'user@example.com';

// Mask email for privacy
final masked = Str.mask(email, '*', 4, 7);
print(masked); // 'user*******com'

// Extract domain
final domain = Str.after(email, '@');
print(domain); // 'example.com'

// Using fluent API
final processed = email
    .str
    .before('@')
    .ucfirst()
    .append(' User')
    .toString();
print(processed); // 'User User'

URL Generation

final title = 'How to Build Amazing Flutter Apps';

// Create SEO-friendly URL slug
final slug = Str.slug(title);
print(slug); // 'how-to-build-amazing-flutter-apps'

final url = 'https://myblog.com/posts/${slug}';
print(url);
// 'https://myblog.com/posts/how-to-build-amazing-flutter-apps'

Text Formatting

final rawText = '  hello_world  ';

// Clean and format text
final formatted = rawText
    .str
    .squish()         // Remove extra whitespace
    .headline()       // Convert to headline case
    .wrap('"')        // Wrap with quotes
    .toString();
print(formatted); // '"Hello World"'

🎯 Complete Method List

Case Conversion

  • camel(), snake(), kebab(), studly(), title(), lower(), upper(), ucfirst(), lcfirst(), headline()

String Extraction

  • after(), afterLast(), before(), beforeLast(), between(), betweenFirst(), charAt(), excerpt(), limit(), substr(), take(), words()

Validation

  • contains(), containsAll(), doesntContain(), startsWith(), endsWith(), is(), isAscii(), isJson(), isUrl(), isUuid(), isUlid(), isEmpty(), isNotEmpty()

String Manipulation

  • append(), prepend(), finish(), start(), chopStart(), chopEnd(), mask(), padLeft(), padRight(), padBoth(), remove(), repeat(), replace(), replaceFirst(), replaceLast(), reverse(), slug(), squish(), stripTags(), swap(), trim(), ltrim(), rtrim(), wrap(), unwrap()

Pluralization

  • plural(), singular()

Encoding/Decoding

  • toBase64(), fromBase64(), hash(), toHtmlString(), toUri()

Utility

  • length(), position(), random(), split(), wordCount(), match(), matchAll()

Conditional Methods (Fluent API)

  • when(), whenContains(), whenEmpty(), whenNotEmpty(), whenStartsWith(), whenEndsWith(), and many more...

πŸ”₯ Advanced Usage

Method Chaining

final result = 'taylor_otwell'
    .str
    .replace('_', ' ')
    .title()
    .append(' - Creator of Laravel')
    .toString();
print(result); // 'Taylor Otwell - Creator of Laravel'

Conditional Execution

final text = 'user@example.com';

final result = text
    .str
    .whenContains('@', (s) => 'Email: $s')
    .whenIsUrl((s) => 'URL: $s')
    .whenEmpty((s) => 'Empty string')
    .toString();
print(result); // 'Email: user@example.com'

πŸ“š Documentation

For detailed API documentation, visit pub.dev documentation.

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

⭐ Show Your Support

If you like this package, please give it a ⭐ on pub.dev!

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0