- Seamlessly reuse code between the browser and node without fussing with
module.exports
- Hot-reload caching of scripts loaded from files
- Native support for JSO files
- Run untrusted code within a sandbox
- Supports deferred loading
- No dependencies, single-file implementation
- Lightweight, less than 4k (uncompressed)
npm install jalosi
var jalosi = require("jalosi");
var script = `
function ten() {
return 10;
}
function twice(value) {
return value + value;
}
`;
var { ten, twice } = jalosi.run(script);
console.log(twice(ten()));
jalosi.compile(scripts, imports, options);
Compiles an array of scripts together, but doesn't execute the code. (The scripts
parameter can also be a single string.) If options.sandbox
is truthy then only imports
are made accesible to the script. Otherwise, everything from the global scope is included. (Excluding properties already defined by the imports
object.) Returns an anonymous function.
jalosi.run(scripts, imports, options);
Invokes jalosi.compile
, then runs the code. Returns whatever is returned by the combined scripts.
jalosi.defer(files, imports, options);
Same as jalosi.compile
, but reads the scripts from an array of files instead. (The files
parameter can also be a single string.) If options.path
is set, all files will be loaded from the directory that it points to. Returns an anonymous function.
jalosi.load(files, imports, options);
Invokes jalosi.defer
, then runs the code. Returns whatever is returned by the combined scripts.
jalosi(files, imports, options);
Alias for jalosi.load
.
jalosi.cache;
Reference to Jalosi's file cache. (Useful for diagnostics.)