MCPcopy Index your code
hub / github.com/codeceptjs/CodeceptJS / splitByChunks

Function splitByChunks

lib/html.js:261–293  ·  view source on GitHub ↗
(text, chunkSize)

Source from the content-addressed store, hash-verified

259}
260
261function splitByChunks(text, chunkSize) {
262 chunkSize -= 20
263 const chunks = []
264 for (let i = 0; i < text.length; i += chunkSize) {
265 chunks.push(text.slice(i, i + chunkSize))
266 }
267
268 const regex = /<\s*\w+(?:\s+\w+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^>\s]+)))*\s*$/
269
270 // append tag to chunk if it was split out
271 for (const index in chunks) {
272 const nextIndex = parseInt(index, 10) + 1
273 if (!chunks[nextIndex]) break
274
275 const currentChunk = chunks[index]
276 const nextChunk = chunks[nextIndex]
277
278 const lastTag = currentChunk.match(regex)
279 if (lastTag) {
280 chunks[nextIndex] = lastTag[0] + nextChunk
281 }
282
283 const path = buildPath(parse(currentChunk))
284 if (path) {
285 chunks[nextIndex] = path + chunks[nextIndex]
286 }
287
288 if (chunks[nextIndex].includes('<html')) continue
289 chunks[nextIndex] = `<html><body>${chunks[nextIndex]}</body></html>`
290 }
291
292 return chunks.map(chunk => chunk.trim())
293}
294
295function simplifyHtmlElement(html, maxLength = 300) {
296 try {

Callers 2

setHtmlContextMethod · 0.90
html_test.jsFile · 0.90

Calls 3

buildPathFunction · 0.85
pushMethod · 0.80
includesMethod · 0.80

Tested by

no test coverage detected