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

insert-module-globals

Package Overview
Dependencies
Maintainers
1
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

insert-module-globals

insert implicit module globals into a module-deps stream

  • 1.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
890K
decreased by-0.59%
Maintainers
1
Weekly downloads
 
Created

What is insert-module-globals?

The insert-module-globals npm package is used to insert global variables into the scope of a module. This is particularly useful for browserify transforms, allowing you to inject variables like __filename, __dirname, process, Buffer, and global into your modules.

What are insert-module-globals's main functionalities?

Injecting __filename

This feature allows you to inject the __filename variable into your module's scope. The code sample demonstrates how to use the insert-module-globals package with browserify to transform a file and insert the __filename variable.

const insertGlobals = require('insert-module-globals');
const through = require('through2');

const b = browserify();
b.transform(function (file) {
  return through(function (buf, enc, next) {
    this.push(insertGlobals(file, buf.toString('utf8')));
    next();
  });
});

Injecting __dirname

This feature allows you to inject the __dirname variable into your module's scope. The code sample demonstrates how to use the insert-module-globals package with browserify to transform a file and insert the __dirname variable.

const insertGlobals = require('insert-module-globals');
const through = require('through2');

const b = browserify();
b.transform(function (file) {
  return through(function (buf, enc, next) {
    this.push(insertGlobals(file, buf.toString('utf8')));
    next();
  });
});

Injecting process

This feature allows you to inject the process variable into your module's scope. The code sample demonstrates how to use the insert-module-globals package with browserify to transform a file and insert the process variable.

const insertGlobals = require('insert-module-globals');
const through = require('through2');

const b = browserify();
b.transform(function (file) {
  return through(function (buf, enc, next) {
    this.push(insertGlobals(file, buf.toString('utf8')));
    next();
  });
});

Injecting Buffer

This feature allows you to inject the Buffer variable into your module's scope. The code sample demonstrates how to use the insert-module-globals package with browserify to transform a file and insert the Buffer variable.

const insertGlobals = require('insert-module-globals');
const through = require('through2');

const b = browserify();
b.transform(function (file) {
  return through(function (buf, enc, next) {
    this.push(insertGlobals(file, buf.toString('utf8')));
    next();
  });
});

Injecting global

This feature allows you to inject the global variable into your module's scope. The code sample demonstrates how to use the insert-module-globals package with browserify to transform a file and insert the global variable.

const insertGlobals = require('insert-module-globals');
const through = require('through2');

const b = browserify();
b.transform(function (file) {
  return through(function (buf, enc, next) {
    this.push(insertGlobals(file, buf.toString('utf8')));
    next();
  });
});

Other packages similar to insert-module-globals

Keywords

FAQs

Package last updated on 24 Jun 2013

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