Code coverage report for lib/compareLocales.js

Statements: 100% (23 / 23)      Branches: 100% (12 / 12)      Functions: 100% (2 / 2)      Lines: 100% (23 / 23)      Ignored: none     

All files » lib/ » compareLocales.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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56    1 2 2 1     1 1 1 1   1 3 1   2 1   1                     1 3 1       1               1 3 3 3         3    
'use strict';
 
module.exports = function(localeA, localeB, options) {
  options = options || {};
  if (typeof localeA !== 'object' || typeof localeB !== 'object') {
    throw new Error('s18n: `localeA` and `localeB` must be objects.');
  }
 
  var localeAMissing = {};
  var localeBMissing = {};
  var unmodifiedStrings = {};
  var modifiedStrings = [];
 
  for (var hashA in localeA) {
    if (typeof localeB[hashA] === 'undefined') {
      localeBMissing[hashA] = localeA[hashA];
    } else {
      if (localeA[hashA] === localeB[hashA]) {
        unmodifiedStrings[hashA] = localeA[hashA];
      } else {
        modifiedStrings.push({
          hash: hashA,
          strings: [
            localeA[hashA],
            localeB[hashA]
          ]
        });
      }
    }
  }
 
  for (var hashB in localeB) {
    if (typeof localeA[hashB] === 'undefined') {
      localeAMissing[hashB] = localeB[hashB];
    }
  }
 
  return [
    arrayifyResults(localeAMissing),
    arrayifyResults(localeBMissing),
    arrayifyResults(unmodifiedStrings),
    modifiedStrings
  ];
};
 
function arrayifyResults(resultsObj) {
  var array = [];
  for (var hash in resultsObj) {
    array.push({
      hash: hash,
      string: resultsObj[hash]
    });
  }
  return array;
}