# custom-unique

> Generate custom and random unique strings

Latest version **1.0.6** (published 2017-12-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install custom-unique
pnpm add custom-unique
yarn add custom-unique
bun add custom-unique
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2017-12-27 |
| First published | 2017-12-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | jvitoroc |
| Maintainers | jvitoroc |
| Keywords | unique, random, custom, config, md5, crypto, key, token |

## Links

- npm: https://www.npmjs.com/package/custom-unique
- Repository: https://github.com/jvitoroc/custom-unique
- Homepage: https://github.com/jvitoroc/custom-unique#readme
- Issues: https://github.com/jvitoroc/custom-unique/issues
- npm.io page: https://npm.io/package/custom-unique

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 1.0.6 (latest) — 2017-12-27
- 1.0.5 — 2017-12-27
- 1.0.4 — 2017-12-27
- 1.0.3 — 2017-12-27
- 1.0.2 — 2017-12-27
- 1.0.1 — 2017-12-27
- 1.0.0 — 2017-12-27

## README

# custom-unique
Generate custom and random unique strings.

`npm install --save custom-unique`

## Examples
```javascript
var customUnique = require('custom-unique');

var gen = customUnique.compile({n: '1n4n68dma98560d', a: '1234567890'}, '((n))-((a))-((n))-((a))');
gen(); // 08nmd5mn5a6141d-2335291955-6068n84a989n0a5-4633515073
gen(); // dnm85966885n60n-3751472625-4mdnd8606081854-5222094747

var serialGen = customUnique.compile({c: '1234567890', b: 'abcedfgh'}, '((c)4)-((b)4)-((c)4)-((b)4)');
serialGen(); // 4830-heea-0194-gfeg
serialGen(); // 5593-chcg-3889-ccch
```

## API
#### function compile(config, format)
Creates a function that returns random strings.

**Return value:** function ([prefix][, suffix])
* `config (Object)` An object containing all values that will replace the corresponding placeholders in `format`.
* `format (String)` An string containing placeholders that will be replaced by random values composed by `config`.

## Explanation
The keys of `config` can be referenced in `format`. Those references will be replaced by a random string composed of chars from the value of that key.

To reference a property from `config`, use the following syntax in format: `((property))`.

This reference will be replaced by a random value composed of chars from `config[property]` , and it will have the length equal to `config[property]`.

```javascript
var config = {ex: '123'};
var format = '--((ex))--';

var gen = customUnique.compile(config, format);
gen(); // --231--
gen(); // --312--
```
You can define the length yourself using this syntax: `((property)length)`.

```javascript
var config = {ex: '123'};
var format = '--((ex)10)--';

var gen = customUnique.compile(config, format);
gen(); // --1132222311--
gen(); // --1312313113--
```
You may add prefixes and suffixes to the generated strings.
```javascript
var config = {ex: '123'};
var format = '--((ex)10)--';

var gen = customUnique.compile(config, format);
gen('ID-'); // ID---2212122311--
gen('', 'HI'); // --1312313113--HI
gen('PHOTO', 'HI'); // PHOTO--1312313113--HI
```

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