Advertisement
Guest User

usmobile_roaming_analyze.js

a guest
Jun 14th, 2025
708
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function convert(data) {
  2.     const carriers = ["warp", "gsm", "dark_star"];
  3.     const planKey = "annual_unlimited_premium";
  4.  
  5.     const offeringsByCarrier = {}; // carrier -> offering -> country[]
  6.  
  7.     for (const country of data) {
  8.         const countryName = country.country;
  9.         for (const carrier of carriers) {
  10.             const offering = country[carrier][planKey];
  11.  
  12.             let offeringMap = (offeringsByCarrier[carrier] = offeringsByCarrier[carrier] || {});
  13.             let countryList = (offeringMap[offering] = offeringMap[offering] || []);
  14.             countryList.push(countryName);
  15.         }
  16.     }
  17.  
  18.     const countriesByCarrier = {}; // carrier -> Set<country>
  19.     for (const [carrier, offerings] of Object.entries(offeringsByCarrier)) {
  20.         let set = new Set();
  21.         for (const [offering, countries] of Object.entries(offerings)) {
  22.             if (offering == "Unavailable") continue;
  23.  
  24.             // Exclude Warp's eSIM-only (non-native) countries
  25.             if (carrier == "warp" && offering.indexOf("mins") == -1) continue;
  26.  
  27.             set = set.union(new Set(countries));
  28.         }
  29.         countriesByCarrier[carrier] = set;
  30.     }
  31.  
  32.     const exclusives = {}; // carrier -> Set<country>
  33.     for (const [carrier, countries] of Object.entries(countriesByCarrier)) {
  34.         const others = carriers.filter(c => c != carrier);
  35.         const otherSet = others.reduce((accum, carrier) => accum.union(countriesByCarrier[carrier]), new Set());
  36.         const exclusive = countries.difference(otherSet);
  37.         exclusives[carrier] = exclusive;
  38.     }
  39.  
  40.     const countryListString = coll => {
  41.         const arr = Array.from(coll).sort();
  42.         return `${arr.length} countries: ${arr.join(", ")}`;
  43.     };
  44.     const mapValues = (mapping, fn) => {
  45.         let result = {};
  46.         for (const [key, val] of Object.entries(mapping)) {
  47.             result[key] = fn(val);
  48.         }
  49.         return result;
  50.     };
  51.  
  52.     return {
  53.         offeringsByCarrier,
  54.         countriesByCarrier,
  55.         exclusives,
  56.         strings: {
  57.             countriesByCarrier: mapValues(countriesByCarrier, countryListString),
  58.             exclusives: mapValues(exclusives, countryListString),
  59.             offeringsByCarrier: mapValues(offeringsByCarrier, (offerings) => mapValues(offerings, countryListString)),
  60.         }
  61.     };
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement