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

callback-loader

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

callback-loader

Webpack loader that parse your JS-file, call specified functions and replace their call expressions with results

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
209
decreased by-39.24%
Maintainers
1
Weekly downloads
 
Created
Source

callback-loader

Webpack loader that parse your JS-file, call specified functions and replace their call expressions with the results.

Installation

npm install callback-loader

Usage

Source file:

var a = multBy2(10);
var b = mult(10, 3);
var c = concat("foo", "bar");

Webpack config:

{
    ...
    callbackLoader: {
        multBy2: function(num) {
            return num * 2;
        },
        mult: function(num1, num2) {
            return num1 * num2;
        },
        concat: function(str1, str2) {
            return '"' + str1 + str2 + '"';
        }
    }
}

Result:

var a = 20;
var b = 30;
var c = "foobar";

Notice that quotes was added in concat function.

Loader parameters

You can choose which functions will be processed in your query:

'callback?mult&multBy2!example.js'

Result for this query will be this:

var a = 20;
var b = 30;
var c = concat("foo", "bar");

Different configs

Webpack config:

{
    ...
    callbackLoader: {
        concat: function(str1, str2) {
            return '"' + str1 + str2 + '"';
        }
    },
    anotherConfig: {
        concat: function(str1, str2) {
            return '"' + str1 + str2 + '-version2"';
        }
    }
}

Loader query:

'callback?config=anotherConfig!example.js'

Result for this query will be this:

var a = multBy2(10);
var b = mult(10, 3);
var c = "foobar-version2";

Restrictions

No expressions in function arguments, sorry. Only raw values.

Keywords

FAQs

Package last updated on 06 Oct 2015

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