https://github.com/pirxpilot/ufid
URL friendly reasonably unique ids
https://github.com/pirxpilot/ufid
Last synced: 11 months ago
JSON representation
URL friendly reasonably unique ids
- Host: GitHub
- URL: https://github.com/pirxpilot/ufid
- Owner: pirxpilot
- Created: 2020-06-20T14:22:12.000Z (about 6 years ago)
- Default Branch: main
- Last Pushed: 2023-09-11T06:00:08.000Z (almost 3 years ago)
- Last Synced: 2025-03-03T14:48:15.443Z (over 1 year ago)
- Language: JavaScript
- Size: 12.7 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- Changelog: History.md
Awesome Lists containing this project
README
[![NPM version][npm-image]][npm-url]
[![Build Status][build-image]][build-url]
[![Dependency Status][deps-image]][deps-url]
# ufid
URL friendly reasonably unique ids.
## Install
```sh
$ npm install --save ufid
```
## Usage
Generate uids with only numbers and letters (both uppercase and lowercase):
```js
import { generator } from 'ufid';
const uid = generator({ size: 10 });
uid(); // 10 characters long
uid(); // another one - also 10 characters long
uid(8); // another one 8 characters long
```
With custom alfabet:
```js
import { generator } from 'ufid';
const uid = generator({ size: 12, alphabet: 'abc0123A' });
uid(); // 12 characters long, only a-c, 0-3, and A
```
With custom byte stream:
```js
import { generator } from 'ufid';
const byteStream = {
next: () => Math.random() * 62
};
const uid = generator({ size: 6, byteStream });
uid(); // 6 characters long using non-secure random
```
## License
MIT © [Damian Krzeminski](https://pirxpilot.me)
[npm-image]: https://img.shields.io/npm/v/ufid
[npm-url]: https://npmjs.org/package/ufid
[build-url]: https://github.com/pirxpilot/ufid/actions/workflows/check.yaml
[build-image]: https://img.shields.io/github/actions/workflow/status/pirxpilot/ufid/check.yaml?branch=main
[deps-image]: https://img.shields.io/librariesio/release/npm/ufid
[deps-url]: https://libraries.io/npm/ufid