Comparing version 1.0.2 to 2.0.0
export declare const fetch: (url: string) => Promise<any>; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,81 +1,81 @@ | ||
import * as t from './types'; | ||
declare class _ARQ { | ||
arqApi: string; | ||
constructor(arqApi: string); | ||
url: string; | ||
key: string; | ||
constructor(url: string, key: string); | ||
private fetch; | ||
/** | ||
* Get direct Deezer song link. | ||
* @param query | ||
* @param limit | ||
* Search Deezer and get direct links to download songs. | ||
*/ | ||
deezer(query: string, count: number): Promise<any>; | ||
deezer(query: string, count: number): Promise<t.DeezerResult>; | ||
/** | ||
* | ||
* @param query | ||
* Search for Torrents across various websites. | ||
*/ | ||
torrent(query: string): Promise<any>; | ||
torrent(query: string): Promise<t.TorrentResult>; | ||
/** | ||
* | ||
* @param query | ||
* Get songs from Saavn. | ||
*/ | ||
saavn(query: string): Promise<any>; | ||
saavn(query: string): Promise<t.SaavnResult>; | ||
/** | ||
* Get information about a Saavn playlist. | ||
*/ | ||
saavnPlaylist(query: string): Promise<any>; | ||
/** | ||
* Search for YouTube videos. | ||
* @param query | ||
*/ | ||
youtube(query: string): Promise<any>; | ||
youtube(query: string): Promise<t.YouTubeResult>; | ||
/** | ||
* | ||
* @param query | ||
* Search for wallpapares. | ||
*/ | ||
wall(query: string): Promise<any>; | ||
wall(query: string): Promise<t.WallResult>; | ||
/** | ||
* | ||
* @param query | ||
* Search for Reddit posts. | ||
*/ | ||
reddit(query: string): Promise<any>; | ||
reddit(query: string): Promise<t.RedditResult>; | ||
/** | ||
* Search the Urban dictionary. | ||
* @param query | ||
*/ | ||
ud(query: string): Promise<any>; | ||
ud(query: string): Promise<t.UdResult>; | ||
/** | ||
* | ||
* @param query | ||
* Search for a PH video. | ||
*/ | ||
ph(query: string): Promise<any>; | ||
ph(query: string): Promise<t.PhDlResult>; | ||
/** | ||
* | ||
* @param query | ||
* Download a PH video. | ||
*/ | ||
phdl(query: string): Promise<any>; | ||
phDownload(url: string): Promise<t.PhDlResult>; | ||
/** | ||
* | ||
* @param query | ||
* Communicate with an AI chatbot. | ||
*/ | ||
luna(query: string): Promise<any>; | ||
luna(query: string): Promise<t.LunaResult>; | ||
/** | ||
* | ||
* @param query | ||
* Get song lyrics. | ||
*/ | ||
lyrics(query: string): Promise<any>; | ||
lyrics(query: string): Promise<t.LyricsResult>; | ||
/** | ||
* | ||
* @param query | ||
* Search Wikipeida. | ||
*/ | ||
wiki(query: string): Promise<any>; | ||
wiki(query: string): Promise<t.WikiResult>; | ||
/** | ||
* | ||
* @param url | ||
* Scan and classify an image. | ||
*/ | ||
nsfwScan(url: string): Promise<any>; | ||
nsfwScan(url: string): Promise<t.NsfwScanResult>; | ||
/** | ||
* | ||
* @param url | ||
* Recognize characters in an image. | ||
*/ | ||
ocr(url: string): Promise<any>; | ||
ocr(url: string): Promise<t.OcrResult>; | ||
/** | ||
* | ||
* Get stats of the ARQ API. | ||
*/ | ||
stats(): Promise<any>; | ||
stats(): Promise<t.StatsResults>; | ||
/** | ||
* Generate a true random number using atmospheric noises. | ||
*/ | ||
random(min: number, max: number): Promise<t.RandomResult>; | ||
/** | ||
* Get a sock5 proxy. | ||
*/ | ||
proxy(): Promise<t.ProxyResult>; | ||
} | ||
export declare const ARQ: typeof _ARQ; | ||
export {}; |
@@ -38,14 +38,48 @@ "use strict"; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ARQ = void 0; | ||
var querystring_1 = require("querystring"); | ||
var fetcher_1 = require("./fetcher"); | ||
var node_fetch_1 = __importDefault(require("node-fetch")); | ||
var _ARQ = /** @class */ (function () { | ||
function _ARQ(arqApi) { | ||
this.arqApi = arqApi; | ||
function _ARQ(url, key) { | ||
this.url = url.endsWith('/') ? url : url + '/'; | ||
this.key = key; | ||
} | ||
_ARQ.prototype.fetch = function (route, query) { | ||
if (query === void 0) { query = {}; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var response, _a, ok, result; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: return [4 /*yield*/, node_fetch_1.default(this.url + route + '?' + querystring_1.encode(query), { | ||
method: 'GET', | ||
headers: { 'x-api-key': this.key }, | ||
})]; | ||
case 1: | ||
response = _b.sent(); | ||
if (response.status == 403 || response.status == 401) { | ||
throw new Error('Invalid API key'); | ||
} | ||
return [4 /*yield*/, response.json()]; | ||
case 2: | ||
_a = _b.sent(), ok = _a.ok, result = _a.result; | ||
if (typeof ok === 'undefined' || typeof result == 'undefined') { | ||
throw new Error('Invalid response'); | ||
} | ||
if (ok) { | ||
return [2 /*return*/, result]; | ||
} | ||
else { | ||
throw new Error(result); | ||
} | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** | ||
* Get direct Deezer song link. | ||
* @param query | ||
* @param limit | ||
* Search Deezer and get direct links to download songs. | ||
*/ | ||
@@ -56,3 +90,3 @@ _ARQ.prototype.deezer = function (query, count) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, fetcher_1.fetch(this.arqApi + "/deezer?" + querystring_1.encode({ query: query, count: count }))]; | ||
case 0: return [4 /*yield*/, this.fetch('deezer', { query: query, count: count })]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
@@ -64,4 +98,3 @@ } | ||
/** | ||
* | ||
* @param query | ||
* Search for Torrents across various websites. | ||
*/ | ||
@@ -72,3 +105,3 @@ _ARQ.prototype.torrent = function (query) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, fetcher_1.fetch(this.arqApi + "/torrent?" + querystring_1.encode({ query: query }))]; | ||
case 0: return [4 /*yield*/, this.fetch('torrent', { query: query })]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
@@ -80,4 +113,3 @@ } | ||
/** | ||
* | ||
* @param query | ||
* Get songs from Saavn. | ||
*/ | ||
@@ -88,3 +120,3 @@ _ARQ.prototype.saavn = function (query) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, fetcher_1.fetch(this.arqApi + "/saavn?" + querystring_1.encode({ query: query }))]; | ||
case 0: return [4 /*yield*/, this.fetch('saavn', { query: query })]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
@@ -96,4 +128,16 @@ } | ||
/** | ||
* Get information about a Saavn playlist. | ||
*/ | ||
_ARQ.prototype.saavnPlaylist = function (query) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.fetch('saavnPlaylist', { query: query })]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** | ||
* Search for YouTube videos. | ||
* @param query | ||
*/ | ||
@@ -104,3 +148,3 @@ _ARQ.prototype.youtube = function (query) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, fetcher_1.fetch(this.arqApi + "/youtube?" + querystring_1.encode({ query: query }))]; | ||
case 0: return [4 /*yield*/, this.fetch('youtube', { query: query })]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
@@ -112,4 +156,3 @@ } | ||
/** | ||
* | ||
* @param query | ||
* Search for wallpapares. | ||
*/ | ||
@@ -120,3 +163,3 @@ _ARQ.prototype.wall = function (query) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, fetcher_1.fetch(this.arqApi + "/wall?" + querystring_1.encode({ query: query }))]; | ||
case 0: return [4 /*yield*/, this.fetch('wall', { query: query })]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
@@ -128,4 +171,3 @@ } | ||
/** | ||
* | ||
* @param query | ||
* Search for Reddit posts. | ||
*/ | ||
@@ -136,3 +178,3 @@ _ARQ.prototype.reddit = function (query) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, fetcher_1.fetch(this.arqApi + "/reddit?" + querystring_1.encode({ query: query }))]; | ||
case 0: return [4 /*yield*/, this.fetch('reddit', { query: query })]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
@@ -145,3 +187,2 @@ } | ||
* Search the Urban dictionary. | ||
* @param query | ||
*/ | ||
@@ -152,3 +193,3 @@ _ARQ.prototype.ud = function (query) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, fetcher_1.fetch(this.arqApi + "/ud?" + querystring_1.encode({ query: query }))]; | ||
case 0: return [4 /*yield*/, this.fetch('ud', { query: query })]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
@@ -160,4 +201,3 @@ } | ||
/** | ||
* | ||
* @param query | ||
* Search for a PH video. | ||
*/ | ||
@@ -168,3 +208,3 @@ _ARQ.prototype.ph = function (query) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, fetcher_1.fetch(this.arqApi + "/ph?" + querystring_1.encode({ query: query }))]; | ||
case 0: return [4 /*yield*/, this.fetch('ph', { query: query })]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
@@ -176,10 +216,9 @@ } | ||
/** | ||
* | ||
* @param query | ||
* Download a PH video. | ||
*/ | ||
_ARQ.prototype.phdl = function (query) { | ||
_ARQ.prototype.phDownload = function (url) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, fetcher_1.fetch(this.arqApi + "/phdl?" + querystring_1.encode({ query: query }))]; | ||
case 0: return [4 /*yield*/, this.fetch('phdl', { url: url })]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
@@ -191,4 +230,3 @@ } | ||
/** | ||
* | ||
* @param query | ||
* Communicate with an AI chatbot. | ||
*/ | ||
@@ -199,3 +237,3 @@ _ARQ.prototype.luna = function (query) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, fetcher_1.fetch(this.arqApi + "/luna?" + querystring_1.encode({ query: query }))]; | ||
case 0: return [4 /*yield*/, this.fetch('luna', { query: query })]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
@@ -207,4 +245,3 @@ } | ||
/** | ||
* | ||
* @param query | ||
* Get song lyrics. | ||
*/ | ||
@@ -215,3 +252,3 @@ _ARQ.prototype.lyrics = function (query) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, fetcher_1.fetch(this.arqApi + "/lyrics?" + querystring_1.encode({ query: query }))]; | ||
case 0: return [4 /*yield*/, this.fetch('lyrics', { query: query })]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
@@ -223,4 +260,3 @@ } | ||
/** | ||
* | ||
* @param query | ||
* Search Wikipeida. | ||
*/ | ||
@@ -231,3 +267,3 @@ _ARQ.prototype.wiki = function (query) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, fetcher_1.fetch(this.arqApi + "/wiki?" + querystring_1.encode({ query: query }))]; | ||
case 0: return [4 /*yield*/, this.fetch('wiki', { query: query })]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
@@ -239,4 +275,3 @@ } | ||
/** | ||
* | ||
* @param url | ||
* Scan and classify an image. | ||
*/ | ||
@@ -247,3 +282,3 @@ _ARQ.prototype.nsfwScan = function (url) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, fetcher_1.fetch(this.arqApi + "/wiki?" + querystring_1.encode({ url: url }))]; | ||
case 0: return [4 /*yield*/, this.fetch('nsfw_scan', { url: url })]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
@@ -255,4 +290,3 @@ } | ||
/** | ||
* | ||
* @param url | ||
* Recognize characters in an image. | ||
*/ | ||
@@ -263,3 +297,3 @@ _ARQ.prototype.ocr = function (url) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, fetcher_1.fetch(this.arqApi + "/wiki?" + querystring_1.encode({ url: url }))]; | ||
case 0: return [4 /*yield*/, this.fetch('ocr', { url: url })]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
@@ -271,3 +305,3 @@ } | ||
/** | ||
* | ||
* Get stats of the ARQ API. | ||
*/ | ||
@@ -278,3 +312,3 @@ _ARQ.prototype.stats = function () { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, fetcher_1.fetch(this.arqApi + "/stats")]; | ||
case 0: return [4 /*yield*/, this.fetch('stats')]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
@@ -285,4 +319,30 @@ } | ||
}; | ||
/** | ||
* Generate a true random number using atmospheric noises. | ||
*/ | ||
_ARQ.prototype.random = function (min, max) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.fetch('stats', { min: min, max: max })]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** | ||
* Get a sock5 proxy. | ||
*/ | ||
_ARQ.prototype.proxy = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.fetch('proxy')]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
return _ARQ; | ||
}()); | ||
exports.ARQ = _ARQ; |
{ | ||
"name": "arq-js", | ||
"version": "1.0.2", | ||
"version": "2.0.0", | ||
"description": "", | ||
@@ -13,3 +13,3 @@ "main": "dist/index.js", | ||
"type": "git", | ||
"url": "git+https://github.com/rojserbest/arqjs.git" | ||
"url": "git+https://github.com/rojserbest/arq-js.git" | ||
}, | ||
@@ -19,5 +19,5 @@ "author": "Roj Serbest <rojserbest@gmail.com>", | ||
"bugs": { | ||
"url": "https://github.com/rojserbest/arqjs/issues" | ||
"url": "https://github.com/rojserbest/arq-js/issues" | ||
}, | ||
"homepage": "https://github.com/rojserbest/arqjs#readme", | ||
"homepage": "https://github.com/rojserbest/arq-js", | ||
"dependencies": { | ||
@@ -24,0 +24,0 @@ "node-fetch": "^2.6.1" |
@@ -0,0 +0,0 @@ # ARQJS |
156
src/index.ts
import { encode } from 'querystring'; | ||
import { fetch } from './fetcher'; | ||
import fetch from 'node-fetch'; | ||
import * as t from './types'; | ||
class _ARQ { | ||
arqApi: string; | ||
url: string; | ||
key: string; | ||
constructor(arqApi: string) { | ||
this.arqApi = arqApi; | ||
constructor(url: string, key: string) { | ||
this.url = url.endsWith('/') ? url : url + '/'; | ||
this.key = key; | ||
} | ||
private async fetch(route: string, query: { [key: string]: any } = {}) { | ||
const response = await fetch(this.url + route + '?' + encode(query), { | ||
method: 'GET', | ||
headers: { 'x-api-key': this.key }, | ||
}); | ||
if (response.status == 403 || response.status == 401) { | ||
throw new Error('Invalid API key'); | ||
} | ||
const { ok, result } = await response.json(); | ||
if (typeof ok === 'undefined' || typeof result == 'undefined') { | ||
throw new Error('Invalid response'); | ||
} | ||
if (ok) { | ||
return result; | ||
} else { | ||
throw new Error(result); | ||
} | ||
} | ||
/** | ||
* Get direct Deezer song link. | ||
* @param query | ||
* @param limit | ||
* Search Deezer and get direct links to download songs. | ||
*/ | ||
async deezer(query: string, count: number) { | ||
return await fetch(`${this.arqApi}/deezer?${encode({ query, count })}`); | ||
async deezer(query: string, count: number): Promise<t.DeezerResult> { | ||
return await this.fetch('deezer', { query, count }); | ||
} | ||
/** | ||
* | ||
* @param query | ||
* Search for Torrents across various websites. | ||
*/ | ||
async torrent(query: string) { | ||
return await fetch(`${this.arqApi}/torrent?${encode({ query })}`); | ||
async torrent(query: string): Promise<t.TorrentResult> { | ||
return await this.fetch('torrent', { query }); | ||
} | ||
/** | ||
* | ||
* @param query | ||
* Get songs from Saavn. | ||
*/ | ||
async saavn(query: string) { | ||
return await fetch(`${this.arqApi}/saavn?${encode({ query })}`); | ||
async saavn(query: string): Promise<t.SaavnResult> { | ||
return await this.fetch('saavn', { query }); | ||
} | ||
/** | ||
* Get information about a Saavn playlist. | ||
*/ | ||
async saavnPlaylist(query: string): Promise<any> { | ||
return await this.fetch('saavnPlaylist', { query }); | ||
} | ||
/** | ||
* Search for YouTube videos. | ||
* @param query | ||
*/ | ||
async youtube(query: string) { | ||
return await fetch(`${this.arqApi}/youtube?${encode({ query })}`); | ||
async youtube(query: string): Promise<t.YouTubeResult> { | ||
return await this.fetch('youtube', { query }); | ||
} | ||
/** | ||
* | ||
* @param query | ||
* Search for wallpapares. | ||
*/ | ||
async wall(query: string) { | ||
return await fetch(`${this.arqApi}/wall?${encode({ query })}`); | ||
async wall(query: string): Promise<t.WallResult> { | ||
return await this.fetch('wall', { query }); | ||
} | ||
/** | ||
* | ||
* @param query | ||
* Search for Reddit posts. | ||
*/ | ||
async reddit(query: string) { | ||
return await fetch(`${this.arqApi}/reddit?${encode({ query })}`); | ||
async reddit(query: string): Promise<t.RedditResult> { | ||
return await this.fetch('reddit', { query }); | ||
} | ||
@@ -62,72 +88,78 @@ | ||
* Search the Urban dictionary. | ||
* @param query | ||
*/ | ||
async ud(query: string) { | ||
return await fetch(`${this.arqApi}/ud?${encode({ query })}`); | ||
async ud(query: string): Promise<t.UdResult> { | ||
return await this.fetch('ud', { query }); | ||
} | ||
/** | ||
* | ||
* @param query | ||
* Search for a PH video. | ||
*/ | ||
async ph(query: string) { | ||
return await fetch(`${this.arqApi}/ph?${encode({ query })}`); | ||
async ph(query: string): Promise<t.PhDlResult> { | ||
return await this.fetch('ph', { query }); | ||
} | ||
/** | ||
* | ||
* @param query | ||
* Download a PH video. | ||
*/ | ||
async phdl(query: string) { | ||
return await fetch(`${this.arqApi}/phdl?${encode({ query })}`); | ||
async phDownload(url: string): Promise<t.PhDlResult> { | ||
return await this.fetch('phdl', { url }); | ||
} | ||
/** | ||
* | ||
* @param query | ||
* Communicate with an AI chatbot. | ||
*/ | ||
async luna(query: string) { | ||
return await fetch(`${this.arqApi}/luna?${encode({ query })}`); | ||
async luna(query: string): Promise<t.LunaResult> { | ||
return await this.fetch('luna', { query }); | ||
} | ||
/** | ||
* | ||
* @param query | ||
* Get song lyrics. | ||
*/ | ||
async lyrics(query: string) { | ||
return await fetch(`${this.arqApi}/lyrics?${encode({ query })}`); | ||
async lyrics(query: string): Promise<t.LyricsResult> { | ||
return await this.fetch('lyrics', { query }); | ||
} | ||
/** | ||
* | ||
* @param query | ||
* Search Wikipeida. | ||
*/ | ||
async wiki(query: string) { | ||
return await fetch(`${this.arqApi}/wiki?${encode({ query })}`); | ||
async wiki(query: string): Promise<t.WikiResult> { | ||
return await this.fetch('wiki', { query }); | ||
} | ||
/** | ||
* | ||
* @param url | ||
* Scan and classify an image. | ||
*/ | ||
async nsfwScan(url: string) { | ||
return await fetch(`${this.arqApi}/wiki?${encode({ url })}`); | ||
async nsfwScan(url: string): Promise<t.NsfwScanResult> { | ||
return await this.fetch('nsfw_scan', { url }); | ||
} | ||
/** | ||
* | ||
* @param url | ||
* Recognize characters in an image. | ||
*/ | ||
async ocr(url: string) { | ||
return await fetch(`${this.arqApi}/wiki?${encode({ url })}`); | ||
async ocr(url: string): Promise<t.OcrResult> { | ||
return await this.fetch('ocr', { url }); | ||
} | ||
/** | ||
* | ||
* Get stats of the ARQ API. | ||
*/ | ||
async stats() { | ||
return await fetch(`${this.arqApi}/stats`); | ||
async stats(): Promise<t.StatsResults> { | ||
return await this.fetch('stats'); | ||
} | ||
/** | ||
* Generate a true random number using atmospheric noises. | ||
*/ | ||
async random(min: number, max: number): Promise<t.RandomResult> { | ||
return await this.fetch('stats', { min, max }); | ||
} | ||
/** | ||
* Get a sock5 proxy. | ||
*/ | ||
async proxy(): Promise<t.ProxyResult> { | ||
return await this.fetch('proxy'); | ||
} | ||
} | ||
export const ARQ = _ARQ; |
@@ -0,0 +0,0 @@ { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
34301
17
905