UNPKG

2.26 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 error: Error | null;
18 saxStream: SAXStream;
19 constructor(opts?: XMLToSitemapItemStreamOptions);
20 _transform(data: string, encoding: string, callback: TransformCallback): void;
21 private err;
22}
23/**
24 Read xml and resolve with the configuration that would produce it or reject with
25 an error
26 ```
27 const { createReadStream } = require('fs')
28 const { parseSitemap, createSitemap } = require('sitemap')
29 parseSitemap(createReadStream('./example.xml')).then(
30 // produces the same xml
31 // you can, of course, more practically modify it or store it
32 (xmlConfig) => console.log(createSitemap(xmlConfig).toString()),
33 (err) => console.log(err)
34 )
35 ```
36 @param {Readable} xml what to parse
37 @return {Promise<SitemapItem[]>} resolves with list of sitemap items that can be fed into a SitemapStream. Rejects with an Error object.
38 */
39export declare function parseSitemap(xml: Readable): Promise<SitemapItem[]>;
40export interface ObjectStreamToJSONOptions extends TransformOptions {
41 lineSeparated: boolean;
42}
43/**
44 * A Transform that converts a stream of objects into a JSON Array or a line
45 * separated stringified JSON
46 * @param [lineSeparated=false] whether to separate entries by a new line or comma
47 */
48export declare class ObjectStreamToJSON extends Transform {
49 lineSeparated: boolean;
50 firstWritten: boolean;
51 constructor(opts?: ObjectStreamToJSONOptions);
52 _transform(chunk: SitemapItem, encoding: string, cb: TransformCallback): void;
53 _flush(cb: TransformCallback): void;
54}
55export {};
56
\No newline at end of file