Open the context
Choose the project folder and name the files or behavior involved.
Split a bot’s outgoing text at the configured UTF-16 length limit without separating a surrogate pair. Check an emoji at the boundary, an empty message and fenced code, preserving the text when the chunks are joined.
Choose the project folder and name the files or behavior involved.
Describe the input, expected output and boundaries that must stay intact.
Review the proposed edits and any commands before relying on their result.
Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.
if (!Number.isInteger(start) || start < 0 || start > text.length) {
throw new Error("start.invalid");
}
if (!Number.isInteger(limit) || limit < 1) throw new Error("limit.invalid");
if (start === text.length) return "";
let end = Math.min(start + limit, text.length);
const last = text.charCodeAt(end - 1);
if (end < text.length && last >= 0xD800 && last <= 0xDBFF) end--;
if (end === start) throw new Error("limit.too_small");
return text.slice(start, end);The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.