ngubin / key-n
Generation a unique short key from the number.
v1.0
2020-07-09 01:40 UTC
Requires
- php: >=7.2
Requires (Dev)
- phpunit/phpunit: ^8.0
This package is not auto-updated.
Last update: 2024-09-27 19:45:29 UTC
README
Generating a unique short key from the number.
A simple library for converting a number into a string key and back. You can use to shorten long numbers to unique keys.
Example Usage
Creating a key from a number:
You can only encode an integer greater than or equal to one.
use KeyN\Make\Key62; $instance = Key62::make(); $key = $instance->encode(100000);
Set your own character set to create keys:
use KeyN\Make\Key62; $characters = 'wWpJbH8nIDed1Evq5OcToF2ZuXsayz7RrtP490ixSKC3GM6gYkNVhBUQmLlfAj'; $instance = Key62::make($characters); $key = $instance->encode(100000);
Getting the number from the key:
You can decode the key if all of its characters are in the class set.
use KeyN\Make\Key62; $instance = Key62::make(); $number = $instance->decode('Gh1a');
License
This project is released under the MIT License.
© 2020 Nik Gubin, All rights reserved.