Skip to content

Commit aae0601

Browse files
committed
fix(utils): add missing biome noRestrictedImports rule and correct truncate docs
- Add noRestrictedImports to biome.json under style — bans nanoid and uuid package imports at lint time (crypto.randomUUID/randomBytes are caught by the check:utils grep script which handles global property access) - Correct truncate() TSDoc and parameter name: sliceLength makes it clear that total output length is sliceLength + suffix.length, matching the behavior all callers were already written to expect
1 parent b488fff commit aae0601

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

biome.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,16 @@
113113
"noUnusedTemplateLiteral": "off",
114114
"useNumberNamespace": "error",
115115
"noInferrableTypes": "error",
116-
"noUselessElse": "error"
116+
"noUselessElse": "error",
117+
"noRestrictedImports": {
118+
"level": "error",
119+
"options": {
120+
"paths": {
121+
"nanoid": "Use generateId() or generateShortId() from @sim/utils/id instead",
122+
"uuid": "Use generateId() from @sim/utils/id instead"
123+
}
124+
}
125+
}
117126
},
118127
"complexity": {
119128
"noForEach": "off",

packages/utils/src/string.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/**
2-
* Truncates `str` to at most `maxLength` characters, appending `suffix` when
3-
* truncation occurs. Defaults to `'...'`.
2+
* Truncates `str` if it exceeds `sliceLength` characters, appending `suffix`.
3+
* The total output length when truncated is `sliceLength + suffix.length`.
4+
* Defaults suffix to `'...'`.
45
*
56
* @example
6-
* truncate('hello world', 8) // 'hello...'
7-
* truncate('hello world', 8, ' …') // 'hello …'
7+
* truncate('hello world', 8) // 'hello wo...' (11 chars)
8+
* truncate('hello world', 8, ' …') // 'hello wo …'
89
* truncate('hi', 10) // 'hi'
910
*/
10-
export function truncate(str: string, maxLength: number, suffix = '...'): string {
11-
return str.length > maxLength ? str.slice(0, maxLength) + suffix : str
11+
export function truncate(str: string, sliceLength: number, suffix = '...'): string {
12+
return str.length > sliceLength ? str.slice(0, sliceLength) + suffix : str
1213
}

0 commit comments

Comments
 (0)