# ts-randomstring

> A library used for generating random strings, written in TypeScript and based on Node.

Latest version **1.0.8** (published 2021-08-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install ts-randomstring
pnpm add ts-randomstring
yarn add ts-randomstring
bun add ts-randomstring
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.8 |
| Published | 2021-08-03 |
| First published | 2021-07-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 24.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | doubletruth |
| Maintainers | doubletruth |
| Keywords | TypeScript, Node, Random String, Crypto |

## Links

- npm: https://www.npmjs.com/package/ts-randomstring
- Repository: https://github.com/doubletruth/ts-randomstring
- Homepage: https://github.com/doubletruth/ts-randomstring#readme
- Issues: https://github.com/doubletruth/ts-randomstring/issues
- npm.io page: https://npm.io/package/ts-randomstring

## Dependencies (1)

- [@types/node](https://npm.io/package/@types/node.md) ^16.3.1

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.0.8 (latest) — 2021-08-03
- 1.0.7 — 2021-08-03
- 1.0.6 — 2021-07-15
- 1.0.5 — 2021-07-15
- 1.0.4 — 2021-07-10
- 1.0.3 — 2021-07-10
- 1.0.2 — 2021-07-10
- 1.0.1 — 2021-07-10
- 1.0.0 — 2021-07-10

## README

# ts-randomstring

A simple Node-based library written in TypeScript that allows you to generate random strings (a)synchronously.

## Installation
NPM
```
npm install ts-randomstring
```

Yarn
```
yarn add ts-randomstring
```

## Usage
Consumers are able to use both synchronous and asynchrounous (via callback) functions and class methods.

Exported function examples:
```
import { generateRandomString } from "ts-randomstring/lib"

// Synchronously generate a random string via function.
const randomString = generateRandomString();
```
```
import { generateRandomStringAsync } from "ts-randomstring/lib"

// Asynchronously generate a random string via function and callback.
generateRandomStringAsync((error, randomString) => {
    if (error === undefined) {
        // Use your randomly generated string.
        console.log(randomString);
    } else {
        // Handle error.
        console.log(error);
    }
});
```
Exported class method examples:

```
import { RandomString } from "ts-randomstring/lib"

// Synchronously generate a random string via class method.
const randomString = new RandomString();
const rand = randomString.generate();
```

```
import { RandomString } from "ts-randomstring/lib"

// Asynchronously generate a random string via class method callback.
const randomString = new RandomString();
randomString.generateAsync((error, rand) => {
    if (error === undefined) {
        // Use your randomly generated string.
        console.log(rand);
    } else {
        // Handle error.
        console.log(error);
    }
});
```
Examples of random string options (demonstrated via functions):
```
import { generateRandomString } from "ts-randomstring/lib"

// Setting length.
const randomString = generateRandomString({
    length: 128
});
```
```
import { generateRandomString, CharacterSetType } from "ts-randomstring/lib"

// Setting length and character set.
const randomString = generateRandomString({
    length: 64,
    charSetType: CharacterSetType.Hex
});
```
```
import { generateRandomString, CharacterSetType, Capitalisation } from "ts-randomstring/lib"

// Setting length, character set, and capitalisation style.
const randomString = generateRandomString({
    length: 32,
    charSetType: CharacterSetType.Alphanumeric,
    capitalisation: Capitalisation.Uppercase
});
```

## Options in-depth

`length`: `number` (default=`32`); sets the length of the required random string

`charSetType`: `CharacterSetType` (default=`CharacterSetType.Alphanumeric`); sets the type of the character set used for random string generation.

`capitalisation`: `Capitalisation` (default=`Capitalisation.Mixed`); sets the capitalisation style of the random string.

#

Valid `CharacterSetType` and `Capitalisation` enum values:

`CharacterSetType`
- Alphanumeric
- Alphabetic
- Numeric
- Hex
- Binary
- Octal

`Capitalisation`
- Mixed
- Uppercase
- Lowercase

---
_Source: https://npm.io/package/ts-randomstring · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
