Passed
Pull Request — master (#163)
by Sean
02:41
created

Sitemapper.parse   A

Complexity

Conditions 1

Size

Total Lines 1
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 1
c 0
b 0
f 0
rs 10
cc 1
1
export interface SitemapperSiteData {
2
  loc: string;
3
  sitemap: string;
4
  lastmod?: string;
5
  priority?: string;
6
  changefreq?: string;
7
  [key: string]: any;
8
}
9
10
export interface SitemapperResponse {
11
  url: string;
12
  sites: SitemapperSiteData[];
13
  errors: SitemapperErrorData[];
14
}
15
16
export interface SitemapperErrorData {
17
  type: string;
18
  url: string;
19
  retries: number;
20
}
21
22
export interface SitemapperOptions {
23
  concurrency?: number;
24
  debug?: boolean;
25
  lastmod?: number;
26
  rejectUnauthorized?: boolean;
27
  requestHeaders?: { [name: string]: string };
28
  retries?: number;
29
  timeout?: number;
30
  url?: string;
31
  fields?: { [name: string]: boolean };
32
  proxyAgent?: any;
33
  exclusions?: RegExp[];
34
}
35
36
declare class Sitemapper {
37
  timeout: number;
38
  url: string;
39
  debug: boolean;
40
  lastmod: number;
41
  fields?: { [name: string]: boolean };
42
  requestHeaders?: { [name: string]: string };
43
  concurrency?: number;
44
  retries?: number;
45
  rejectUnauthorized?: boolean;
46
  exclusions?: RegExp[];
47
  proxyAgent?: any;
48
  timeoutTable: { [url: string]: NodeJS.Timeout };
49
50
  constructor(options?: SitemapperOptions);
51
52
  private initializeTimeout(url: string, requester: any): void;
53
  private crawl(url: string, retryIndex?: number): Promise<any>;
54
  private parse(url: string): Promise<any>;
55
  isExcluded(url: string): boolean;
56
57
  /**
58
   * Gets the sites from a sitemap.xml with a given URL
59
   *
60
   * @param url URL to the sitemap.xml file
61
   */
62
  fetch(
63
    this: Sitemapper & { fields?: object },
64
    url?: string
65
  ): Promise<
66
    Omit<SitemapperResponse, 'sites'> & { sites: SitemapperSiteData[] }
67
  >;
68
69
  /**
70
   * @deprecated Use fetch() instead.
71
   */
72
  getSites(
73
    url: string | undefined,
74
    callback: (err: Error | null, sites: string[]) => void
75
  ): Promise<void>;
76
}
77
78
export default Sitemapper;
79