npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tsxml

v0.1.0

Published

**A no-dependency XML parser with DOM-like AST and XML serialization for node.js and the browser.**

Downloads

1,183

Readme

tsxml

A no-dependency XML parser with DOM-like AST and XML serialization for node.js and the browser.

Overview

tsxml is a small, not (yet) spec compliant XML library that contains a liberal parser, a syntax tree similar to, but not as complicated as, the DOM. The syntax tree can be used to build XML manually. It can serialize formatted and compact XML.

It supports all kinds of XML nodes, including comments, markup declaration openers (such as <!DOCTYPE ...>), processing instructions (<?svg...) and self closing (<foo />) and "void" (<foo>) nodes, meaning it's capable of parsing HTML and SVG, too.

Is it used somewhere?

Yup, here: vs-code-xml-format.

Status Quo

Parser

The parser is:

  • liberal in what it accepts

The parser is not (yet):

  • incremental
  • capable of streaming

At the moment the parser only processes complete XML strings at once, incremental parsing is not possible yet (which can be a performance issue with huge documents). If you need incremental parsing and are comfortable with using streams, check out sax-js.

Schema Validation

Does not exist. At least not yet.

Syntax Tree

The syntax tree can be built manually (see examples) or by the parser. It is similar to the DOM, but not quite as complex. It can be used to traverse (in fact, the parser uses AST nodes it creates to traverse while parsing) and to serialize XML.

To-Do-List:

  • XPath support

XML Serialization (converting objects to XML strings)

Syntax tree nodes support XML serialization with their toString() and toFormattedString() methods, for example:

const document = xml.Compiler.parseStringToAst(`
	<foo><bar /></foo>
`);
/*
	The following 2 statements will log '<foo><bar /></foo>' 
*/
console.log(node.toString());
console.log(node + '');
/*
	The following statement will log:
		<foo>
			<bar />
		</foo> 
*/
node.toFormattedString();

Formatting can also be done in a somewhat more concise way:

console.log(await xml.Compiler.formatXmlString('<foo><bar /></foo>'));
/*
	...which will log:
		<foo>
			<bar />
		</foo> 
*/

Why build another XML parser, aren't there plenty already?

I see your point. There's plenty of good parsers around and most of them get the job done alright. What I wanted, however, is a tool that runs in every environment (browser, node.js, you name it), doesn't come with a myriad of dependencies (especially ones that run in node's C-space), that doesn't just ignore comments, MDOs and processing instructions (which are a huge no-no in some other libraries) and that, ideally, has a syntax tree that allows traversal similar to the DOM instead of just providing plain old objects. Oh, right, there should be a way to serialize XML as well.

If you don't need all of this, you might want to check out these:

Alternatives

License

MIT. See LICENSE file.