@rpearce/simple-uniqueid
Version:
Generate simple unique ids
58 lines (44 loc) • 2.83 kB
Markdown
# simple-uniqueid
[](#contributors)
[](https://www.npmjs.com/package/@rpearce/simple-uniqueid) [](https://www.npmjs.com/package/@rpearce/simple-uniqueid) [](https://travis-ci.org/rpearce/simple-uniqueid) [](https://coveralls.io/github/rpearce/simple-uniqueid?branch=master) [](https://codeclimate.com/github/rpearce/simple-uniqueid/maintainability)
Generate simple unique ids.
This small package relies on `Math.random().toString(16).slice(-4)` to generate
32 unique characters with an optional string prefix.
_Note: This is not a replacement for a real crypto library but is intended for
small-batch use (like HTML `id` attributes)._
## Links
* [Installation](#installation)
* [Usage](#usage)
* [All Conributors](#contributors)
* [Authors](./AUTHORS)
* [Changelog](./CHANGELOG.md)
* [Contributing](./CONTRIBUTING.md)
* [Code of Conduct](./CODE_OF_CONDUCT.md)
## Installation
```
$ npm i @rpearce/simple-uniqueid
```
or
```
$ yarn add @rpearce/simple-uniqueid
```
## Usage
```js
import uniqueId from 'simple-uniqueid'
uniqueId() // "177dc3d88508b9f8bd2e69982a7d03b8"
uniqueId('myPrefix-') // "myPrefix-64f8fca9b3d96c98a267ba58cf0f9eb8"
```
## Contributors
Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
<tr>
<td align="center"><a href="https://robertwpearce.com"><img src="https://avatars2.githubusercontent.com/u/592876?v=4" width="100px;" alt=""/><br /><sub><b>Robert Pearce</b></sub></a><br /><a href="https://github.com/rpearce/simple-uniqueid/commits?author=rpearce" title="Code">💻</a> <a href="https://github.com/rpearce/simple-uniqueid/commits?author=rpearce" title="Documentation">📖</a> <a href="#example-rpearce" title="Examples">💡</a> <a href="#ideas-rpearce" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/rpearce/simple-uniqueid/commits?author=rpearce" title="Tests">⚠️</a></td>
</tr>
</table>
<!-- markdownlint-enable -->
<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->
This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!