@arnabxd/bin-lookup
Version:
Search bin details from various bin database
46 lines (45 loc) • 1.72 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const cheerio_1 = __importDefault(require("cheerio"));
const axios_1 = __importDefault(require("axios"));
const emoji_flags_1 = __importDefault(require("emoji-flags"));
const utils_1 = require("../utils");
const errors_1 = require("../errors");
exports.default = async (bin) => {
const response = await axios_1.default.get(`https://bins.ws/search?bins=${bin}`);
if (!response.data) {
return (0, errors_1.CustomError)('Failed to fetch data');
}
const $ = cheerio_1.default.load(response.data);
const message = $('.page h2').text();
if (!message.match('Total found 1 bins')) {
return errors_1.NotFound;
}
const type = $('table.dataframe td:nth-child(2)').text();
const level = $('table.dataframe td:nth-child(3)').text();
const vendor = $('table.dataframe td:nth-child(4)').text();
const bank = $('table.dataframe td:nth-child(5)').text();
const country = $('table.dataframe td:nth-child(6)').text();
const countryInfo = emoji_flags_1.default.countryCode(country);
return {
result: true,
message: 'Search Successful',
data: {
bin,
vendor,
type,
level,
bank,
country: (0, utils_1.alphaToCountry)(country),
countryInfo: {
name: countryInfo.name,
emoji: countryInfo.emoji,
unicode: countryInfo.unicode,
code: countryInfo.code,
},
},
};
};