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

node-retrieve-globals

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-retrieve-globals

Execute a string of JavaScript using Node.js and return the global variable values and functions.

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
17K
increased by8.12%
Maintainers
1
Weekly downloads
 
Created
Source

node-retrieve-globals

Execute a string of JavaScript using Node.js and return the global variable values and functions.

  • Sync and async methods for synchronous or asynchronous JavaScript code respectively.
  • Can return any JavaScript data types
  • Can provide external variable values as context to the local scope

Installation

Available on npm

npm install node-retrieve-globals

Usage

// const { ModuleScript } = require("node-retrieve-globals");
import { ModuleScript } from "node-retrieve-globals";

And then:

let code = `var a = 1;
const b = "hello";

function hello() {}`;

let vm = new ModuleScript(code);

vm.getGlobalContextSync();
// or await vm.getGlobalContext();

Returns:

{ a: 1, b: "hello", hello: function hello() {} }

Pass in your own Data and reference it in the JavaScript code

let code = `let ref = myData;`;

let vm = new ModuleScript(code);

vm.getGlobalContextSync({ myData: "hello" });
// or await vm.getGlobalContext({ myData: "hello" });

Returns:

{ ref: "hello" }

FAQs

Package last updated on 19 Feb 2023

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

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