add tall
This commit is contained in:
parent
929e34834d
commit
172b799a07
9 changed files with 248 additions and 0 deletions
22
node_modules/tall/lib/cjs/index.d.ts
generated
vendored
Normal file
22
node_modules/tall/lib/cjs/index.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
/// <reference types="node" />
|
||||
/// <reference types="node" />
|
||||
import { IncomingMessage } from 'http';
|
||||
import { RequestOptions } from 'https';
|
||||
export declare class Follow {
|
||||
follow: URL;
|
||||
constructor(follow: URL);
|
||||
}
|
||||
export declare class Stop {
|
||||
stop: URL;
|
||||
constructor(stop: URL);
|
||||
}
|
||||
export interface TallPlugin {
|
||||
(url: URL, response: IncomingMessage, previous: Follow | Stop): Promise<Follow | Stop>;
|
||||
}
|
||||
export declare function locationHeaderPlugin(url: URL, response: IncomingMessage, previous: Follow | Stop): Promise<Follow | Stop>;
|
||||
export interface TallOptions extends RequestOptions {
|
||||
maxRedirects: number;
|
||||
timeout: number;
|
||||
plugins: TallPlugin[];
|
||||
}
|
||||
export declare const tall: (url: string, options?: Partial<TallOptions>) => Promise<string>;
|
76
node_modules/tall/lib/cjs/index.js
generated
vendored
Normal file
76
node_modules/tall/lib/cjs/index.js
generated
vendored
Normal file
|
@ -0,0 +1,76 @@
|
|||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.tall = exports.locationHeaderPlugin = exports.Stop = exports.Follow = void 0;
|
||||
const http_1 = require("http");
|
||||
const https_1 = require("https");
|
||||
class Follow {
|
||||
constructor(follow) {
|
||||
this.follow = follow;
|
||||
}
|
||||
}
|
||||
exports.Follow = Follow;
|
||||
class Stop {
|
||||
constructor(stop) {
|
||||
this.stop = stop;
|
||||
}
|
||||
}
|
||||
exports.Stop = Stop;
|
||||
function locationHeaderPlugin(url, response, previous) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const { protocol, host } = url;
|
||||
if (response.headers.location) {
|
||||
const followUrl = new URL(response.headers.location.startsWith('http')
|
||||
? response.headers.location
|
||||
: `${protocol}//${host}${response.headers.location}`);
|
||||
return new Follow(followUrl);
|
||||
}
|
||||
return previous;
|
||||
});
|
||||
}
|
||||
exports.locationHeaderPlugin = locationHeaderPlugin;
|
||||
const defaultOptions = {
|
||||
method: 'GET',
|
||||
maxRedirects: 3,
|
||||
headers: {},
|
||||
timeout: 120000,
|
||||
plugins: [locationHeaderPlugin]
|
||||
};
|
||||
function makeRequest(url, options) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const request = url.protocol === 'https:' ? https_1.request : http_1.request;
|
||||
const req = request(url, options, (response) => {
|
||||
resolve(response);
|
||||
});
|
||||
req.on('error', reject);
|
||||
req.setTimeout(options.timeout, () => req.destroy());
|
||||
req.end();
|
||||
});
|
||||
}
|
||||
const tall = (url, options) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const opt = Object.assign({}, defaultOptions, options);
|
||||
if (opt.maxRedirects <= 0) {
|
||||
return url.toString();
|
||||
}
|
||||
const parsedUrl = new URL(url);
|
||||
let prev = new Stop(parsedUrl);
|
||||
const response = yield makeRequest(parsedUrl, opt);
|
||||
for (const plugin of opt.plugins) {
|
||||
prev = yield plugin(parsedUrl, response, prev);
|
||||
}
|
||||
const maxRedirects = opt.maxRedirects - 1;
|
||||
if (prev instanceof Follow) {
|
||||
return yield (0, exports.tall)(prev.follow.toString(), Object.assign(Object.assign({}, options), { maxRedirects }));
|
||||
}
|
||||
return prev.stop.toString();
|
||||
});
|
||||
exports.tall = tall;
|
||||
//# sourceMappingURL=index.js.map
|
1
node_modules/tall/lib/cjs/index.js.map
generated
vendored
Normal file
1
node_modules/tall/lib/cjs/index.js.map
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+BAA0D;AAC1D,iCAA2D;AAE3D,MAAa,MAAM;IAEjB,YAAY,MAAW;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;CACF;AALD,wBAKC;AAED,MAAa,IAAI;IAEf,YAAY,IAAS;QACnB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;CACF;AALD,oBAKC;AAQD,SAAsB,oBAAoB,CACxC,GAAQ,EACR,QAAyB,EACzB,QAAuB;;QAEvB,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,GAAG,CAAA;QAE9B,IAAI,QAAQ,CAAC,OAAO,CAAC,QAAQ,EAAE;YAC7B,MAAM,SAAS,GAAG,IAAI,GAAG,CACvB,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC;gBAC1C,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ;gBAC3B,CAAC,CAAC,GAAG,QAAQ,KAAK,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,QAAQ,EAAE,CACvD,CAAA;YACD,OAAO,IAAI,MAAM,CAAC,SAAS,CAAC,CAAA;SAC7B;QAED,OAAO,QAAQ,CAAA;IACjB,CAAC;CAAA;AAjBD,oDAiBC;AAQD,MAAM,cAAc,GAAgB;IAClC,MAAM,EAAE,KAAK;IACb,YAAY,EAAE,CAAC;IACf,OAAO,EAAE,EAAE;IACX,OAAO,EAAE,MAAM;IACf,OAAO,EAAE,CAAC,oBAAoB,CAAC;CAChC,CAAA;AAED,SAAS,WAAW,CAAC,GAAQ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AI,IAAI,YAAY,MAAM,EAAE;QAC1B,OAAO,MAAM,IAAA,YAAI,EAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,kCAAO,OAAO,KAAE,YAAY,IAAG,CAAA;KACxE;IAED,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAA;AAC7B,CAAC,CAAA,CAAA;AAtBY,QAAA,IAAI,QAsBhB"}
|
1
node_modules/tall/lib/cjs/package.json
generated
vendored
Normal file
1
node_modules/tall/lib/cjs/package.json
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
{"type":"commonjs"}
|
22
node_modules/tall/lib/esm/index.d.ts
generated
vendored
Normal file
22
node_modules/tall/lib/esm/index.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
/// <reference types="node" />
|
||||
/// <reference types="node" />
|
||||
import { IncomingMessage } from 'http';
|
||||
import { RequestOptions } from 'https';
|
||||
export declare class Follow {
|
||||
follow: URL;
|
||||
constructor(follow: URL);
|
||||
}
|
||||
export declare class Stop {
|
||||
stop: URL;
|
||||
constructor(stop: URL);
|
||||
}
|
||||
export interface TallPlugin {
|
||||
(url: URL, response: IncomingMessage, previous: Follow | Stop): Promise<Follow | Stop>;
|
||||
}
|
||||
export declare function locationHeaderPlugin(url: URL, response: IncomingMessage, previous: Follow | Stop): Promise<Follow | Stop>;
|
||||
export interface TallOptions extends RequestOptions {
|
||||
maxRedirects: number;
|
||||
timeout: number;
|
||||
plugins: TallPlugin[];
|
||||
}
|
||||
export declare const tall: (url: string, options?: Partial<TallOptions>) => Promise<string>;
|
69
node_modules/tall/lib/esm/index.js
generated
vendored
Normal file
69
node_modules/tall/lib/esm/index.js
generated
vendored
Normal file
|
@ -0,0 +1,69 @@
|
|||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
import { request as httpReq } from 'http';
|
||||
import { request as httpsReq } from 'https';
|
||||
export class Follow {
|
||||
constructor(follow) {
|
||||
this.follow = follow;
|
||||
}
|
||||
}
|
||||
export class Stop {
|
||||
constructor(stop) {
|
||||
this.stop = stop;
|
||||
}
|
||||
}
|
||||
export function locationHeaderPlugin(url, response, previous) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const { protocol, host } = url;
|
||||
if (response.headers.location) {
|
||||
const followUrl = new URL(response.headers.location.startsWith('http')
|
||||
? response.headers.location
|
||||
: `${protocol}//${host}${response.headers.location}`);
|
||||
return new Follow(followUrl);
|
||||
}
|
||||
return previous;
|
||||
});
|
||||
}
|
||||
const defaultOptions = {
|
||||
method: 'GET',
|
||||
maxRedirects: 3,
|
||||
headers: {},
|
||||
timeout: 120000,
|
||||
plugins: [locationHeaderPlugin]
|
||||
};
|
||||
function makeRequest(url, options) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const request = url.protocol === 'https:' ? httpsReq : httpReq;
|
||||
const req = request(url, options, (response) => {
|
||||
resolve(response);
|
||||
});
|
||||
req.on('error', reject);
|
||||
req.setTimeout(options.timeout, () => req.destroy());
|
||||
req.end();
|
||||
});
|
||||
}
|
||||
export const tall = (url, options) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const opt = Object.assign({}, defaultOptions, options);
|
||||
if (opt.maxRedirects <= 0) {
|
||||
return url.toString();
|
||||
}
|
||||
const parsedUrl = new URL(url);
|
||||
let prev = new Stop(parsedUrl);
|
||||
const response = yield makeRequest(parsedUrl, opt);
|
||||
for (const plugin of opt.plugins) {
|
||||
prev = yield plugin(parsedUrl, response, prev);
|
||||
}
|
||||
const maxRedirects = opt.maxRedirects - 1;
|
||||
if (prev instanceof Follow) {
|
||||
return yield tall(prev.follow.toString(), Object.assign(Object.assign({}, options), { maxRedirects }));
|
||||
}
|
||||
return prev.stop.toString();
|
||||
});
|
||||
//# sourceMappingURL=index.js.map
|
1
node_modules/tall/lib/esm/index.js.map
generated
vendored
Normal file
1
node_modules/tall/lib/esm/index.js.map
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAmB,OAAO,IAAI,OAAO,EAAE,MAAM,MAAM,CAAA;AAC1D,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAkB,MAAM,OAAO,CAAA;AAE3D,MAAM,OAAO,MAAM;IAEjB,YAAY,MAAW;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;CACF;AAED,MAAM,OAAO,IAAI;IAEf,YAAY,IAAS;QACnB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;CACF;AAQD,MAAM,UAAgB,oBAAoB,CACxC,GAAQ,EACR,QAAyB,EACzB,QAAuB;;QAEvB,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,GAAG,CAAA;QAE9B,IAAI,QAAQ,CAAC,OAAO,CAAC,QAAQ,EAAE;YAC7B,MAAM,SAAS,GAAG,IAAI,GAAG,CACvB,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC;gBAC1C,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ;gBAC3B,CAAC,CAAC,GAAG,QAAQ,KAAK,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,QAAQ,EAAE,CACvD,CAAA;YACD,OAAO,IAAI,MAAM,CAAC,SAAS,CAAC,CAAA;SAC7B;QAED,OAAO,QAAQ,CAAA;IACjB,CAAC;CAAA;AAQD,M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AK,MAAM,MAAM,IAAI,GAAG,CAAC,OAAO,EAAE;QAChC,IAAI,GAAG,MAAM,MAAM,CAAC,SAAS,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAA;KAC/C;IAED,MAAM,YAAY,GAAG,GAAG,CAAC,YAAY,GAAG,CAAC,CAAA;IACzC,IAAI,IAAI,YAAY,MAAM,EAAE;QAC1B,OAAO,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,kCAAO,OAAO,KAAE,YAAY,IAAG,CAAA;KACxE;IAED,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAA;AAC7B,CAAC,CAAA,CAAA"}
|
55
node_modules/tall/package.json
generated
vendored
Normal file
55
node_modules/tall/package.json
generated
vendored
Normal file
|
@ -0,0 +1,55 @@
|
|||
{
|
||||
"name": "tall",
|
||||
"version": "8.0.0",
|
||||
"description": "Promise-based, No-dependency URL unshortner (expander) module for Node.js",
|
||||
"type": "module",
|
||||
"main": "./lib/cjs/index.js",
|
||||
"module": "./lib/esm/index.js",
|
||||
"exports": {
|
||||
"import": "./lib/esm/index.js",
|
||||
"require": "./lib/cjs/index.js"
|
||||
},
|
||||
"files": [
|
||||
"lib/",
|
||||
"!lib/**/*.test*",
|
||||
"!lib/**/jest.*"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=16.0.0"
|
||||
},
|
||||
"engineStrict": true,
|
||||
"scripts": {
|
||||
"clean": "rm -rf ./lib",
|
||||
"build": "tsc -p tsconfig.json && tsc -p tsconfig-cjs.json && echo '{\"type\":\"commonjs\"}' > lib/cjs/package.json",
|
||||
"build:test": "node test/commonjs.cjs && node test/esm.js",
|
||||
"prepublish": "npm run build",
|
||||
"prepare": "npm run build"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/lmammino/tall.git"
|
||||
},
|
||||
"author": {
|
||||
"name": "Luciano Mammino",
|
||||
"url": "https://loige.co"
|
||||
},
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/lmammino/tall/issues"
|
||||
},
|
||||
"homepage": "https://github.com/lmammino/tall#readme",
|
||||
"keywords": [
|
||||
"URL",
|
||||
"shortner",
|
||||
"unshortner",
|
||||
"expander",
|
||||
"tall",
|
||||
"link",
|
||||
"expand link",
|
||||
"expand url",
|
||||
"promise",
|
||||
"no depenencies",
|
||||
"no dependency",
|
||||
"typescript"
|
||||
]
|
||||
}
|
|
@ -21,6 +21,7 @@
|
|||
"q": "^1.5.1",
|
||||
"request": "^2.88.2",
|
||||
"selenium-webdriver": "^4.8.0",
|
||||
"tall": "^8.0.0",
|
||||
"until": "^0.1.1"
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue