Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
cbschuld committed Apr 11, 2020
1 parent f485121 commit 7e7b60f
Show file tree
Hide file tree
Showing 11 changed files with 2,229 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/vendor/
.idea
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
language: php

dist: trusty

php:
- 7.4
- 7.3

install: composer install

script: phpunit --configuration phpunit.xml.dist
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2020 Chris Schuld <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,51 @@
# 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

```sh
composer require cbschuld/php-uuid-base58
```

## Usage

```php

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

```sh
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.

![performance graph](https://raw.githubusercontent.com/cbschuld/uuid-base58/master/__tests__/performance.png)

## Base58 Alphabet

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

[Additional information on Base-58](https://en.wikipedia.org/wiki/Base58).

## Contact

**Twitter** - @cbschuld

## Contributing

Yes, thank you! Please update the docs and tests and add your name to the package.json file.
23 changes: 23 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "cbschuld/php-uuid-base58",
"description": "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.",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Chris Schuld",
"email": "[email protected]"
}
],
"autoload": {
"psr-4": {
"cbschuld\\": "src/"
}
},
"require": {
"ramsey/uuid": "^4.0"
},
"require-dev": {
"phpunit/phpunit": "^9.1"
}
}
Loading

0 comments on commit 7e7b60f

Please sign in to comment.