Passed
Pull Request — master (#181)
by Sean
03:09
created

sitemapper.d.ts   A

Complexity

Total Complexity 9
Complexity/F 1

Size

Lines of Code 102
Function Count 9

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 9
eloc 79
mnd 0
bc 0
fnc 9
dl 0
loc 102
rs 10
bpm 0
cpm 1
noi 0
c 0
b 0
f 0

8 Functions

Rating   Name   Duplication   Size   Complexity  
A Sitemapper.crawl 0 1 1
A Sitemapper.parse 0 1 1
A Sitemapper.initializeTimeout 0 2 1
A Sitemapper.getSites 0 8 1
A Sitemapper.parseLocalFile 0 1 1
A Sitemapper.isLocalFile 0 1 1
A Sitemapper.fetch 0 11 1
A Sitemapper.isExcluded 0 1 1
1
import { HttpProxyAgent, HttpsProxyAgent } from 'hpagent';
2
3
export interface SitemapperSiteData {
4
  loc: string;
5
  lastmod?: string;
6
  priority?: string;
7
  changefreq?: string;
8
  [key: string]: any;
9
}
10
11
export interface SitemapperResponse {
12
  url: string;
13
  sites: string[] | SitemapperSiteData[];
14
  errors: SitemapperErrorData[];
15
}
16
17
export type SitemapperResponseSite = { [name in SitemapperField]?: string };
18
19
export interface SitemapperErrorData {
20
  type: string;
21
  url: string;
22
  retries: number;
23
}
24
25
export type SitemapperField =
26
  | 'loc'
27
  | 'sitemap'
28
  | 'lastmod'
29
  | 'changefreq'
30
  | 'priority'
31
  | 'image:loc'
32
  | 'image:title'
33
  | 'image:caption'
34
  | 'video:title'
35
  | 'video:description'
36
  | 'video:thumbnail_loc';
37
38
export type SitemapperFields = { [name in SitemapperField]?: boolean };
39
40
export interface SitemapperOptions {
41
  concurrency?: number;
42
  debug?: boolean;
43
  lastmod?: number;
44
  rejectUnauthorized?: boolean;
45
  requestHeaders?: { [name: string]: string };
46
  retries?: number;
47
  timeout?: number;
48
  url?: string;
49
  fields?: SitemapperFields;
50
  proxyAgent?: HttpProxyAgent | HttpsProxyAgent;
51
  exclusions?: RegExp[];
52
}
53
54
declare class Sitemapper {
55
  timeout: number;
56
  url: string;
57
  debug: boolean;
58
  lastmod: number;
59
  fields?: { [name: string]: boolean };
60
  requestHeaders?: { [name: string]: string };
61
  concurrency?: number;
62
  retries?: number;
63
  rejectUnauthorized?: boolean;
64
  exclusions?: RegExp[];
65
  proxyAgent?: any;
66
  timeoutTable: { [url: string]: NodeJS.Timeout };
67
68
  constructor(options?: SitemapperOptions);
69
70
  private initializeTimeout(url: string, requester: any): void;
71
  private crawl(url: string, retryIndex?: number): Promise<any>;
72
  private parse(url: string): Promise<any>;
73
  private isLocalFile(input: string): boolean;
74
  private parseLocalFile(filePath: string): Promise<any>;
75
  isExcluded(url: string): boolean;
76
77
  /**
78
   * Gets the sites from a sitemap.xml with a given URL or local file path
79
   *
80
   * @param url URL to the sitemap.xml file or path to a local sitemap file
81
   */
82
  fetch(
83
    this: Sitemapper & { fields: object },
84
    url?: string
85
  ): Promise<
86
    Omit<SitemapperResponse, 'sites'> & { sites: SitemapperSiteData[] }
87
  >;
88
  fetch(
89
    url?: string
90
  ): Promise<Omit<SitemapperResponse, 'sites'> & { sites: string[] }>;
91
92
  /**
93
   * @deprecated Use fetch() instead.
94
   */
95
  getSites(
96
    url: string | undefined,
97
    callback: (err: Error | null, sites: string[]) => void
98
  ): Promise<void>;
99
}
100
101
export default Sitemapper;
102