This package is a simple string masker for Laravel.
You can install the package via composer:
composer require karaca-tech/string-mask
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.
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.
composer test
Please see CHANGELOG for more information on what has changed recently.
Contributions are always welcome, thanks to all of our contributors!