karaca-tech/string-mask

There is no license information available for the latest version (v0.1.1) of this package.

v0.1.1 2024-09-28 19:46 UTC

This package is not auto-updated.

Last update: 2024-12-21 21:08:53 UTC


README

String Mask

Latest Version on Packagist GitHub Tests Action Status GitHub Tests Action Status Total Downloads

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!