UNPKG

656 BJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.unique = unique;
7var BASE = 16;
8var INDEX = 0;
9/**
10 * Generate an identifier from
11 * - customizable prefix
12 * - hexadecimal timestap
13 * - local incrementor
14 * that is
15 * - cheap
16 * - platform agnostic
17 * - unique enough to prevent accidental collision
18 *
19 * @param {string} [prefix=zs]
20 * @return {string}
21 */
22
23function unique() {
24 var prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'zs';
25 var hexadecimalTimestamp = new Date().getTime().toString(BASE);
26 var index = INDEX++;
27 return [prefix, hexadecimalTimestamp, index].join('-');
28}
\No newline at end of file