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

import-locals

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

import-locals

Allows you to import local variables, functions and classes from other modules

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
26K
increased by18.05%
Maintainers
1
Weekly downloads
 
Created
Source

import-locals

💿 Installation

npm i import-locals

📖 Usage

import locals from "import-locals";
const locals = require("import-locals"); // ES5 usage

locals.export("request/lib/cookies", "RequestJar");
locals.export("request/lib/cookies", "CookieJar");
locals.export("request/lib/cookies", "CookieJar", "LocalJar");

import { RequestJar, CookieJar, LocalJar } from "request/lib/cookies"; // ES6 works
const { RequestJar, CookieJar, LocalJar } = require("request/lib/cookies");

🔨 Advanced usage

// you can access internal GlobalPatcher
global.locals.separator = "\n\n";

global.locals.global.locals.unpatch();

global.locals.compile.call(module, content, filename);

🔬 LocalPatcher

Methods

export

export(request: String, variable: String, name: String = variable);
  • request - module name or path

  • variable - name of variable (or function, class, etc) to export

  • name - name to use for export, by default the same as variable

/* Usage example */
patcher.export("request/lib/cookies", "RequestJar");
patcher.export("request/lib/cookies", "CookieJar", "LocalJar");

import { RequestJar, LocalJar } from "request/lib/cookies";

unexport

unexport(request: String, variable: String = null, name: String = variable);
  • request - module name or path

  • variable - if null unexports all variables

  • name - name used for export, by default the same as variable

/* Usage example */
patcher.unexport("request/lib/cookies", "RequestJar");
patcher.unexport("request/lib/cookies", "CookieJar", "LocalJar");
patcher.unexport("request/lib/cookies");

❓ How does it work?

This module adds exports[name]=variable to requested source file, so you can require it

var foo = ["bar"];

// this module adds:
exports["foo"] = foo;

📝 License

Released under MIT license

🦉 Alex Owl

Keywords

FAQs

Package last updated on 11 Mar 2019

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