Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sidoshi/random-string
Create cryptographically random strings on browser and node.
https://github.com/sidoshi/random-string
Last synced: about 5 hours ago
JSON representation
Create cryptographically random strings on browser and node.
- Host: GitHub
- URL: https://github.com/sidoshi/random-string
- Owner: sidoshi
- License: mit
- Created: 2019-07-04T15:48:12.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T03:41:04.000Z (almost 2 years ago)
- Last Synced: 2024-11-10T13:42:54.624Z (about 1 month ago)
- Language: TypeScript
- Homepage:
- Size: 1.22 MB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Cryptographic Random String
[![Build Status](https://travis-ci.org/sidoshi/random-string.svg?branch=master)](https://travis-ci.org/sidoshi/random-string)
Library to create cryptographically random strings.
## Install
```bash
npm i @sidoshi/random-string
```## Usage
```js
import { randomstring, charsets } from '@sidoshi/random-string';// => Alphanumeric string of length 32
console.log(randomstring());// => Alphanumeric string of length 10
console.log(randomstring(10));// => Alphabetic string of length 32
console.log(randomstring({ characters: charsets.alphabetic }));// => Numeric string of length 10
console.log(randomstring({ characters: charsets.numeric, length: 10 }));// => String of length 50 with custom character set
console.log(
randomstring({ characters: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567', length: 50 })
);// => Composing predefined charsets
console.log(
randomstring({ characters: charsets.numeric + charsets.symbols, length: 50 })
);
```## API
- `charsets` - Predefined character sets
- `alphanumeric`
- `alphabetic`
- `loweralpha`
- `upperalpha`
- `numeric`
- `hex`
- `symbols`* `randomstring(size?)` - Generate a random string of given size. (default: 30)
- `randomstring(options?)` - Generate a random string using given options
- `length` - Length of the specified string. (default: 30)
- `characters` - Character set to use to generate string (default: `charsets.alphanumeric`). Can be one of the predifined `charsets` or a custom
string. Throws if `characters.length` > 65536.## Licence
MIT © [Siddharth Doshi](https://sid.sh)