Coder Social home page Coder Social logo

mgrajcarek / uuid-shortener Goto Github PK

View Code? Open in Web Editor NEW
146.0 6.0 6.0 120 KB

A simple RFC 4122 UUID shortener library. Change your 36 chars long ID into it's shorter equivalent.

License: MIT License

PHP 100.00%
short-uuids uuid-generators uuid shortuuid shortener-library

uuid-shortener's Introduction

UUID SHORTENER

Minimum PHP Version Build Status

A simple shortener library for RFC 4122 compatible UUIDs. Change your 36 chars long UUID into it's shorter equivalent.

Key concept and inspiration taken from pascaldevink/shortuuid library. If you just need to generate short UUIDs the easy way, I encourage you to check his work. If you expect perfomance, this library uses ext-gmp to speed up the process.

Installation

The preferred method of installation is via Packagist and Composer. Run the following command to install the package and add it as a requirement to your project's composer.json:

composer require keiko/uuid-shortener

Example

<?php
require 'vendor/autoload.php';

use Keiko\Uuid\Shortener\Dictionary;
use Keiko\Uuid\Shortener\Shortener;

// Generate UUID, for example using Ramsey/UUID
$uuid = '806d0969-95b3-433b-976f-774611fdacbb';
$shortener = Shortener::make(
    Dictionary::createUnmistakable() // or pass your own characters set
);

echo $shortener->reduce($uuid); // output: mavTAjNm4NVztDwh4gdSrQ

You can reverse the process and expand your short UUID back to hexadecimal value.

<?php
require 'vendor/autoload.php';

use Keiko\Uuid\Shortener\Dictionary;
use Keiko\Uuid\Shortener\Shortener;

$shortUuid = 'mavTAjNm4NVztDwh4gdSrQ';
$shortener = Shortener::make(
    Dictionary::createUnmistakable()
);

echo $shortener->expand($shortUuid); // output: 806d0969-95b3-433b-976f-774611fdacbb 

Performance

In order to get optimal performance from this library, it is endorsed that you run ext-gmp in your system.

Keiko\Uuid\Shortener\Shortener::make() will pick a GMP-compatible shortener or a fallback shortener based on your system dependencies.

Plans

UUID Shortener is not connected with any UUID generator library. It also does not generate new UUIDs. It has only one purpose - transform your long, hexadecimal IDs (no matter where they come from), into a shorter and easier to read set of characters. In the near future additional service will be added, which will be able to generate short UUIDs in companion with most popular UUID generators.

uuid-shortener's People

Contributors

frankverhoeven avatar marmichalski avatar mgrajcarek avatar ocramius avatar peter279k avatar trearcul avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

uuid-shortener's Issues

BigNumber replacement?

Package moontoast/math is abandoned, you should avoid using it. Use brick/math instead.

Any plans on switching to brick/math instead?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.