This is a straight up manual transpilation to ES6 of the short-uid npm package by Ankit Kuwadekar.
The above linked repository has gone stale, no updates in the past 3 years (as of updating this README).
If used in a ES6 environment it fails to follow good import
standards.
Even so, the functionality is still useful. So here we are.
Install using npm:
npm install --save short-unique-id
ES6:
// Import
import ShortUniqueId from 'short-unique-id';
// Instantiate
const uid = new ShortUniqueId();
Node.js:
// Import
var ShortUniqueId = require('short-unique-id');
// Instantiate
var uid = new ShortUniqueId();
Browser:
<!-- Import -->
<script src="https://rawgit.com/jeanlescure/short-unique-id/master/dist/short-unique-id.min.js"></script>
<!-- Instantiate -->
<script>
var uid = new ShortUniqueId();
</script>
Once instantiated you can use one of two functions:
// Generate Random Unique ID of a specific length
uid.randomUUID(6); // zUvMF8
uid.randomUUID(8); // 4308OPWZ
uid.randomUUID(13); // o0Sf6rfoPOrz5
// Generate Sequential Unique ID based on internal dictionary and counter
uid.sequentialUUID(); // v
uid.sequentialUUID(); // 0
uid.sequentialUUID(); // Y
Tests run using Jasmine:
npm test
This will update the short-unique-id.js
file under ./lib
, which will then be imported by the spec and tested.
Find lint using airbnb for eslint:
npm run lint
In order to publish the latest changes you must build the distribution files:
npm run build
This will update the short-unique-id.js
file under ./lib
, which will then be minified as the short-unique-id.min.js
file under the ./dist
directory.