🚀 Launch Week Day 3:Introducing Supply Chain Attack Campaigns Tracking.Learn More →
Socket
Book a DemoInstallSign in
Socket

snippet-stream

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

snippet-stream

Split a stream of JS source code into parsable snippets

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

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

FAQs

Package last updated on 29 Oct 2015

Did you know?

Socket

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.

Install

Related posts