mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-11-02 19:29:10 +08:00
DISABLE_THIRD_PARTY_CHECK=NPM update R=jacktfranklin@chromium.org Bug: none Change-Id: I41b7006f336b9465677cc7434abd70a732c58221 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2692907 Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org> Reviewed-by: Jack Franklin <jacktfranklin@chromium.org>
43 lines
1.1 KiB
JavaScript
43 lines
1.1 KiB
JavaScript
export default serializeChunks
|
|
|
|
import assert from 'assert'
|
|
import codes from '../character/codes.mjs'
|
|
import values from '../character/values.mjs'
|
|
import fromCharCode from '../constant/from-char-code.mjs'
|
|
|
|
function serializeChunks(chunks) {
|
|
var index = -1
|
|
var result = []
|
|
var chunk
|
|
var value
|
|
var atTab
|
|
|
|
while (++index < chunks.length) {
|
|
chunk = chunks[index]
|
|
|
|
if (typeof chunk === 'string') {
|
|
value = chunk
|
|
} else if (chunk === codes.carriageReturn) {
|
|
value = values.cr
|
|
} else if (chunk === codes.lineFeed) {
|
|
value = values.lf
|
|
} else if (chunk === codes.carriageReturnLineFeed) {
|
|
value = values.cr + values.lf
|
|
} else if (chunk === codes.horizontalTab) {
|
|
value = values.ht
|
|
} else if (chunk === codes.virtualSpace) {
|
|
if (atTab) continue
|
|
value = values.space
|
|
} else {
|
|
assert.equal(typeof chunk, 'number', 'expected number')
|
|
// Currently only replacement character.
|
|
value = fromCharCode(chunk)
|
|
}
|
|
|
|
atTab = chunk === codes.horizontalTab
|
|
result.push(value)
|
|
}
|
|
|
|
return result.join('')
|
|
}
|