UNPKG

2.21 kBTypeScriptView Raw
1/// <reference types="node" />
2import { SAXStream } from 'sax';
3import { Readable, Transform, TransformOptions, TransformCallback } from 'stream';
4import { SitemapItem, ErrorLevel } from './types';
5declare type Logger = (level: 'warn' | 'error' | 'info' | 'log', ...message: Parameters<Console['log']>[0]) => void;
6export interface XMLToSitemapItemStreamOptions extends TransformOptions {
7 level?: ErrorLevel;
8 logger?: Logger | false;
9}
10/**
11 * Takes a stream of xml and transforms it into a stream of SitemapItems
12 * Use this to parse existing sitemaps into config options compatible with this library
13 */
14export declare class XMLToSitemapItemStream extends Transform {
15 level: ErrorLevel;
16 logger: Logger;
17 saxStream: SAXStream;
18 constructor(opts?: XMLToSitemapItemStreamOptions);
19 _transform(data: string, encoding: string, callback: TransformCallback): void;
20}
21/**
22 Read xml and resolve with the configuration that would produce it or reject with
23 an error
24 ```
25 const { createReadStream } = require('fs')
26 const { parseSitemap, createSitemap } = require('sitemap')
27 parseSitemap(createReadStream('./example.xml')).then(
28 // produces the same xml
29 // you can, of course, more practically modify it or store it
30 (xmlConfig) => console.log(createSitemap(xmlConfig).toString()),
31 (err) => console.log(err)
32 )
33 ```
34 @param {Readable} xml what to parse
35 @return {Promise<SitemapItem[]>} resolves with list of sitemap items that can be fed into a SitemapStream. Rejects with an Error object.
36 */
37export declare function parseSitemap(xml: Readable): Promise<SitemapItem[]>;
38export interface ObjectStreamToJSONOptions extends TransformOptions {
39 lineSeparated: boolean;
40}
41/**
42 * A Transform that converts a stream of objects into a JSON Array or a line
43 * separated stringified JSON
44 * @param [lineSeparated=false] whether to separate entries by a new line or comma
45 */
46export declare class ObjectStreamToJSON extends Transform {
47 lineSeparated: boolean;
48 firstWritten: boolean;
49 constructor(opts?: ObjectStreamToJSONOptions);
50 _transform(chunk: SitemapItem, encoding: string, cb: TransformCallback): void;
51 _flush(cb: TransformCallback): void;
52}
53export {};
54
\No newline at end of file