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

peew

v0.3.1

Published

parses xml using sax.js

Downloads

1

Readme

peew

parses xml using sax.js.

Build Status Dependency Status devDependency Status

Note: This project is under active development. API may change. Requires minimum Node.js version 4.2.1.

API

Tree

Tree can be used to parse XML. Initialize the Tree like so:

const Tree = require('peew').Tree();

const config = {
    strict: true,
    // sax: [sax.js settings]
};

const xmlTree = new Tree(config);

The Tree holds a root element and therefore the XML hierarchy and provides methods to operate on this tree.

Tree.parse(String)

xmlTree.parse('some xml')
	.then(function (res) {
	   // .. do something with the parsed xml
	});

Tree.getRoot()

Return the root element of the tree.

Tree.isElement(element)

Return whether element is an instance of Element.

Element

Any xml object is transformed into a so-called 'Element'. This class holds a JavaScript Objects which contain a name, attributes, children and so on. After using the Tree you will get an Object which is an instance of Element.

The Element class provides you some useful methods that help you find children, iterate over children and so on.

Note: You can use this class to build an xml-like structure using JS objects but you will not be able to transform it to pure XML as this is not supported yet (but is considered as nice to have feature and will be supported in the future).

Element.root()

Returns the root of the Element tree.

Element.up()

Returns the parent Element of the current Element.

Element.get(key)

Returns the Elements attribute named key.

Element.keys()

Returns the Elements attribute names.

Element.setAttributes(Object)

Use an object to set attributes on the current Element.

Element.addChildNode(Element)

Adds the given Element to the children of the current Element. Note: This returns the added child, not the current Element!

Element.setText(String)

Sets Element.text to the text which occur before the first subelement.

Element.find(match)

find() finds the first child with a name matching match.

Element.findAll(match)

findAll() finds all children wit a name matching match.

Element.findText(match)

findText() finds the text for the first direct child of the current element with name matching 'name'

Element.iter(match)

Returns a generator which makes it possible to iterate recursively over the whole tree.

Element.treeFind(match)

Deprecated: Use Element.iter().

treeFind() returns the first Element with the name matching match, searching on the whole tree from the current Element.

Element.treeFindAll(match)

Deprecated: Use Element.iter().

treeFindAll() returns any occurrence of Element.name === 'match' on the whole tree, starting from the current Element.