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

install

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

install

Minimal JavaScript module loader

  • 0.6.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
708K
increased by5.78%
Maintainers
1
Weekly downloads
 
Created
Source

install Build Status

The CommonJS module syntax is one of the most widely accepted conventions in the JavaScript ecosystem. Everyone seems to agree that require and exports are a reasonable way of expressing module dependencies and interfaces, and the tools for managing modular code are getting better all the time.

Much less of a consensus has developed around the best way to deliver CommonJS modules to a web browser, where the synchronous semantics of require pose a non-trivial implementation challenge. This module loader contributes to that confusion, yet also demonstrates that an amply-featured module loader need not stretch into the hundreds or thousands of lines.

Installation

From NPM:

npm install install

From GitHub:

cd path/to/node_modules
git clone git://github.com/benjamn/install.git
cd install
npm install .

Usage

When evaluated, the contents of install.js create a global function called install. This function is the only external interface to the module loader, and it can be called in two ways.

The first way is to pass a module identifier string followed by a module factory function:

install("some/module/id", function(require, exports, module) {
    // CommonJS module code goes here.

    // For example:
    exports.setImmediate = function(callback) {
        return setTimeout(callback, 0);
    };
});

This makes the module available for requirement, but does not evaluate the contents of the module until the first time another module calls require("some/module/id").

The second way to invoke install is to omit the module identifier and pass an anonymous module factory function:

install(function(require) {
    // Code that uses require goes here.

    // For example:
    require("some/module/id").setImmediate(function() {
        console.log("setImmediate fired");
    });
});

Anonymous modules are executed in order of installation, as soon as their requirements have been installed. Note that such modules do not have exports objects, because anonymous modules cannot be required.

Sugar

If a named module has no requirements and does not need its own scope, the following shorthand can be used to install the module:

install("simple/module", { exports: {
    one: 1,
    two: 2,
    buckle: "my shoe"
}});

Keywords

FAQs

Package last updated on 20 Mar 2016

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