Skip to content

Latest commit

 

History

History
50 lines (36 loc) · 1.09 KB

README.md

File metadata and controls

50 lines (36 loc) · 1.09 KB

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.

The main motivation for this was that I needed something to quickly simulate the nginx HttpSubModule.

Installation

For the time being install from Github:

$ npm install 'git+https://github.com/makern/karma-regex-preprocessor.git' --save-dev

Configuration

Example configuration:

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

    regexPreprocessor: {
      rules: [
        // Simple string replace of 'foo' with 'bar'
        [ 'foo', 'bar' ],
        // Prefix all numbers with '-'
        [ /[\d]+/g, '-$1'],
        // Use a function to calculate replacement
        [ '%rand%', function(match) { return Math.random() } ]
      ]
    }
  });
};

License

The MIT License (MIT)