Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jaytaph/shortid
ShortID generator that serves as an alternative for UUIDs
https://github.com/jaytaph/shortid
Last synced: 22 days ago
JSON representation
ShortID generator that serves as an alternative for UUIDs
- Host: GitHub
- URL: https://github.com/jaytaph/shortid
- Owner: jaytaph
- License: mit
- Created: 2017-05-04T15:11:29.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-05-04T15:11:46.000Z (over 7 years ago)
- Last Synced: 2023-07-15T14:27:22.503Z (over 1 year ago)
- Size: 13.7 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
A simple short ID generator as an alternative for UUIDs
This package is based on the blogpost: https://eager.io/blog/how-long-does-an-id-need-to-be/
and others.Usage:
composer require noxlogic/shortid
In your code:
$id = ShortId::generate();
Or a bit more in control:$generator = new Gmp();
$encoder = new Base58();
$id = ShortId::generate($generator, $encoder);# Generators
These are the actual generators that converts the generated number. This can be done in multiple ways but by
leveraging extensions like GMP (and possibly BCMATH) should speed up generation. Currently there is a plain generator
and a GMP generator. When possible, the shortner will use GMP when available.
# Encoders
This will convert the actual number into something that can be used on your website by encoding the data. There are
two: base64, which will encode in a generic way, and base58 encoder, which will compact the number even a bit more. It
will also generate only url-safe numbers by not using some url-unsafe characters that base64 uses.