feat: truncate short description exceeding the byte limit (#143)
Some checks failed
Publish Docker Image / publish (push) Has been cancelled
Some checks failed
Publish Docker Image / publish (push) Has been cancelled
* feat: truncate short description exceeding the byte limit * fix tests
This commit is contained in:
14
src/utils.ts
Normal file
14
src/utils.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import unicodeSubstring = require('unicode-substring')
|
||||
|
||||
export function getErrorMessage(error: unknown) {
|
||||
if (error instanceof Error) return error.message
|
||||
return String(error)
|
||||
}
|
||||
|
||||
export function truncateToBytes(s: string, n: number): string {
|
||||
let len = n
|
||||
while (Buffer.byteLength(s) > n) {
|
||||
s = unicodeSubstring(s, 0, len--)
|
||||
}
|
||||
return s
|
||||
}
|
||||
Reference in New Issue
Block a user