MCPcopy Index your code
hub / github.com/nodejs/node / rtfEscape

Function rtfEscape

tools/license2rtf.mjs:220–232  ·  view source on GitHub ↗
(string)

Source from the content-addressed store, hash-verified

218}
219
220function rtfEscape(string) {
221 function toHex(number, length) {
222 return (~~number).toString(16).padStart(length, '0');
223 }
224
225 return string
226 .replace(/[\\{}]/g, (m) => `\\${m}`)
227 .replace(/\t/g, () => '\\tab ')
228 // eslint-disable-next-line no-control-regex
229 .replace(/[\x00-\x1f\x7f-\xff]/g, (m) => `\\'${toHex(m.charCodeAt(0), 2)}`)
230 .replace(/\ufeff/g, '')
231 .replace(/[\u0100-\uffff]/g, (m) => `\\u${toHex(m.charCodeAt(0), 4)}?`);
232}
233
234/*
235 * This filter generates an rtf document from a stream of paragraph objects.

Callers

nothing calls this directly

Calls 1

toHexFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…