Code coverage report for node-mhtml/lib/partCollection.js

Statements: 95% (19 / 20)      Branches: 87.5% (7 / 8)      Functions: 100% (3 / 3)      Lines: 95% (19 / 20)     

All files » node-mhtml/lib/ » partCollection.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 421   1 1   1   1 9 9 9     1       54   54         54 8 8 7     46     54 54       8      
'use strict';
 
var path = require('path');
var Part = require(__dirname + '/part');
 
module.exports = PartCollection;
 
function PartCollection() {
  this.length = 0;
  this.basePath = null;
  this._parts = [];
}
 
PartCollection.prototype = {
 
  push: function (part) {
 
    var dirname;
 
    Iif (!(part instanceof Part)) {
      throw new Error('Invalid part');
    }
 
    // TODO: move this into Path::setBasePath()
    if (!this.length && part.meta('content-type') === 'text/html') {
      dirname = path.dirname(part.meta('content-location'));
      if (dirname.match(/^file:/)) {
        part.basePath = this.basePath = dirname.replace(/\\/g, '/') + '/';
      }
    } else {
      part.basePath = this.basePath;
    }
 
    this._parts.push(part);
    this.length = this._parts.length;
  },
 
  each: function (cb) {
    this._parts.forEach(cb);
  }
};