All Projects → hidehalo → Nanoid Php

hidehalo / Nanoid Php

Licence: mit
PHP implementation of Nanoid, secure URL-friendly unique ID generator

Projects that are alternatives of or similar to Nanoid Php

electron-request
Zero-dependency, Lightweight HTTP request client for Electron or Node.js
Stars: ✭ 45 (-85.71%)
Mutual labels:  lightweight
Hyperhtml
A Fast & Light Virtual DOM Alternative
Stars: ✭ 2,872 (+811.75%)
Mutual labels:  lightweight
Air Light
WordPress starter theme - designed to be minimal, lightweight and easy for all kinds of WordPress projects. Public Roadmap: https://favro.com/organization/3b45e73eaf083f68fefef368/c1dd2d4a99d6723904d2e763
Stars: ✭ 285 (-9.52%)
Mutual labels:  lightweight
lighttp
Lightweight asynchronous HTTP/WS client/server
Stars: ✭ 22 (-93.02%)
Mutual labels:  lightweight
Lightweight Segmentation
Lightweight models for real-time semantic segmentation(include mobilenetv1-v3, shufflenetv1-v2, igcv3, efficientnet).
Stars: ✭ 261 (-17.14%)
Mutual labels:  lightweight
Yaku
A lightweight promise library
Stars: ✭ 276 (-12.38%)
Mutual labels:  lightweight
LongUI
Lightweight C++ GUI Library 轻量级C++图形界面库
Stars: ✭ 149 (-52.7%)
Mutual labels:  lightweight
Light 4j
A fast, lightweight and more productive microservices framework
Stars: ✭ 3,303 (+948.57%)
Mutual labels:  lightweight
Gortal
🚪A super lightweight jumpserver service developed using the Go language. 一个使用 Go 语言开发的,超级轻量的跳板机服务。
Stars: ✭ 262 (-16.83%)
Mutual labels:  lightweight
Libwebsockets
canonical libwebsockets.org networking library
Stars: ✭ 3,314 (+952.06%)
Mutual labels:  lightweight
TTInputVisibilityController
Lightweight controller to keep your inputs visible when the keyboard is presented.
Stars: ✭ 21 (-93.33%)
Mutual labels:  lightweight
Framework
Swoole, PSR-15, PSR-7, PSR-11 lightweight modular anti-framework for REST micro-services.
Stars: ✭ 259 (-17.78%)
Mutual labels:  lightweight
Gopa
[WIP] GOPA, a spider written in Golang, for Elasticsearch. DEMO: http://index.elasticsearch.cn
Stars: ✭ 277 (-12.06%)
Mutual labels:  lightweight
jsonlint
Lightweight command-line tool for validating JSON
Stars: ✭ 27 (-91.43%)
Mutual labels:  lightweight
Stagesepx
detect stages in video automatically
Stars: ✭ 293 (-6.98%)
Mutual labels:  lightweight
brisk-ioc
fast light brisk ioc/di container on nodejs; Node下快速 轻量的IoC/DI容器,依赖注入,配合装饰器使用
Stars: ✭ 12 (-96.19%)
Mutual labels:  lightweight
Infini Gateway
INFINI-GATEWAY(极限网关), a high performance and lightweight gateway written in golang, for elasticsearch and his friends.
Stars: ✭ 272 (-13.65%)
Mutual labels:  lightweight
Autocomplete.js
Simple autocomplete pure vanilla Javascript library.
Stars: ✭ 3,428 (+988.25%)
Mutual labels:  lightweight
Trace4j
基于注解的轻量级java流程跟踪工具
Stars: ✭ 302 (-4.13%)
Mutual labels:  lightweight
Simple Php Router
Simple, fast and yet powerful PHP router that is easy to get integrated and in any project. Heavily inspired by the way Laravel handles routing, with both simplicity and expand-ability in mind.
Stars: ✭ 279 (-11.43%)
Mutual labels:  lightweight

Nanoid-php

Build Status

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

Safe. It uses cryptographically strong random APIs and guarantees a proper distribution of symbols.

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

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.

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

Install

Via Composer

$composer require hidehalo/nanoid-php

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).

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

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

Alphabet must contain 256 symbols or less. Otherwise, the generator will not be secure.

Custom Random Bytes Generator

# 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.

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

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

Examples

Please see Examples for more information on detailed usage.

Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

$composer test

Contributing

Please see CONTRIBUTING and CODE_OF_CONDUCT for details.

Notice

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

Credits

License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].