MCPcopy Create free account
hub / github.com/nodejs/node / removeChars

Function removeChars

deps/undici/src/lib/web/fetch/formdata-parser.js:492–505  ·  view source on GitHub ↗

* @param {Buffer} buf * @param {boolean} leading * @param {boolean} trailing * @param {(charCode: number) => boolean} predicate * @returns {Buffer}

(buf, leading, trailing, predicate)

Source from the content-addressed store, hash-verified

490 * @returns {Buffer}
491 */
492function removeChars (buf, leading, trailing, predicate) {
493 let lead = 0
494 let trail = buf.length - 1
495
496 if (leading) {
497 while (lead < buf.length && predicate(buf[lead])) lead++
498 }
499
500 if (trailing) {
501 while (trail > 0 && predicate(buf[trail])) trail--
502 }
503
504 return lead === 0 && trail === buf.length - 1 ? buf : buf.subarray(lead, trail + 1)
505}
506
507/**
508 * Checks if {@param buffer} starts with {@param start}

Callers 3

gettingDecodingSplittingFunction · 0.70
removeHTTPWhitespaceFunction · 0.70

Calls 1

predicateFunction · 0.50

Tested by

no test coverage detected