Last change
on this file since 84d0fbb was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
562 bytes
|
Rev | Line | |
---|
[6a3a178] | 1 | var toString = require('./toString');
|
---|
| 2 |
|
---|
| 3 | /** Used to generate unique IDs. */
|
---|
| 4 | var idCounter = 0;
|
---|
| 5 |
|
---|
| 6 | /**
|
---|
| 7 | * Generates a unique ID. If `prefix` is given, the ID is appended to it.
|
---|
| 8 | *
|
---|
| 9 | * @static
|
---|
| 10 | * @since 0.1.0
|
---|
| 11 | * @memberOf _
|
---|
| 12 | * @category Util
|
---|
| 13 | * @param {string} [prefix=''] The value to prefix the ID with.
|
---|
| 14 | * @returns {string} Returns the unique ID.
|
---|
| 15 | * @example
|
---|
| 16 | *
|
---|
| 17 | * _.uniqueId('contact_');
|
---|
| 18 | * // => 'contact_104'
|
---|
| 19 | *
|
---|
| 20 | * _.uniqueId();
|
---|
| 21 | * // => '105'
|
---|
| 22 | */
|
---|
| 23 | function uniqueId(prefix) {
|
---|
| 24 | var id = ++idCounter;
|
---|
| 25 | return toString(prefix) + id;
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | module.exports = uniqueId;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.