Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jsinc

Package Overview
Dependencies
Maintainers
0
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsinc - npm Package Compare versions

Comparing version 0.1.0 to 0.1.2

README.md

60

index.js

@@ -1,40 +0,30 @@

// example:
// download http://codeplex.com/jslinq
// var app={};
// app.jsinc = require('jsinc');
// app.jslinq = app.jsinc(__dirname+'/deps/jslinq/scripts/JSLINQ.js').window.JSLINQ;
//
//var self=this;
//self.load_js_prefix=__dirname;
function jsinc( file , addtosandbox)
var fs=require('fs');
var vm=require('vm');
function jsinc()
{
///if(file begins with http) download it...
//else
//if(file[0]!='/')file=self.load_js_prefix+'/'+file; //node js probably does it better.
var data = require('fs').readFileSync( file), sandbox = {
// all local var definations in the script are saved in sandbox;
// animal: 'cat',
// count: 2 //want to share anything? you can put it here
console:console,
window:{Function:Function} // many scripts expect window to be exists
};
if(addtosandbox)
{
for(key in addtosandbox)
{
if(Object.prototype.hasOwnProperty.call(addtosandbox, key))
{
sandbox[key]=addtosandbox[key];
}
}
}
process.binding( 'evals').Script.runInNewContext( data, sandbox, file );
//console.log(sandbox);
var files=arguments;
if(arguments.length>1 && typeof arguments[arguments.length-1]=='object')
{
var sandbox=arguments[arguments.length-1];//the last argument is sand box
files=Array.prototype.slice.call(arguments,0,arguments.length-1);// the other arguments are the files array
}
var data = "", sandbox = sandbox || {};
for(var i=0;i<files.length;i++)
{
var file=files[i];
data = fs.readFileSync( file,'utf-8');
if(!('console' in sandbox)) sandbox.console=console; // adds a console variable, probably a wanted future.
if(!('window' in sandbox)) sandbox.window=sandbox; // adds window variable to sandbox, probaly required by some scripts
vm.runInNewContext( data, sandbox, file );
}
//console.log(sandbox);
return sandbox;
}
this.jsinc=jsinc;
jsinc.jsinc=jsinc;//backwards compatibility
module.exports=jsinc;
//var date=load_js( 'date.js' );
// to get started do like this:
//
//var jsinc = require('jsinc');
//var date = jsinc( 'date.js' );
//console.log(date);

@@ -5,3 +5,3 @@ {

"description": "Include non module javascript file as module",
"version": "0.1.0",
"version": "0.1.2",
"homepage": "http://github.com/shimondoodkin/jsinc",

@@ -13,6 +13,9 @@ "repository": {

"engines": {
"node": ">=0.2.4"
"node": ">=0.3.1"
},
"dependencies": {},
"devDependencies": {}
}
"devDependencies": {},
"scripts": {
"test": "test.js"
}
}
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