Skip to content

Commit

Permalink
jsdoc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dbushell committed Mar 3, 2024
1 parent c635b8e commit c46891c
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Fetch and parse XML documents using the power of JavaScript web streams and asyn

## Usage

See the `examples` directory for platform specific examples.
Add dependency from JSR: [@dbushell/xml-streamify](https://jsr.io/@dbushell/xml-streamify). See the `examples` directory for platform specific examples.

```javascript
import {parse} from "jsr:@dbushell/[email protected]";
Expand Down
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dbushell/xml-streamify",
"version": "0.2.1",
"version": "0.2.2",
"exports": {
".": "./mod.ts",
"./node": "./src/node.ts",
Expand Down
4 changes: 4 additions & 0 deletions mod.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @module
* Fetch and parse XML documents using web streams and async iterators.
*/
export * from './src/node.ts';
export * from './src/parse.ts';
export * from './src/stream.ts';
4 changes: 3 additions & 1 deletion src/node.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/**
* XML node with helper methods to read data and traverse the tree
* @module
* Module exports an XML Node class
*/
/** XML node with helper methods to read data and traverse the tree */
export class Node {
#type: string;
#children: Array<Node>;
Expand Down
10 changes: 10 additions & 0 deletions src/parse.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @module
* Module export an async generator function for parsing a streamed XML document.
*/
import type {ParseOptions} from './types.ts';
import {NodeType} from './types.ts';
import {Node} from './node.ts';
Expand All @@ -9,6 +13,12 @@ const ignoreTypes: Partial<Record<NodeType, keyof ParseOptions>> = {
[NodeType.DOCTYPE]: 'ignoreDoctype'
} as const;

/**
* Async generator function for parsing a streamed XML document
* @param url URL to fetch and parse
* @param options Parsing options {@link ParseOptions}
* @returns Yields parsed XML nodes {@link Node}
*/
export async function* parse(
url: string | URL,
options?: ParseOptions
Expand Down
9 changes: 6 additions & 3 deletions src/stream.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @module
* Module exports a `TransformStream` class for decoding binary XML streams into structured data.
*/
import {NodeType, StateType} from './types.ts';

type State = NodeType | StateType;
Expand Down Expand Up @@ -25,6 +29,7 @@ const ENTITIES = {
}
} as const;

/** Transformer object for `TransformStream` constructed by `XMLStream` */
export const transformer: Transformer<Uint8Array, [NodeType, string]> & {
buf: string;
state: State;
Expand Down Expand Up @@ -91,9 +96,7 @@ export const transformer: Transformer<Uint8Array, [NodeType, string]> & {
}
};

/**
* Convert a binary XML stream into a stream of XML nodes
*/
/** Transform a binary XML stream into a stream of structured XML data */
export class XMLStream extends TransformStream<Uint8Array, [NodeType, string]> {
constructor() {
super({...transformer});
Expand Down
5 changes: 5 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* @module
* Types for `@dbushell/xml-streamify`
*/
/** Options for `parse` async generator function */
export interface ParseOptions {
/** Abort signal for fetch and parser */
signal?: AbortSignal;
Expand Down

0 comments on commit c46891c

Please sign in to comment.