Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
A collection of Node.js transform stream utilities for simple data manipulation.
Install with npm install sculpt --save
.
All of Sculpt's streams operate in objectMode
, so be careful that you know what data types are
going in and coming out of your streams. Normally Node.js streams are guaranteed to be strings or
buffers, but that is not the case when streams operate in object mode.
Methods
Builders
Strings
Objects
Control Flow
Miscellaneous
Arguments
var stream = sculpt.map(function (chunk) {
return chunk + chunk
})
stream.pipe(process.stdout)
stream.write('hello')
// hellohello
Map can also operate asynchronously. To make the stream async, pass a second argument
(a done callback) and call .async()
.
var stream = sculpt.map(function (chunk, done) {
requestRemoteData(chunk, function (err, data) {
done(err, chunk + data)
})
}).async()
stream.pipe(process.stdout)
stream.write('hello')
// 'hello some remote data...'
Map streams can also operate in multi mode, which lets them push multiple unique values
in a single callback. Callbacks in multi mode must return arrays, and each item
will be pushed individually. To create a map steam in multi mode call .multi()
.
This is most useful when you're consuming the output with another stream that depends on meaningful items in each push. This is how the split stream is implemented.
var i = 0
var stream = sculpt.map(function (chunk) {
i++
return [i.toString(), chunk]
}).multi()
stream.pipe(process.stdout)
stream.write('hello')
// 1hello
Arguments
var stream = sculpt.filter(function (chunk) {
return chunk.toString().length >= 5
})
stream.on('data', console.log.bind(console))
stream.write('hi')
stream.write('hello')
stream.write('goodbye')
// 'hellogoodbye'
Filter can also operate asynchronously. To make the stream async, pass a second argument
(a done callback) and call .async()
.
var stream = sculpt.filter(function (chunk, done) {
requestRemoteValidation(chunk, function (err, valid) {
done(err, !! valid)
})
}).async()
stream.on('data', console.log.bind(console))
stream.write('hi')
stream.write('hello')
stream.write('goodbye')
// 'hellogoodbye'
Arguments
var stream = sculpt.append('!!')
stream.on('data', console.log.bind(console))
stream.write('hello')
stream.write('world')
// 'hello!!world!!'
Arguments
var stream = sculpt.prepend('> ')
stream.pipe(process.stdout)
stream.write('hello\n')
stream.write('world')
// > hello
// > world
Arguments
var stream = sculpt.replace('!', '?')
stream.pipe(process.stdout)
stream.write('hello! ')
stream.write('world ')
stream.write('goodbye!')
// 'hello? world goodbye?'
Arguments
This is intended to be used on arrays, but could work on any data type that has a join()
method.
var stream = sculpt.join('|')
stream.pipe(process.stdout)
stream.write([1, 2, 3])
stream.write(['foo', 'bar'])
// '1|2|3foo|bar'
Arguments
var stream = sculpt.invoke('toString')
stream.pipe(process.stdout)
stream.end(123)
// '123'
Arguments
This is intended to be used on strings (and create arrays), but could work on any data type that
has a split()
method.
var stream = sculpt.split('|')
var partNumber = 0
stream.on('data', function (part) {
partNumber++
console.log(partNumber, part)
})
stream.write('hi|bye|foo|bar')
// '1 hi'
// '2 bye'
// '3 foo'
// '4 bar'
Arguments
Each output chunk will be a buffer of length
bytes, except the last chunk, which will be however many bytes are left over.
var stream = sculpt.byteLength(5)
stream.on('data', function (chunk) {
console.log(chunk.toString())
})
stream.end('abcdefghijk')
// 'abcde'
// 'fghij'
// 'k'
Arguments
Errors from the forked stream are bubbled up to this transform stream.
var stream = sculpt.fork(process.stderr)
stream.pipe(process.stderr)
stream.write('hello world')
// 'hello world' is output to stdout and stderr
Arguments
var count = 0
var stream = tap(function (item) {
if (item === 'bump') {
count++
}
})
stream.on('end', function () {
console.log('Count is %d', count)
})
stream.write('bump')
stream.write('bump')
stream.write('hello')
stream.write('bump')
// 'Count is 3'
Transform streams can be piped together. Let's say you have a file with song lyrics and you want to clean it up.
fs.createReadStream('./lyrics.txt')
// Split into individual lines
// The following streams will operate on one line at a time.
.pipe(sculpt.split('\n'))
// Remove trailing whitespace from each line
.pipe(sculpt.replace(/\s+$/, ''))
// Remove empty lines
.pipe(sculpt.filter(function (line) {
return line.length > 0
}))
// Bring back line breaks
.pipe(sculpt.append('\n'))
// Print the result
.pipe(process.stdout)
FAQs
Generate Node 0.10-friendly transform streams to manipulate other streams.
We found that sculpt demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.