node-csfd-api 3.0.0-next.4 → 3.0.0-next.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/fetchers/index.js +8 -2
- package/esm/fetchers/index.js +8 -2
- package/package.json +2 -2
package/cjs/fetchers/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// import fetch from 'cross-fetch';
|
|
3
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -9,8 +8,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
9
|
});
|
|
11
10
|
};
|
|
11
|
+
var _a;
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
exports.fetchPage = void 0;
|
|
14
|
+
// Check if `fetch` is available in global scope (nodejs 18+) or in window (browser)
|
|
15
|
+
// If not, use cross-fetch polyfill
|
|
16
|
+
const cross_fetch_1 = require("cross-fetch");
|
|
17
|
+
const fetchSafe = (_a = ((typeof fetch === 'function' && fetch) ||
|
|
18
|
+
(typeof global === 'object' && global.fetch) ||
|
|
19
|
+
(typeof window !== 'undefined' && window.fetch))) !== null && _a !== void 0 ? _a : cross_fetch_1.fetch;
|
|
14
20
|
const USER_AGENTS = [
|
|
15
21
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36',
|
|
16
22
|
'Mozilla/5.0 (iPhone; CPU iPhone OS 14_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/87.0.4280.77 Mobile/15E148 Safari/604.1',
|
|
@@ -22,7 +28,7 @@ const headers = {
|
|
|
22
28
|
};
|
|
23
29
|
const fetchPage = (url) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
30
|
try {
|
|
25
|
-
const response = yield
|
|
31
|
+
const response = yield fetchSafe(url, { headers });
|
|
26
32
|
if (response.status >= 400 && response.status < 600) {
|
|
27
33
|
throw new Error(`node-csfd-api: Bad response ${response.status} for url: ${url}`);
|
|
28
34
|
}
|
package/esm/fetchers/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// import fetch from 'cross-fetch';
|
|
2
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -8,6 +7,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
8
|
});
|
|
10
9
|
};
|
|
10
|
+
var _a;
|
|
11
|
+
// Check if `fetch` is available in global scope (nodejs 18+) or in window (browser)
|
|
12
|
+
// If not, use cross-fetch polyfill
|
|
13
|
+
import { fetch as crossFetch } from 'cross-fetch';
|
|
14
|
+
const fetchSafe = (_a = ((typeof fetch === 'function' && fetch) ||
|
|
15
|
+
(typeof global === 'object' && global.fetch) ||
|
|
16
|
+
(typeof window !== 'undefined' && window.fetch))) !== null && _a !== void 0 ? _a : crossFetch;
|
|
11
17
|
const USER_AGENTS = [
|
|
12
18
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36',
|
|
13
19
|
'Mozilla/5.0 (iPhone; CPU iPhone OS 14_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/87.0.4280.77 Mobile/15E148 Safari/604.1',
|
|
@@ -19,7 +25,7 @@ const headers = {
|
|
|
19
25
|
};
|
|
20
26
|
export const fetchPage = (url) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
27
|
try {
|
|
22
|
-
const response = yield
|
|
28
|
+
const response = yield fetchSafe(url, { headers });
|
|
23
29
|
if (response.status >= 400 && response.status < 600) {
|
|
24
30
|
throw new Error(`node-csfd-api: Bad response ${response.status} for url: ${url}`);
|
|
25
31
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-csfd-api",
|
|
3
|
-
"version": "3.0.0-next.
|
|
3
|
+
"version": "3.0.0-next.6",
|
|
4
4
|
"description": "ČSFD API in JavaScript. Amazing NPM library for scrapping csfd.cz :)",
|
|
5
5
|
"main": "./cjs/index.js",
|
|
6
6
|
"author": "BART! <bart@bartweb.cz>",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"lint": "eslint ./src/**/**/* --fix",
|
|
16
16
|
"test": "jest",
|
|
17
17
|
"fix-paths": "yarn json -I -f ./dist/package.json -e \"this.module='./esm/index.js';this.main='./cjs/index.js';this.types='./types/index.d.ts'\"",
|
|
18
|
-
"publish:next": "yarn && yarn build && yarn test --coverage true && cd dist && npm publish --tag
|
|
18
|
+
"publish:next": "yarn && yarn build && yarn test --coverage true && cd dist && npm publish --tag next",
|
|
19
19
|
"postversion": "git push && git push --follow-tags",
|
|
20
20
|
"release:beta": "npm version preminor --preid=beta -m \"chore(update): prelease %s β\"",
|
|
21
21
|
"prerelease:beta": "npm version prerelease --preid=beta -m \"chore(update): prelease %s β\"",
|