update at 2026-02-08 18:28:39

This commit is contained in:
douboer
2026-02-08 18:28:39 +08:00
parent e2a46e413a
commit 0f5a7f0d85
97 changed files with 22029 additions and 59 deletions

View File

@@ -0,0 +1,36 @@
const MAX_CHARS_PER_LINE = 45
function normalizeLineBreaks(text) {
return String(text || '').replace(/\r\n?/g, '\n')
}
function wrapTextByChars(text, maxCharsPerLine = MAX_CHARS_PER_LINE) {
if (maxCharsPerLine <= 0) {
return normalizeLineBreaks(text)
}
const normalized = normalizeLineBreaks(text)
const lines = normalized.split('\n')
const wrappedLines = []
for (const line of lines) {
const chars = Array.from(line)
if (!chars.length) {
wrappedLines.push('')
continue
}
for (let i = 0; i < chars.length; i += maxCharsPerLine) {
wrappedLines.push(chars.slice(i, i + maxCharsPerLine).join(''))
}
}
return wrappedLines.join('\n')
}
module.exports = {
MAX_CHARS_PER_LINE,
normalizeLineBreaks,
wrapTextByChars,
}