<commit_before>const Promise = require('bluebird');
const PbfSplicer = require('./PbfSplicer');
const LanguagePicker = require('./LanguagePicker');
const Err = require('@kartotherian/err');
const checkType = require('@kartotherian/input-validator');
const uptile = require('tilelive-promise');
const fs = require('fs');

let core;

function Babel(uri, callback) {
  if (!new.target) {
    return new Babel(uri, callback);
  }

  let self = this;

  Promise.try(() => {
    self = uptile(self);
    const { query } = checkType.normalizeUrl(uri);
    checkType(query, 'source', 'string', true);
    checkType(query, 'tag', 'string', 'name');
    self.nameTag = query.tag;
    checkType(query, 'multiTag', 'string', `${self.nameTag}_`);
    self.multiTag = query.multiTag;
    checkType(query, 'keepUncompressed', 'boolean');
    self.keepUncompressed = query.keepUncompressed;

    switch (uri.protocol) {
      case 'babel:':
        checkType(query, 'combineName', 'boolean', false);
        self.combineName = query.combineName;

        checkType(query, 'defaultLanguage', 'string');
        query.languageMap = query.languageMap || 'lib/fallbacks.json';
        if (typeof query.languageMap === 'string') {
          query.languageMap = JSON.parse(fs.readFileSync(query.languageMap, 'utf8'));
        }
        if (typeof query.languageMap === 'object' &&
          !Array.isArray(query.languageMap)
        ) {
          for (const lang of Object.keys(query.languageMap)) {
            const value = { languageMap: query.languageMap[lang] };
            checkType(value, 'languageMap', 'string-array', true);
            value.languageMap.unshift(lang);
            query.languageMap[lang] = value.languageMap;
          }
        } else {
          throw new Err('languageMap must be a dictionary of' +
            ' langCodes => [list of langs codes]');
        }
        self.languageMap = query.languageMap;

        self.langSplicers = {};
        self.pickLanguage = true;
        self.splicer = self._createSplicer(query.defaultLanguage);
        break;
<commit_msg>Use path.join(__dirname,'fallbacks.json') for absolute path info<commit_after>const Promise = require('bluebird');
const PbfSplicer = require('./PbfSplicer');
const LanguagePicker = require('./LanguagePicker');
const Err = require('@kartotherian/err');
const checkType = require('@kartotherian/input-validator');
const uptile = require('tilelive-promise');
const fs = require('fs');
const path = require('path');

let core;

function Babel(uri, callback) {
  if (!new.target) {
    return new Babel(uri, callback);
  }

  let self = this;

  Promise.try(() => {
    self = uptile(self);
    const { query } = checkType.normalizeUrl(uri);
    checkType(query, 'source', 'string', true);
    checkType(query, 'tag', 'string', 'name');
    self.nameTag = query.tag;
    checkType(query, 'multiTag', 'string', `${self.nameTag}_`);
    self.multiTag = query.multiTag;
    checkType(query, 'keepUncompressed', 'boolean');
    self.keepUncompressed = query.keepUncompressed;

    switch (uri.protocol) {
      case 'babel:':
        checkType(query, 'combineName', 'boolean', false);
        self.combineName = query.combineName;

        checkType(query, 'defaultLanguage', 'string');
        query.languageMap = query.languageMap || path.join(__dirname, 'fallbacks.json');
        if (typeof query.languageMap === 'string') {
          query.languageMap = JSON.parse(fs.readFileSync(query.languageMap, 'utf8'));
        }
        if (typeof query.languageMap === 'object' &&
          !Array.isArray(query.languageMap)
        ) {
          for (const lang of Object.keys(query.languageMap)) {
            const value = { languageMap: query.languageMap[lang] };
            checkType(value, 'languageMap', 'string-array', true);
            value.languageMap.unshift(lang);
            query.languageMap[lang] = value.languageMap;
          }
        } else {
          throw new Err('languageMap must be a dictionary of' +
            ' langCodes => [list of langs codes]');
        }
        self.languageMap = query.languageMap;

        self.langSplicers = {};
        self.pickLanguage = true;
        self.splicer = self._createSplicer(query.defaultLanguage);
        break;

{'fraction_non_alphanumeric': 0.14577944980014107, 'fraction_numerical': 0.00047025628967787447, 'mean_word_length': 3.03988603988604, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3975710', 'n_tokens_mistral': 1262, 'n_tokens_neox': 1255, 'n_words': 265}