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

xml-trap

v0.1.3

Published

A Typescript XML, RSS and Atom parser

Downloads

8

Readme

XML T.R.A.P. - a Typescript RSS/Atom Feed Parser written in Bun

This is a simple RSS/Atom feed parser written in Typescript, using Bun. It can parse feeds and create an AST of the feed in JSON.

Quickstart

npm install xml-trap 

Usage

You can either use the newFeed function to parse a feed, or the createTree function to create an AST of the feed.

Feeds

To parse an RSS Feed, use the newFeed function.

import { newFeed } from "xml-trap";

const feed = await newFeed("https://example.com/feed.xml");
console.log(feed.title) // The title of the feed

The Feed type has a number of fields that can be accessed:

| Field | Description | | --- | --- | | url | The URL of the feed | | title | The title of the feed | | description | The description of the feed | | language | The language of the feed | | update | The last build date of the feed (or the updated date) | | items | An array of items in the feed | | tree | An AST of the feed in JSON | | source | A minified copy of the source XML |

AST

To create a tree-representation of the feed, use the createTree function.

import { createTree } from "xml-trap";

const tree = createTree("https://example.com/feed.xml");
console.log(tree.root) // The root of the tree

The Tree type has two main fields:

| Field | Description | | --- | --- | | declaration | The XML declaration node | | root | The root node of the tree (and all children) |

The XMLNode type represents nodes on the tree, with fields:

| Field | Description | | --- | --- | | name | The name of the node eg. div, or the node text | | type | The type of the node (eg. Declaration, Opening, Self-closing, etc.) | | attributes | An object of attributes on the node | | value | The value of the node (eg. the text of a text node) | | children | An array of children of the node |

This tree is used to construct feeds, and of course can be re-used as you wish for handling other XML documents.

Tests

Both the AST and Feed Parser are well-covered with unit tests, and more end-to-end-ish tests (reading live feeds). To run the tests:

bun test # run the test suite
bun run test/bench.ts # run the benchmarks

Contributing

This project is open to contributions. As you see above, the project is well-covered with tests. If you want to contribute, it would probably be best to either add a URL to the feed tests, or in the case of the AST modules, adding a new XML document and referencing the benchmarks would be a good place to start.

All contributions should have a test, and should pass or improve the existing suite. Don't worry too much about benchmarks, but if you have a contribution that makes the code faster, you're welcome to add a benchmark to show the improvement.

Setup

To get started, follow these steps:

# Clone the repo
gh repo clone knightspore/xml-trap
cd xml-trap 

# Install dependencies
bun install

# Run the example and start exploring
bun run example.ts

# Once you're done, build the project
bun run build
# And submit a PR with your changes

License

This project is licensed under the MIT License. See the LICENSE file for more information.

Shoutouts