New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

karma-regex-preprocessor

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

karma-regex-preprocessor

Regular expression replace preprocessor for karma test runner

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

karma-regex-preprocessor

A karma preprocessor which does one or more regular expression substitutions on the file contents. It effectively just calls String.prototype.replace() with the parameters specified in the configuration.

Historically, the main motivation for this was that https://github.com/mode needed something to quickly simulate the nginx HttpSubModule.

Installation

Install from npm:

npm install karma-regex-preprocessor --save-dev

Configuration

Example configuration:

// karma.conf.js
module.exports = function(config) {
  config.set({
    preprocessors: {
      '**/*.js': ['regex']
    },

    regexPreprocessor: {
      rules: [
        {
          // Replacements for File1.
          fileName: "File1.js", replacement: [
            // Simple string replace of 'foo' with 'bar'.
            { replace: "foo", with: "bar" },
            // Prefix all numbers with '-'.
            { replace: /[\d]+/g, with: "-$1" },
            // Use a function to calculate replacement.
            { replace: "%rand%", with: function (match) { return Math.random() } }
          ]
        },
        {
          // Replacements for File2.
          fileName: "File2.js", replacement: [
            // Simple string replace of 'foo' with 'baz'.
            { replace: "foo", with: "baz" },
            // Prefix all numbers with '€'.
            { replace: /[\d]+/g, with: "€$1" },
            // Use a function to calculate replacement.
            { replace: "%rand%", with: function (match) { return Math.random()*5 } }
          ]
        }
      ]
    }
  });
};

License

The MIT License (MIT)

Keywords

karma-plugin

FAQs

Package last updated on 19 Apr 2017

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