karaca-tech / string-mask
Installs: 1 372
Dependents: 0
Suggesters: 0
Security: 0
Stars: 8
Watchers: 4
Forks: 2
Open Issues: 0
Requires
- php: ^8.2
- ext-mbstring: *
- spatie/laravel-package-tools: ^1.15
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.35
- orchestra/testbench: ^8.5
- pestphp/pest: ^2.18
- phpstan/extension-installer: ^1.1
- phpstan/phpstan: ^1.10
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
This package is not auto-updated.
Last update: 2024-11-09 20:34:14 UTC
README
String Mask
This package is a simple string masker for Laravel.
Installation
You can install the package via composer:
composer require karaca-tech/string-mask
Usage
use KaracaTech\StringMask\Facades\Mask; mask('John Doe')->keepFirstAndLastCharacter()->apply(); // J******e Mask::fullname('John Doe'); // J*** D** Mask::initials('John Doe'); // J.D. // Let's spice things up a little bit Mask::of('John Doe') ->silent() ->eachWord() ->keepFirstWord() ->keepFirstCharacter() ->then(fn(Masker $masked) => $masked->append('.')) ->apply(); // John D.
Using your own processors
All processors must be extended from KaracaTech\StringMask\Powder\Processor
abstract class.
use KaracaTech\StringMask\Powder\Processor; use KaracaTech\StringMask\MaskTarget; class MyProcessor extends Processor { public function execute(MaskTarget $string): string { // Do your magic here } } // or class ProcessorWithParams extends Processor { public function __construct(private AnotherClass $anotherClass) { } public function execute(MaskTarget $string): string { // Do your magic here } }
Then you can use your processor like this:
Mask::of('John Doe') ->using(MyProcessor::class) ->using(MyOtherProcessor::class) ->using(ProcessorWithParams::class, new AnotherClass()) ->apply();
For further examples, please check out the KaracaTech\StringMask\Concerete\Processors
namespace.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Contributions are always welcome, thanks to all of our contributors!