Code Monkey home page Code Monkey logo

php-uuid-base58's Introduction

php-uuid-base58

Generates a RFC4122 compliant v4 UUID and returns it encoded in base-58. This is great for creating unique IDs which only consume 22 characters of storage. Also provides base-58 encoding and decoding.

Installation

composer require cbschuld/php-uuid-base58

Usage

use cbschuld\UuidBase58;

$id = UuidBase58::id();

API

The UuidBase58 class provides three static functions

  • id - creates the RFC4122 v4 UUID encoded in base-58
  • encode(string) - encodes a base-16 string in base-58
  • decode(string) - decodes a string from base-58 to base-16

Testing

npm run test

Performance Hit

There is an additional performance hit to translate a v4 UUID into base58. In testing I found the overhead for the translation to base58 adds an additional 31%. In 100k calculation batches I found that v4 uuid calculation took 1.606s/100k vs 2.319s/100k for uuid58. Thus, 69% of the runtime was consumed calculating a v4 uuid. Additional work could be done to bring the uuid calculation internal and attempt to increase performance.

Base58 Alphabet

This solution uses the Bitcoin / IPFS hash alphabet: 123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz

Additional information on Base-58.

Contact

Twitter - @cbschuld

Contributing

Yes, thank you! Please update the docs and tests and add your name to the package.json file.

php-uuid-base58's People

Contributors

cbschuld avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

code-monkeys

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.