Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/crypto-utils/uid-safe
URL and cookie safe UIDs
https://github.com/crypto-utils/uid-safe
javascript nodejs uid
Last synced: about 2 months ago
JSON representation
URL and cookie safe UIDs
- Host: GitHub
- URL: https://github.com/crypto-utils/uid-safe
- Owner: crypto-utils
- License: mit
- Created: 2014-06-18T09:01:07.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2021-02-18T02:28:45.000Z (over 3 years ago)
- Last Synced: 2024-07-13T00:49:11.430Z (2 months ago)
- Topics: javascript, nodejs, uid
- Language: JavaScript
- Size: 55.7 KB
- Stars: 144
- Watchers: 9
- Forks: 12
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: HISTORY.md
- License: LICENSE
Awesome Lists containing this project
README
# uid-safe
[![NPM Version][npm-image]][npm-url]
[![NPM Downloads][downloads-image]][downloads-url]
[![Node.js Version][node-version-image]][node-version-url]
[![Build Status][travis-image]][travis-url]
[![Test Coverage][coveralls-image]][coveralls-url]URL and cookie safe UIDs
Create cryptographically secure UIDs safe for both cookie and URL usage.
This is in contrast to modules such as [uid2](https://www.npmjs.com/package/uid2)
whose UIDs are actually skewed due to the use of `%` and unnecessarily
truncate the UID. Use this if you could still use UIDs with `-` and `_` in
them.## Installation
```sh
$ npm install uid-safe
```## API
```js
var uid = require('uid-safe')
```### uid(byteLength, callback)
Asynchronously create a UID with a specific byte length. Because `base64`
encoding is used underneath, this is not the string length. For example,
to create a UID of length 24, you want a byte length of 18.```js
uid(18, function (err, string) {
if (err) throw err
// do something with the string
})
```### uid(byteLength)
Asynchronously create a UID with a specific byte length and return a
`Promise`.**Note**: To use promises in Node.js _prior to 0.12_, promises must be
"polyfilled" using `global.Promise = require('bluebird')`.```js
uid(18).then(function (string) {
// do something with the string
})
```### uid.sync(byteLength)
A synchronous version of above.
```js
var string = uid.sync(18)
```## License
[MIT](LICENSE)
[npm-image]: https://img.shields.io/npm/v/uid-safe.svg
[npm-url]: https://npmjs.org/package/uid-safe
[node-version-image]: https://img.shields.io/node/v/uid-safe.svg
[node-version-url]: https://nodejs.org/en/download/
[travis-image]: https://img.shields.io/travis/crypto-utils/uid-safe/master.svg
[travis-url]: https://travis-ci.org/crypto-utils/uid-safe
[coveralls-image]: https://img.shields.io/coveralls/crypto-utils/uid-safe/master.svg
[coveralls-url]: https://coveralls.io/r/crypto-utils/uid-safe?branch=master
[downloads-image]: https://img.shields.io/npm/dm/uid-safe.svg
[downloads-url]: https://npmjs.org/package/uid-safe