https://github.com/rolandjitsu/uid
Random UIDs for the web
https://github.com/rolandjitsu/uid
browser javascript typescript uid
Last synced: about 2 months ago
JSON representation
Random UIDs for the web
- Host: GitHub
- URL: https://github.com/rolandjitsu/uid
- Owner: rolandjitsu
- Created: 2018-08-29T13:02:33.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2020-09-06T04:48:00.000Z (almost 6 years ago)
- Last Synced: 2026-03-30T07:59:12.417Z (3 months ago)
- Topics: browser, javascript, typescript, uid
- Language: TypeScript
- Size: 120 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# UID Generator
> A small package for generating cryptographically secure UIDs in the browser, safe for both cookie and URL usage.
[](https://www.npmjs.com/package/crypto-uid)
[](https://github.com/rolandjitsu/uid/actions?query=workflow%3ATest)
[](https://coveralls.io/github/rolandjitsu/uid?branch=master)
This package is a mirror of [uid-safe](https://github.com/crypto-utils/uid-safe), but meant to be used in a browser env.
Additionally, it comes bundled with [TypeScript](https://www.typescriptlang.org) typings.
# Table of Contents
* [Installation](#installation)
* [Usage](#usage)
* [Browser Support](#browser-support)
* [Contribute](#contribute)
### Installation
----------------
You can install this package from [NPM](https://www.npmjs.com):
```bash
npm add crypto-uid
```
Or with [Yarn](https://yarnpkg.com/en):
```bash
yarn add crypto-uid
```
#### CDN
For CDN, you can use [unpkg](https://unpkg.com):
[https://unpkg.com/crypto-uid/dist/bundles/crypto-uid.umd.min.js](https://unpkg.com/crypto-uid/dist/bundles/crypto-uid.umd.min.js)
The global namespace for crypto-uid is `cryptoUid`:
```js
const id = cryptoUid(6);
```
### Usage
---------
#### ES6
Generate a random UID:
```ts
import uid from 'crypto-uid';
const id = uid(6);
```
#### CommonJS
Generate a random UID:
```ts
const uid = require('crypto-uid');
const id = uid(6);
```
### Browser Support
-------------------
You can expect this lib to run wherever [Web Crypto API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API) is supported.
### Contribute
--------------
If you wish to contribute, please use the following guidelines:
* Use [Conventional Commits](https://conventionalcommits.org)
* Use `[ci skip]` in commit messages to skip a build