Skip to content

mode/karma-regex-preprocessor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published