1.0.2 • Published 9 years ago

snippet-stream v1.0.2

Weekly downloads
7
License
MIT
Repository
github
Last release
9 years ago

snippet-stream

Split a stream of JS source code into parsable snippets

npm install snippet-stream

build status

Uses snippetify for all the heavy lifting

Usage

var snippets = require('snippet-stream')

// create a snippet stream
var stream = snippets()

// write some js to it
stream.write('var a = 1\n')
stream.write('function foo () {\n')
stream.write(' return a + 1\n')
stream.write('}\n')
stream.write('foo()')
stream.end()

stream.on('data', function (data) {
  console.log('snippet:')
  console.log(data)
})

Running the above produces the following output

snippet:
var a = 1

snippet:
function foo () {
 return a + 1
}

snippet:
foo()

Streaming eval

You can use this to create a streaming eval function

var snippets = require('snippet-stream')

// create a snippet stream
var stream = snippets()
var scope = {}

// write some js to it
stream.write('var a = 1\n')
stream.write('function foo () {\n')
stream.write(' return a + 1\n')
stream.write('}\n')
stream.write('console.log(foo())')
stream.end()

stream.on('data', function (data) {
  eval.call(scope, data)
})

License

MIT

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago