Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

to-string numbers written to the stream #47

Merged
merged 1 commit into from Sep 1, 2016
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+23 −5
Diff settings

Always

Just for now

to-string numbers written to the stream

  • Loading branch information...
mafintosh committed Aug 19, 2016
commit 3e285ba5e5b10b7c98552217f5c1023829efe69e
@@ -73,6 +73,10 @@ function isArrayish (arr) {
return /Array\]$/.test(Object.prototype.toString.call(arr))
}

function isBufferish (p) {
return typeof p === 'string' || isArrayish(p) || (p && typeof p.subarray === 'function')
}

function stringConcat (parts) {
var strings = []
var needsToString = false
@@ -82,8 +86,10 @@ function stringConcat (parts) {
strings.push(p)
} else if (Buffer.isBuffer(p)) {
strings.push(p)
} else {
} else if (isBufferish(p)) {
strings.push(new Buffer(p))
} else {
strings.push(new Buffer(String(p)))
}
}
if (Buffer.isBuffer(parts[0])) {
@@ -101,10 +107,11 @@ function bufferConcat (parts) {
var p = parts[i]
if (Buffer.isBuffer(p)) {
bufs.push(p)
} else if (typeof p === 'string' || isArrayish(p)
|| (p && typeof p.subarray === 'function')) {
} else if (isBufferish(p)) {
bufs.push(new Buffer(p))
} else bufs.push(new Buffer(String(p)))
} else {
bufs.push(new Buffer(String(p)))
}
}
return Buffer.concat(bufs)
}
@@ -58,7 +58,7 @@ test('string from buffers with multibyte characters', function (t) {
var snowman = new Buffer('')
for (var i = 0; i < 8; i++) {
strings.write(snowman.slice(0, 1))
strings.write(snowman.slice(1))
strings.write(snowman.slice(1))
}
strings.end()
})
@@ -74,3 +74,14 @@ test('string infer encoding with empty string chunk', function (t) {
strings.write("dogs")
strings.end()
})

test('to string numbers', function (t) {
var write = concat(function (str) {
t.equal(str, 'a1000')
t.end()
})

write.write('a')
write.write(1000)
write.end()
})
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.