Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80742 views
1
var baseToString = require('../internal/baseToString');
2
3
/** Used to generate unique IDs. */
4
var idCounter = 0;
5
6
/**
7
* Generates a unique ID. If `prefix` is provided the ID is appended to it.
8
*
9
* @static
10
* @memberOf _
11
* @category Utility
12
* @param {string} [prefix] The value to prefix the ID with.
13
* @returns {string} Returns the unique ID.
14
* @example
15
*
16
* _.uniqueId('contact_');
17
* // => 'contact_104'
18
*
19
* _.uniqueId();
20
* // => '105'
21
*/
22
function uniqueId(prefix) {
23
var id = ++idCounter;
24
return baseToString(prefix) + id;
25
}
26
27
module.exports = uniqueId;
28
29