From 7b97729a3817cdbc7f83aec824aefd6a11e90ae1 Mon Sep 17 00:00:00 2001 From: ArnabXD Date: Thu, 23 Sep 2021 09:18:59 +0530 Subject: [PATCH] add bins.su --- .eslintrc.json | 3 ++- README.md | 5 ++-- src/sources/binov-net.ts | 1 - src/sources/bins-su.ts | 56 ++++++++++++++++++++++++++++++++++++++++ src/sources/index.ts | 7 +++-- src/types.ts | 2 +- 6 files changed, 67 insertions(+), 7 deletions(-) create mode 100644 src/sources/bins-su.ts diff --git a/.eslintrc.json b/.eslintrc.json index c66fd0a..8cbd8f4 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -2,7 +2,8 @@ "extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"], "plugins": ["@typescript-eslint"], "rules": { - "@typescript-eslint/no-non-null-asserted-optional-chain": "warn" + "@typescript-eslint/no-non-null-asserted-optional-chain": "off", + "@typescript-eslint/no-non-null-assertion": "off" }, "ignorePatterns": "lib/*" } diff --git a/README.md b/README.md index d7260d1..cecdfe8 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,9 @@ ### Available Sources -- bins.ws -- binov.net +- [bins.ws](http://bins.ws) +- [binov.net](http://binov.net) +- [bins.su](htt[://bins.su]) ### Installation diff --git a/src/sources/binov-net.ts b/src/sources/binov-net.ts index 3da736c..80c4669 100644 --- a/src/sources/binov-net.ts +++ b/src/sources/binov-net.ts @@ -25,7 +25,6 @@ export default async (bin: number): Promise => { const $ = cheerio.load(response.data); if (!$('form.logo table:nth-child(3)').text()) { - console.log(1); return NotFound; } diff --git a/src/sources/bins-su.ts b/src/sources/bins-su.ts new file mode 100644 index 0000000..2cf1dc4 --- /dev/null +++ b/src/sources/bins-su.ts @@ -0,0 +1,56 @@ +import cheerio from 'cheerio'; +import axios from 'axios'; +import iso from 'iso-3166-1'; +import emoji from 'emoji-flags'; +import { NotFound, CustomError } from '../errors'; +import { Result } from '../types'; + +export default async (bin: number): Promise => { + const response = await axios({ + 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 CustomError('Failed to fetch data'); + + const $ = cheerio.load(response.data); + const result = $('#result').html(); + if (!result || !result.match('Total found 1 bins')) { + return 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.countryCode(country); + + return { + result: true, + message: 'Search Successful', + data: { + bin, + vendor, + type, + level, + bank, + country: iso.whereAlpha2(country)?.country.toString()!, + countryInfo: { + name: countryInfo.name.toUpperCase(), + emoji: countryInfo.emoji, + unicode: countryInfo.unicode, + code: countryInfo.code, + }, + }, + }; +}; diff --git a/src/sources/index.ts b/src/sources/index.ts index 29e5ee1..529c3b7 100644 --- a/src/sources/index.ts +++ b/src/sources/index.ts @@ -1,10 +1,13 @@ -import binov from './binov-net'; +import binovnet from './binov-net'; import binsws from './bins-ws'; +import binssu from './bins-su'; + import { Result, Sites } from '../types'; export const sources: { [site in Sites]: (bin: number) => Promise; } = { - 'binov.net': binov, + 'binov.net': binovnet, 'bins.ws': binsws, + 'bins.su': binssu, }; diff --git a/src/types.ts b/src/types.ts index e1bd3b4..c66e329 100644 --- a/src/types.ts +++ b/src/types.ts @@ -17,4 +17,4 @@ export interface Result { }; } -export type Sites = 'binov.net' | 'bins.ws'; +export type Sites = 'binov.net' | 'bins.ws' | 'bins.su';