Package Exports
- short-unique-id
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (short-unique-id) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Short Unique ID Generator
With ES6 imports, Node.js, and browser support
This is a straight up manual transpilation to ES6 of the short-uid npm package by Ankit Kuwadekar.
Why?
The above linked repository has gone stale, no updates in the past 2 years (as of writing 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.
Instantiation (Server-side)
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();
Instantiation (Client-side)
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>
Usage
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
Development
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.
Build
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.