fix: replace {__} workaround with clean range() helper in Svelte templates
This commit is contained in:
@@ -80,3 +80,19 @@ export function calculateAge(dateOfBirth: string | undefined | null): number | n
|
||||
}
|
||||
return age;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an array of numbers from 0 to n-1.
|
||||
*
|
||||
* Useful for iterating a fixed number of times in Svelte templates:
|
||||
*
|
||||
* {#each range(3) as i}
|
||||
* <div>{i}</div>
|
||||
* {/each}
|
||||
*
|
||||
* Replaces the `{#each Array(3) as _, i (i)}{__}{/each}` workaround pattern
|
||||
* that was needed to suppress eslint unused-variable warnings.
|
||||
*/
|
||||
export function range(n: number): number[] {
|
||||
return Array.from({ length: n }, (_, i) => i);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user