@arnabxd/bin-lookup
Version:
Search bin details from various bin database
58 lines (57 loc) • 2.27 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 (0, axios_1.default)({
method: 'POST',
url: 'http://bins.su/',
headers: {
// prettier-ignore
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
'accept-language': 'en-US,en;q=0.9',
'cache-control': 'max-age=0',
'content-type': 'application/x-www-form-urlencoded',
'upgrade-insecure-requests': '1',
},
data: `action=searchbins&bins=${bin}&bank=&country=`,
});
if (!response.data) {
return (0, errors_1.CustomError)('Failed to fetch data');
}
const $ = cheerio_1.default.load(response.data);
const result = $('#result').html();
if (!result || !result.match('Total found 1 bins')) {
return errors_1.NotFound;
}
const country = $('#result tr:nth-child(2) td:nth-child(2)').text();
const vendor = $('#result tr:nth-child(2) td:nth-child(3)').text();
const type = $('#result tr:nth-child(2) td:nth-child(4)').text();
const level = $('#result tr:nth-child(2) td:nth-child(5)').text();
const bank = $('#result tr:nth-child(2) 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,
},
},
};
};