uid-promise

generates a cryptographically strong random uid

Usage no npm install needed!

<script type="module">
  import uidPromise from 'https://cdn.skypack.dev/uid-promise';
</script>

README

uid-promise

Creates a cryptographically secure UID with a 62 character range that can be safely used in URLs.

Usage

Firstly, install the package from npm:

npm install --save uid-promise

Then load it:

const uid = require('uid-promise');

Finally, call it:

await uid(20);

API

uid(Number len) => Promise

  • Return a Promise that resolves with a string of random characters of length len
  • len must always be provided, else the promise is rejected
  • Under the hood, crypto.randomBytes is used
  • Character set: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789

Authors