feat: truncate short description exceeding the byte limit (#143)
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:
Peter Evans
2023-04-07 09:16:46 +09:00
committed by GitHub
parent 3ba533f0ff
commit 4b1a4bb484
7 changed files with 80 additions and 47 deletions

14
src/utils.ts Normal file
View 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
}