@jsvision/core / boundPasteText
Function: boundPasteText()
boundPasteText(
text,capBytes?):BoundedPasteText
Defined in: input/paste.ts:53
Bound direct string paste using the same UTF-8 byte limit as terminal bracketed paste.
TextEncoder.encodeInto stops before a code point that cannot fit. Its read count is therefore a safe UTF-16 slice boundary for well-formed surrogate pairs, while slicing the original string also preserves any isolated surrogate supplied by the host. The helper first proves small inputs fit from their maximum possible UTF-8 size, then allocates at most the configured bounded buffer instead of encoding an arbitrarily large input into a second full-size byte array.
Parameters
text
string
Untrusted plain text supplied by a host clipboard.
capBytes?
number = PASTE_CAP_BYTES
Maximum encoded UTF-8 bytes; defaults to PASTE_CAP_BYTES.
Returns
The unchanged input when it fits, otherwise its longest complete bounded prefix.
Throws
When capBytes is negative, non-integral, not a safe integer, or exceeds PASTE_CAP_BYTES.
Example
import { boundPasteText } from '@jsvision/core';
const bounded = boundPasteText('A😀B', 5);
// bounded === { text: 'A😀', truncated: true }