index.js
function transformData(data, config, done) {

  data.baseSize = config.baseSize;

  data.svgPath = config.svgPath.replace("%f", config.svg.sprite);
  data.pngPath = config.pngPath.replace("%f", config.svg.sprite.replace(/\.svg$/, ".png"));

  data.svg = data.svg.map(function(item) {

      item.relHeight = item.height / config.baseSize;
      item.relWidth  = item.width / config.baseSize;

      item.relPositionX = item.positionX / config.baseSize - config.padding / config.baseSize;
      item.relPositionY = item.positionY / config.baseSize - config.padding / config.baseSize;
      item.normal = true;

      if (item.name.match(/~/g)) {
        if (config.mode !== "sprite") {
          return false;
        } else {
          var segs  = item.name.split("~");
          item.name = item.selector[0].expression + ":" + segs[1];
          item.normal = false;
        }
      } else {
        item.name = item.selector[0].expression;
      }

      return item;
    });

  data.svg = data.svg.filter(function(item) { return item; });

  data.relWidth  = data.swidth / config.baseSize;
  data.relHeight = data.sheight / config.baseSize;

  if (config.asyncTransforms) {
    return done(data);
  }
  return data;
}
function transformData(data, config, done) {

  data.baseSize = config.baseSize;

  data.svgPath = config.svgPath.replace("%f", config.svg.sprite);
  data.pngPath = config.pngPath.replace("%f", config.svg.sprite.replace(/\.svg$/, ".png"));

  data.svg = data.svg.map(function(item) {

      item.relHeight = item.height / config.baseSize;
      item.relWidth  = item.width / config.baseSize;

      item.relPositionX = item.positionX / config.baseSize - config.padding / config.baseSize;
      item.relPositionY = item.positionY / config.baseSize - config.padding / config.baseSize;
      item.normal = true;

      if (item.name.match(/~/g)) {
        if (config.mode !== "sprite") {
          return false;
        } else {
          var segs  = item.name.split("~");
          item.name = item.selector[0].expression + ":" + segs[1];
          item.normal = false;
        }
      } else {
        item.name = item.selector[0].expression;
      }

      return item;
    });

  data.svg = data.svg.filter(function(item) { return item; });

  data.relWidth  = data.swidth / config.baseSize;
  data.relHeight = data.sheight / config.baseSize;

  if (config.asyncTransforms) {
    return done(data);
  }
  return data;
}
function transformData ( data , config , done ) { data . baseSize = config . baseSize ; data . svgPath = config . svgPath . replace ( "%f" , config . svg . sprite ) ; data . pngPath = config . pngPath . replace ( "%f" , config . svg . sprite . replace ( / \.svg$ / , ".png" ) ) ; data . svg = data . svg . map ( function ( item ) { item . relHeight = item . height / config . baseSize ; item . relWidth = item . width / config . baseSize ; item . relPositionX = item . positionX / config . baseSize - config . padding / config . baseSize ; item . relPositionY = item . positionY / config . baseSize - config . padding / config . baseSize ; item . normal = true ; if ( item . name . match ( / ~ / g ) ) { if ( config . mode !== "sprite" ) { return false ; } else { var segs = item . name . split ( "~" ) ; item . name = item . selector [ 0 ] . expression + ":" + segs [ 1 ] ; item . normal = false ; } } else { item . name = item . selector [ 0 ] . expression ; } return item ; } ) ; data . svg = data . svg . filter ( function ( item ) { return item ; } ) ; data . relWidth = data . swidth / config . baseSize ; data . relHeight = data . sheight / config . baseSize ; if ( config . asyncTransforms ) { return done ( data ) ; } return data ; }
Any last-minute data transformations before handing off to templates,
can be overridden by supplying a 'transformData' option
@param data
@param config
@returns {*}
Any last - minute data transformations before handing off to templates can be overridden by supplying a transformData option