2017 © Pedro Peláez
 

library nanoid-php

A copy of nanoid in PHP

image

hidehalo/nanoid-php

A copy of nanoid in PHP

  • Friday, November 24, 2017
  • by hidehalo
  • Repository
  • 2 Watchers
  • 52 Stars
  • 4,070 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 6 Versions
  • 69 % Grown

The README.md

Nanoid-php

Build Status FOSSA Status, (*1)

A tiny (179 bytes), secure URL-friendly unique string ID generator for JavaScript, (*2)

Safe. It uses cryptographically strong random APIs and guarantees a proper distribution of symbols., (*3)

Small. Only 179 bytes (minified and gzipped). No dependencies. It uses Size Limit to control size., (*4)

Compact. It uses more symbols than UUID (A-Za-z0-9_-) and has the same number of unique options in just 21 symbols instead of 36., (*5)

Thanks awesome ai and his nanoid, this package is a copy in PHP! If you like nanoid and you want to use it in PHP, try me :D, (*6)

Install

Via Composer, (*7)

``` bash composer require hidehalo/nanoid-php, (*8)


## Usage ### Normal > The main module uses URL-friendly symbols (A-Za-z0-9_\-) and returns an ID with 21 characters (to have the same collisions probability as UUID v4). ``` php use Hidehalo\Nanoid\Client; use Hidehalo\Nanoid\GeneratorInterface; $client = new Client(); # default random generator echo $client->generateId($size = 21); # more safer random generator echo $client->generateId($size = 21, $mode = Client::MODE_DYNAMIC);

Custom Alphabet or Length

``` php echo $client->formattedId($alphabet = '0123456789abcdefg', $size = 21);, (*9)


> Alphabet must contain 256 symbols or less. > Otherwise, the generator will not be secure. ### Custom Random Bytes Generator ``` php # PS: anonymous class is new feature when PHP_VERSION >= 7.0 echo $client->formattedId($alphabet = '0123456789abcdefg', $size = 21, new class implements GeneratorInterface { /** * @inheritDoc */ public function random($size) { //TODO: implemenation ... } });

random callback must accept the array size and return an array with random numbers., (*10)

If you want to use the same URL-friendly symbols with format, you can get default alphabet from the url module:, (*11)

Please see CoreInterface::random(...) for the core random API prototype and notes, (*12)

Examples

Please see Examples for more information on detailed usage., (*13)

Change log

Please see CHANGELOG for more information on what has changed recently., (*14)

Testing

bash composer test, (*15)

Contributing

Please see CONTRIBUTING and CODE_OF_CONDUCT for details., (*16)

Notice

If you have any issues, just feel free and open it in this repository, thx!, (*17)

Credits

License

The MIT License (MIT). Please see License File for more information., (*18)

FOSSA Status, (*19)

The Versions

24/11 2017

dev-master

9999999-dev https://github.com/hidehalo/nanoid-php

A copy of nanoid in PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

hidehalo nanoid-php

24/11 2017

1.1.1

1.1.1.0 https://github.com/hidehalo/nanoid-php

A copy of nanoid in PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

hidehalo nanoid-php

16/09 2017

1.1.0

1.1.0.0 https://github.com/hidehalo/nanoid-php

A copy of nanoid in PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

hidehalo nanoid-php

14/09 2017

1.1.0-alpha

1.1.0.0-alpha https://github.com/hidehalo/nanoid-php

A copy of nanoid in PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

hidehalo nanoid-php

11/09 2017

1.0.0

1.0.0.0 https://github.com/hidehalo/nanoid-php

A copy of nanoid in PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

hidehalo nanoid-php

11/09 2017

1.0.0-alpha

1.0.0.0-alpha https://github.com/hidehalo/nanoid-php

  Sources   Download

MIT

The Requires

  • php ~5.6|~7.0

 

The Development Requires

hidehalo nanoid-php