blob: 48d9e24f51630a913452119a6d8ba6a6823cf5d6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
'use strict'
var fromCharCode = require('../constant/from-char-code.js')
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 === -5) {
value = '\r'
} else if (chunk === -4) {
value = '\n'
} else if (chunk === -3) {
value = '\r' + '\n'
} else if (chunk === -2) {
value = '\t'
} else if (chunk === -1) {
if (atTab) continue
value = ' '
} else {
// Currently only replacement character.
value = fromCharCode(chunk)
}
atTab = chunk === -2
result.push(value)
}
return result.join('')
}
module.exports = serializeChunks
|