Socket
Socket
Sign inDemoInstall

async-saxophone

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-saxophone - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

2

lib/Saxophone.js

@@ -433,3 +433,3 @@ /**

if (isSelfClosing && optAlwaysTagClose && optinclude.has(Node.tagClose)) {
yield [Node.tagClose, input.slice(chunkPos, realTagClose)];
yield [Node.tagClose, input.slice(chunkPos, realTagClose).trim()];
}

@@ -436,0 +436,0 @@

@@ -363,3 +363,3 @@ const test = require('tape-async');

[ 'tagopen', 'selfclose', '', '/' ],
[ 'tagclose', 'selfclose ' ]
[ 'tagclose', 'selfclose' ]
],

@@ -445,2 +445,37 @@ {alwaysTagClose:true}

test('should fail if a generator is used as an iterator without calling it first', assert => {
async function main() {
async function* gen() {
yield '<a';
yield ' />';
}
const parser = makeAsyncXMLParser();
let accum = [];
try {
for await (let node of parser(gen)) {
accum.push(node);
}
} catch (e) {
assert.equal(e.toString(), 'TypeError: sourceIterator is not async iterable');
}
}
main().then(assert.end).catch(assert.fail);
});
test('should take input from a generator', assert => {
async function main() {
async function* gen() {
yield '<a';
yield ' />';
}
const parser = makeAsyncXMLParser();
let accum = [];
for await (let node of parser(gen())) { // note `gen()`, rather than `gen` in the error test above
accum.push(node);
}
assert.deepEqual(accum, [['tagopen', 'a', '', '/']]);
}
main().then(assert.end).catch(assert.fail);
});
test('should err on unclosed CDATA', assert => {

@@ -447,0 +482,0 @@ expectEvents(assert,

{
"name": "async-saxophone",
"description": "Fast and lightweight asynchronous iterator XML parser in pure JavaScript",
"version": "1.0.0",
"version": "1.0.1",
"license": "MIT",

@@ -6,0 +6,0 @@ "main": "lib/index.js",

@@ -7,10 +7,12 @@ # async-saxophone

Instead, it implements an async iterator. Async-saxophone takes as input an XML document in the form of a string or any iterator, including a stream. It parses the XML and then outputs the nodes (tags, text, comments, etc) encountered as they are parsed. As an async iterator, it is suitable for iteration using `for await...of`.
Instead, it implements an async iterator. Async-saxophone takes as input an XML document in the form of a string or any iterable, including a stream. It parses the XML and then outputs the nodes (tags, text, comments, etc) encountered as they are parsed. As an async iterator, it is suitable for iteration using `for await...of`.
Async-saxophone was developed to assure that a new chunk of XML is not taken from its input until all nodes encountered have been processed, even if there is delay in processing. The asynchronous design assures synchronization of input and output.
The async-saxophone parser is based upon the Saxophone parser and inherits its light weight and speed. It does not maintain document state nor check the validity of the document. Modifications to the Saxophone parser include structuring it as an async generator function, substituting `yield` for `emit`, expecting an input string or iterator as an argument, rather than being piped to, and representing each node as a tuple-like array.
The async-saxophone parser is based upon the Saxophone parser and inherits its light weight and speed. It does not maintain document state nor check the validity of the document. Modifications to the Saxophone parser include structuring it as an async generator function, substituting `yield` for `emit`, expecting an input string or iterable as an argument, rather than being piped to, and representing each node as a tuple-like array.
The parser does not parse the attribute string in a tag nor does it parse entities in text. `Saxophone`'s `parseAttrs` and `parseEntities` functions may be used to parse the attribute string or entities. To avoid unnecessary dependencies, `Saxophone` must be installed seperately if these functions are needed.
Note that if a generator function is passed as the iteratable, a `"sourceIterator is not async iterable"` error will be thrown. Consider a generator function to be a iterable factory. Call it to get the iterator. If a generator `async function* genxml() {...}` is defined, pass `genxml()` to the parser rather than `genxml`.
## Installation

@@ -72,4 +74,4 @@

* `options` are detailed below.
* `parser(iterator)` is the async generator function returned from `makeAsyncXMLParser`.
* It takes as an argument any iterator over an XML document.
* `parser(iterable)` is the async generator function returned from `makeAsyncXMLParser`.
* It takes as an argument any iterable of an XML document.
* It returns an async iterator over the nodes encountered as the document is parsed.

@@ -84,3 +86,3 @@

The parser returned from `makeAsyncXMLParser` is an async generator function. It takes an iterator as an argument and returns an async iterator over the nodes encountered during parsing. The types of nodes and their representation is as follows:
The parser returned from `makeAsyncXMLParser` is an async generator function. It takes an iterable as an argument and returns an async iterator over the nodes encountered during parsing. The types of nodes and their representation is as follows:

@@ -87,0 +89,0 @@ - **tagopen**: `['tagopen', tag-name, attr-string, is-self-closing]`.

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc