Skip to content

Commit

Permalink
add bins.su
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnabXD committed Sep 23, 2021
1 parent 55ed296 commit 7b97729
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/*"
}
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion src/sources/binov-net.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export default async (bin: number): Promise<Result> => {
const $ = cheerio.load(response.data);

if (!$('form.logo table:nth-child(3)').text()) {
console.log(1);
return NotFound;
}

Expand Down
56 changes: 56 additions & 0 deletions src/sources/bins-su.ts
Original file line number Diff line number Diff line change
@@ -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<Result> => {
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,
},
},
};
};
7 changes: 5 additions & 2 deletions src/sources/index.ts
Original file line number Diff line number Diff line change
@@ -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<Result>;
} = {
'binov.net': binov,
'binov.net': binovnet,
'bins.ws': binsws,
'bins.su': binssu,
};
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ export interface Result {
};
}

export type Sites = 'binov.net' | 'bins.ws';
export type Sites = 'binov.net' | 'bins.ws' | 'bins.su';

0 comments on commit 7b97729

Please sign in to comment.