<commit_before>const axios = require('axios');
const wrapAPIKey = require('./wrap-api-key');
const classifier = require('ammobin-classifier');

module.exports = function (type) {
  function fn(ammotype) {
    return axios({
      url: "https://wrapapi.com/use/meta-ammo-ca/theammosource/theammosource/latest",
      method: 'post',
      data: {
        ammotype,
        wrapAPIKey
      }
    }).then(d => {
      if(!d.data.data.items){
        console.warn('no items found for theammosource '+type);
        return [];
      }
      
      return d.data.data.items;
    });
  }


  switch (type) {
    case 'rimfire':
      return fn('1_9').then(classifier.classifyRimfire);
    case 'shotgun':
      return fn('1_48').then(classifier.classifyShotgun);
    case 'centerfire':
      return Promise.all([
        fn('1_33'), // pistol
        fn('1_40') // rifle
      ])
        .then(results => results.reduce((final, r) => final.concat(r), []))
        .then(classifier.classifyCenterFire);

    default:
      return Promise.reject(new Error('unknown type: ' + type));
  }
}<commit_msg>Update the-ammo-source.js (#8)<commit_after>const axios = require('axios');
const wrapAPIKey = require('./wrap-api-key');
const classifier = require('ammobin-classifier');


function classifyRimfire(items) {
  return items.map(i => {
    i.calibre = classifier.classifyRimfire(i.calibre || i.name || '').toUpperCase()
    return i;
  });
}

function classifyCenterfire(items) {
  return items.map(i => {
    i.calibre = classifier.classifyCenterFire(i.calibre || i.name || '').toUpperCase()
    return i;
  });
}

function classifyShotgun(items) {
  return items.map(i => {
    i.calibre = classifier.classifyShotgun(i.calibre || i.name || '').toUpperCase()
    return i;
  });
}

module.exports = function (type) {
  function fn(ammotype) {
    return axios({
      url: "https://wrapapi.com/use/meta-ammo-ca/theammosource/theammosource/latest",
      method: 'post',
      data: {
        ammotype,
        wrapAPIKey
      }
    }).then(d => {
      if(!d.data.data.items){
        console.warn('no items found for theammosource '+type);
        return [];
      }
      
      return d.data.data.items;
    });
  }


  switch (type) {
    case 'rimfire':
      return fn('1_9').then(classifyRimfire);
    case 'shotgun':
      return fn('1_48').then(classifyShotgun);
    case 'centerfire':
      return Promise.all([
        fn('1_33'), // pistol
        fn('1_40') // rifle
      ])
        .then(results => results.reduce((final, r) => final.concat(r), []))
        .then(classifier.classifyCenterFire);

    default:
      return Promise.reject(new Error('unknown type: ' + type));
  }
}
{'fraction_non_alphanumeric': 0.1656122069222181, 'fraction_numerical': 0.008559732043170823, 'mean_word_length': 2.662125340599455, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, 'https://': 2, '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': '4379093', 'n_tokens_mistral': 923, 'n_tokens_neox': 894, 'n_words': 158}