src/karma-json-preprocessor.js
function createJsonPreprocessor(logger, basePath, config) {
  const log = logger.create('preprocessor.json');
  const conf = config || {};
  const stripPrefix = new RegExp(`^${(conf.stripPrefix || '')}`);

  return function(content, file, done) {
    log.debug('Processing "%s".', file.originalPath);

    // Build json path file.
    const jsonPath = file.originalPath
        .replace(`${basePath}/`, '')
        .replace(stripPrefix, '');

    const template = createTemplate(conf.varName || '__json__');

    // Update file path
    file.path = `${file.path}.js`;

    try {
      const o = JSON.parse(content.trim());
      done(util.format(template, jsonPath, JSON.stringify(o)));
    } catch (e) {
      log.error('Json representation of %s is not valid !', file.originalPath);
      done('');
    }
  };
}
function createJsonPreprocessor(logger, basePath, config) {
  const log = logger.create('preprocessor.json');
  const conf = config || {};
  const stripPrefix = new RegExp(`^${(conf.stripPrefix || '')}`);

  return function(content, file, done) {
    log.debug('Processing "%s".', file.originalPath);

    // Build json path file.
    const jsonPath = file.originalPath
        .replace(`${basePath}/`, '')
        .replace(stripPrefix, '');

    const template = createTemplate(conf.varName || '__json__');

    // Update file path
    file.path = `${file.path}.js`;

    try {
      const o = JSON.parse(content.trim());
      done(util.format(template, jsonPath, JSON.stringify(o)));
    } catch (e) {
      log.error('Json representation of %s is not valid !', file.originalPath);
      done('');
    }
  };
}
function createJsonPreprocessor ( logger , basePath , config ) { const log = logger . create ( 'preprocessor.json' ) ; const conf = config || { } ; const stripPrefix = new RegExp ( ` ${ ( conf . stripPrefix || '' ) } ` ) ; return function ( content , file , done ) { log . debug ( 'Processing "%s".' , file . originalPath ) ; // Build json path file. const jsonPath = file . originalPath . replace ( ` ${ basePath } ` , '' ) . replace ( stripPrefix , '' ) ; const template = createTemplate ( conf . varName || '__json__' ) ; // Update file path file . path = ` ${ file . path } ` ; try { const o = JSON . parse ( content . trim ( ) ) ; done ( util . format ( template , jsonPath , JSON . stringify ( o ) ) ) ; } catch ( e ) { log . error ( 'Json representation of %s is not valid !' , file . originalPath ) ; done ( '' ) ; } } ; }
Create the JSON preprocessor.

@param {Object} logger Karma logger.
@param {string} basePath The base path initialized by karma.
@param {Object} config The configuration object.
@return {function} The preprocessor function.
Create the JSON preprocessor .