es-toolkit 1.25.2-dev.817 → 1.25.2-dev.819

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -214,3 +214,4 @@ export { toNumber } from './util/toNumber.mjs';
214
214
  export { toPath } from './util/toPath.mjs';
215
215
  export { toSafeInteger } from './util/toSafeInteger.mjs';
216
216
  export { toString } from './util/toString.mjs';
217
+ export { uniqueId } from './util/uniqueId.mjs';
@@ -214,3 +214,4 @@ export { toNumber } from './util/toNumber.js';
214
214
  export { toPath } from './util/toPath.js';
215
215
  export { toSafeInteger } from './util/toSafeInteger.js';
216
216
  export { toString } from './util/toString.js';
217
+ export { uniqueId } from './util/uniqueId.js';
@@ -2276,6 +2276,12 @@ function toSafeInteger(value) {
2276
2276
  return clamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER);
2277
2277
  }
2278
2278
 
2279
+ let idCounter = 0;
2280
+ function uniqueId(prefix = '') {
2281
+ const id = ++idCounter;
2282
+ return `${prefix}${id}`;
2283
+ }
2284
+
2279
2285
  exports.at = zipWith.at;
2280
2286
  exports.countBy = zipWith.countBy;
2281
2287
  exports.differenceBy = zipWith.differenceBy;
@@ -2491,6 +2497,7 @@ exports.trim = trim;
2491
2497
  exports.trimEnd = trimEnd;
2492
2498
  exports.trimStart = trimStart;
2493
2499
  exports.uniq = uniq;
2500
+ exports.uniqueId = uniqueId;
2494
2501
  exports.unset = unset;
2495
2502
  exports.upperCase = upperCase;
2496
2503
  exports.without = without;
@@ -214,3 +214,4 @@ export { toNumber } from './util/toNumber.mjs';
214
214
  export { toPath } from './util/toPath.mjs';
215
215
  export { toSafeInteger } from './util/toSafeInteger.mjs';
216
216
  export { toString } from './util/toString.mjs';
217
+ export { uniqueId } from './util/uniqueId.mjs';
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Generates a unique identifier, optionally prefixed with a given string.
3
+ *
4
+ * @param {string} [prefix] - An optional string to prefix the unique identifier.
5
+ * If not provided or not a string, only the unique
6
+ * numeric identifier is returned.
7
+ * @returns {string} A string containing the unique identifier, with the optional
8
+ * prefix if provided.
9
+ *
10
+ * @example
11
+ * // Generate a unique ID with a prefix
12
+ * uniqueId('user_'); // => 'user_1'
13
+ *
14
+ * @example
15
+ * // Generate a unique ID without a prefix
16
+ * uniqueId(); // => '2'
17
+ *
18
+ * @example
19
+ * // Subsequent calls increment the internal counter
20
+ * uniqueId('item_'); // => 'item_3'
21
+ * uniqueId(); // => '4'
22
+ */
23
+ declare function uniqueId(prefix?: string): string;
24
+
25
+ export { uniqueId };
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Generates a unique identifier, optionally prefixed with a given string.
3
+ *
4
+ * @param {string} [prefix] - An optional string to prefix the unique identifier.
5
+ * If not provided or not a string, only the unique
6
+ * numeric identifier is returned.
7
+ * @returns {string} A string containing the unique identifier, with the optional
8
+ * prefix if provided.
9
+ *
10
+ * @example
11
+ * // Generate a unique ID with a prefix
12
+ * uniqueId('user_'); // => 'user_1'
13
+ *
14
+ * @example
15
+ * // Generate a unique ID without a prefix
16
+ * uniqueId(); // => '2'
17
+ *
18
+ * @example
19
+ * // Subsequent calls increment the internal counter
20
+ * uniqueId('item_'); // => 'item_3'
21
+ * uniqueId(); // => '4'
22
+ */
23
+ declare function uniqueId(prefix?: string): string;
24
+
25
+ export { uniqueId };
@@ -0,0 +1,7 @@
1
+ let idCounter = 0;
2
+ function uniqueId(prefix = '') {
3
+ const id = ++idCounter;
4
+ return `${prefix}${id}`;
5
+ }
6
+
7
+ export { uniqueId };
@@ -38,6 +38,6 @@
38
38
  * console.log(result);
39
39
  * // Output: { a: [1, 2, 3] }
40
40
  */
41
- declare function merge<T, S>(target: T, source: S): T & S;
41
+ declare function merge<T extends Record<PropertyKey, any>, S extends Record<PropertyKey, any>>(target: T, source: S): T & S;
42
42
 
43
43
  export { merge };
@@ -38,6 +38,6 @@
38
38
  * console.log(result);
39
39
  * // Output: { a: [1, 2, 3] }
40
40
  */
41
- declare function merge<T, S>(target: T, source: S): T & S;
41
+ declare function merge<T extends Record<PropertyKey, any>, S extends Record<PropertyKey, any>>(target: T, source: S): T & S;
42
42
 
43
43
  export { merge };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "es-toolkit",
3
3
  "description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.",
4
- "version": "1.25.2-dev.817+5d5f9c4f",
4
+ "version": "1.25.2-dev.819+415d325f",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {