Socket
Socket
Sign inDemoInstall

browser-module-sandbox

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

browser-module-sandbox - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

26

index.js
var inherits = require('inherits')
var iframe = require('iframe')
var events = require('events')
var extend = require('extend')
var request = require('browser-request')

@@ -23,6 +22,9 @@ var detective = require('detective')

Sandbox.prototype.bundle = function(entry) {
Sandbox.prototype.bundle = function(entry, preferredVersions) {
if (!preferredVersions) preferredVersions = {}
var self = this
var modules = detective(entry)
self.emit('bundleStart')
self.emit('modules', modules)
var body = {

@@ -34,6 +36,16 @@ "options": {

}
modules.map(function(module) {
body.dependencies[module] = 'latest'
var version = preferredVersions[module] || 'latest'
body.dependencies[module] = version
})
self.emit('bundleStart')
request({method: "POST", body: body, url: this.cdn + '/multi', json: true}, function(err, resp, json) {
if (err) {
self.emit('bundleEnd')
return err
}
var allBundles = ''

@@ -43,2 +55,3 @@ Object.keys(json).map(function(module) {

})
// setTimeout is because iframes report inaccurate window.innerWidth/innerHeight, even after DOMContentLoaded!

@@ -50,4 +63,5 @@ var body = self.iframeBody +

'}, 0)</script>'
self.iframe.setHTML({ head: self.iframeHead + self.iframeStyle, body: body })
self.emit('bundleEnd')
var html = { head: self.iframeHead + self.iframeStyle, body: body }
self.iframe.setHTML(html)
self.emit('bundleEnd', html)
})

@@ -54,0 +68,0 @@ }

{
"name": "browser-module-sandbox",
"version": "1.0.0",
"version": "1.1.0",
"description": "uses browserify-cdn to run node code in an iframe",

@@ -13,3 +13,2 @@ "repository": {

"inherits": "1.0.0",
"extend": "1.1.3",
"detective": "~2.1.2"

@@ -16,0 +15,0 @@ },

@@ -31,4 +31,18 @@ # browser-module-sandbox

## events
### sandbox.on('modules', function(modules) {})
modules is the array of modules that gets parsed out of the bundle entry by the `detective` module
### sandbox.on('bundleStart', function() {})
emits when the bundle request begins
### sandbox.on('bundleEnd', function(html) {})
emits when the bundle request finishes. `html` is an object that has the iframe header contents and the full bundle body (made of up all the bundles + the entry in an executable form)
## license
BSD
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc