carvinglabs/code-generator

Provide a simple way to generate unique codes based on a RegExp.

v1.0.0 2017-02-16 15:50 UTC

This package is not auto-updated.

Last update: 2019-08-14 07:29:28 UTC


README

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

code-generator is a tool allowing you to generatate random codes based on a RegExp. In addition, you can make it unique and compare it to an existing Dataset.

Install

Via Composer

$ composer require carvinglabs/code-generator

Usage

  • Generate a simple code :
$codeGenerator = new CodeGenerator();
$code = $codeGenerator->generate(); // return 'AZER1234' for instance
  • Generate a code based on a custom RegExp :
$codeGenerator = new CodeGenerator();
$codeGenerator->setRules('([0-9]{4,4})');
$code = $codeGenerator->generate(); // return '1234' for instance
  • Generate an unique code :
$existingCodes = ['AZER1234', 'QSDF5678', 'WXCV3456'];
$codeGenerator = new CodeGenerator();
$code = $codeGenerator->generateUnique($existingCodes); // return 'REZA4321' for instance

Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Security

If you discover any security related issues, please email julien.bonvarlet@carvinglabs.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.