You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
799 B
40 lines
799 B
'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
|
|
|