Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xxczaki/attoid
Secure URL-friendly unique string ID generator in <8 LOC
https://github.com/xxczaki/attoid
attoid crypto cuid hacktoberfest id nano-id nanoid random-id random-string secure-random-string shortid unique-string uuid uuid-v4 uuid4 uuidv4
Last synced: about 1 month ago
JSON representation
Secure URL-friendly unique string ID generator in <8 LOC
- Host: GitHub
- URL: https://github.com/xxczaki/attoid
- Owner: xxczaki
- License: mit
- Created: 2020-10-13T21:07:38.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2020-12-28T02:17:19.000Z (about 4 years ago)
- Last Synced: 2024-11-08T11:56:26.264Z (about 2 months ago)
- Topics: attoid, crypto, cuid, hacktoberfest, id, nano-id, nanoid, random-id, random-string, secure-random-string, shortid, unique-string, uuid, uuid-v4, uuid4, uuidv4
- Language: TypeScript
- Homepage:
- Size: 58.6 KB
- Stars: 15
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- Funding: .github/funding.yml
- License: license
Awesome Lists containing this project
README
# Atto ID
> Secure URL-friendly unique string ID generator in ~8 LOC.
[![Build Status](https://github.com/xxczaki/attoid/workflows/CI/badge.svg)](https://github.com/xxczaki/attoid/actions?query=workflow%3ACI)
[![Coverage Status](https://coveralls.io/repos/github/xxczaki/attoid/badge.svg?branch=master)](https://coveralls.io/github/xxczaki/attoid?branch=master)
[![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/xojs/xo)This module generates secure, URL-friendly and truly random IDs. It was inspired mainly by [Nano ID](https://github.com/ai/nanoid). It uses the new [`crypto.randomInt`](https://nodejs.org/api/crypto.html#crypto_crypto_randomint_min_max_callback) method introduced in Node.js v14.10.0. Besides limited compatibility, the performance is also relatively low in comparison with similar libraries (about 20k ops/sec).
---
## Highlights
- Tiny size (<8 LOC)
- Same default ID length as in Nano ID
- Bigger default dictionary (includes 2 additional characters - `~` and `.`)
- Uses the truly random Crypto API
- URL-friendly
- Ability to customize dictionary
- Well tested
- Written in TypeScript## Install
```
$ npm install attoid
```## Usage
```js
import {attoid} from 'attoid';attoid(); // => V_SiU1mrfle.wZD9YbBQ
```## API
### attoid(length?, dictionary?)
Returns a random string.
##### length
Type: `number`\
Default: `21`Length of the generated string.
##### dictionary
Type: `string`\
Default: `aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ1234567890-._~`Custom dictionary, from which the string should be generated.
## License
MIT © [Antoni Kepinski](https://kepinski.me)