node-csfd-api 2.7.9 → 2.7.10

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.
@@ -0,0 +1 @@
1
+ export declare const fetchSafe: typeof fetch;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fetchSafe = void 0;
4
+ // Check if `fetch` is available in global scope (nodejs 18+) or in window (browser). If not, use cross-fetch polyfill.
5
+ const cross_fetch_1 = require("cross-fetch");
6
+ exports.fetchSafe = (typeof fetch === 'function' && fetch) || // ServiceWorker fetch (Cloud Functions + Chrome extension)
7
+ (typeof global === 'object' && global.fetch) || // Node.js 18+ fetch
8
+ (typeof window !== 'undefined' && window.fetch) || // Browser fetch
9
+ cross_fetch_1.fetch; // Polyfill fetch
package/fetchers/index.js CHANGED
@@ -1,12 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.fetchPage = void 0;
4
- // Check if `fetch` is available in global scope (nodejs 18+) or in window (browser). If not, use cross-fetch polyfill.
5
- const cross_fetch_1 = require("cross-fetch");
6
- const fetchSafe = (typeof fetch === 'function' && fetch) || // ServiceWorker fetch (Cloud Functions + Chrome extension)
7
- (typeof global === 'object' && global.fetch) || // Node.js 18+ fetch
8
- (typeof window !== 'undefined' && window.fetch) || // Browser fetch
9
- cross_fetch_1.fetch; // Polyfill fetch
4
+ const fetch_polyfill_1 = require("./fetch.polyfill");
10
5
  const USER_AGENTS = [
11
6
  'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36',
12
7
  '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',
@@ -18,7 +13,7 @@ const headers = {
18
13
  };
19
14
  const fetchPage = async (url) => {
20
15
  try {
21
- const response = await fetchSafe(url, { headers });
16
+ const response = await (0, fetch_polyfill_1.fetchSafe)(url, { headers });
22
17
  if (response.status >= 400 && response.status < 600) {
23
18
  throw new Error(`node-csfd-api: Bad response ${response.status} for url: ${url}`);
24
19
  }
@@ -4,4 +4,14 @@ export declare const parseIdFromUrl: (url: string) => number;
4
4
  export declare const getColor: (cls: string) => CSFDColorRating;
5
5
  export declare const parseColor: (quality: Colors) => CSFDColorRating;
6
6
  export declare const addProtocol: (url: string) => string;
7
+ export declare const getDuration: (matches: any[]) => {
8
+ sign: string;
9
+ years: any;
10
+ months: any;
11
+ weeks: any;
12
+ days: any;
13
+ hours: any;
14
+ minutes: any;
15
+ seconds: any;
16
+ };
7
17
  export declare const parseISO8601Duration: (iso: string) => number;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseISO8601Duration = exports.addProtocol = exports.parseColor = exports.getColor = exports.parseIdFromUrl = void 0;
3
+ exports.parseISO8601Duration = exports.getDuration = exports.addProtocol = exports.parseColor = exports.getColor = exports.parseIdFromUrl = void 0;
4
4
  const parseIdFromUrl = (url) => {
5
5
  if (url) {
6
6
  const idSlug = url === null || url === void 0 ? void 0 : url.split('/')[2];
@@ -46,10 +46,8 @@ const addProtocol = (url) => {
46
46
  return url.startsWith('//') ? 'https:' + url : url;
47
47
  };
48
48
  exports.addProtocol = addProtocol;
49
- const parseISO8601Duration = (iso) => {
50
- const iso8601DurationRegex = /(-)?P(?:([.,\d]+)Y)?(?:([.,\d]+)M)?(?:([.,\d]+)W)?(?:([.,\d]+)D)?T(?:([.,\d]+)H)?(?:([.,\d]+)M)?(?:([.,\d]+)S)?/;
51
- const matches = iso.match(iso8601DurationRegex);
52
- const duration = {
49
+ const getDuration = (matches) => {
50
+ return {
53
51
  sign: matches[1] === undefined ? '+' : '-',
54
52
  years: matches[2] === undefined ? 0 : matches[2],
55
53
  months: matches[3] === undefined ? 0 : matches[3],
@@ -59,6 +57,12 @@ const parseISO8601Duration = (iso) => {
59
57
  minutes: matches[7] === undefined ? 0 : matches[7],
60
58
  seconds: matches[8] === undefined ? 0 : matches[8]
61
59
  };
60
+ };
61
+ exports.getDuration = getDuration;
62
+ const parseISO8601Duration = (iso) => {
63
+ const iso8601DurationRegex = /(-)?P(?:([.,\d]+)Y)?(?:([.,\d]+)M)?(?:([.,\d]+)W)?(?:([.,\d]+)D)?T(?:([.,\d]+)H)?(?:([.,\d]+)M)?(?:([.,\d]+)S)?/;
64
+ const matches = iso.match(iso8601DurationRegex);
65
+ const duration = (0, exports.getDuration)(matches);
62
66
  return +duration.minutes;
63
67
  };
64
68
  exports.parseISO8601Duration = parseISO8601Duration;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-csfd-api",
3
- "version": "2.7.9",
3
+ "version": "2.7.10",
4
4
  "description": "ČSFD API in JavaScript. Amazing NPM library for scrapping csfd.cz :)",
5
5
  "main": "./index.js",
6
6
  "author": "BART! <bart@bartweb.cz>",
@@ -10,7 +10,7 @@
10
10
  "build": "tsc",
11
11
  "postbuild": "npm-prepare-dist -s postinstall -s prepare",
12
12
  "tsc": "tsc",
13
- "demo": "ts-node demo",
13
+ "demo": "tsx demo",
14
14
  "lint": "eslint ./src/**/**/* --fix",
15
15
  "test": "vitest",
16
16
  "test:coverage": "yarn test run --coverage",
@@ -28,7 +28,7 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "cross-fetch": "^4.0.0",
31
- "node-html-parser": "^6.1.11"
31
+ "node-html-parser": "^6.1.12"
32
32
  },
33
33
  "repository": {
34
34
  "url": "git+https://github.com/bartholomej/node-csfd-api.git",