Skip to content

Commit 523c609

Browse files
committed
[uniqueId] Track ids per prefix
1 parent 877d00d commit 523c609

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

.changeset/modern-taxis-notice.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte-ux': patch
3+
---
4+
5+
[uniqueId] Track ids per prefix

packages/svelte-ux/src/lib/utils/string.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ export function toTitleCase(str: string, ignore = ['a', 'an', 'is', 'the']) {
2525
/**
2626
* Generates a unique Id, with prefix if provided
2727
*/
28-
let idCounter = 0;
28+
const idMap = new Map<string, number>();
2929
export function uniqueId(prefix = '') {
30-
var id = ++idCounter;
30+
let id = (idMap.get(prefix) ?? 0) + 1;
31+
idMap.set(prefix, id);
3132
return prefix + id;
3233
}
3334

0 commit comments

Comments
 (0)