Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shun-shobon/littlexml
1kB XML library for Node.js, Bun, Deno, Browser, Edge runtime.
https://github.com/shun-shobon/littlexml
cloudflare-workers deno javascript typescript xml
Last synced: 25 days ago
JSON representation
1kB XML library for Node.js, Bun, Deno, Browser, Edge runtime.
- Host: GitHub
- URL: https://github.com/shun-shobon/littlexml
- Owner: shun-shobon
- License: mit
- Created: 2023-03-11T06:43:31.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2025-01-10T23:13:41.000Z (about 1 month ago)
- Last Synced: 2025-01-11T01:36:02.904Z (about 1 month ago)
- Topics: cloudflare-workers, deno, javascript, typescript, xml
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@shun-shobon/littlexml
- Size: 1.46 MB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# @shun-shobon/littlexml
1kB XML library for Node.js, Bun, Deno, Browser, Edge runtime.
[![npm](https://img.shields.io/npm/v/@shun-shobon/littlexml?logo=npm)](https://www.npmjs.com/package/@shun-shobon/littlexml)
[![bundle size](https://img.shields.io/bundlephobia/minzip/@shun-shobon/littlexml)](https://bundlephobia.com/package/@shun-shobon/littlexml)
[![test](https://github.com/shun-shobon/littlexml/actions/workflows/check.yml/badge.svg)](https://github.com/shun-shobon/littlexml/actions/workflows/check.yml)
[![codecov](https://codecov.io/gh/shun-shobon/littlexml/branch/master/graph/badge.svg?token=VAZxHGjjpu)](https://codecov.io/gh/shun-shobon/littlexml)## About
This library is designed to run on small JavaScript runtimes such as Cloudflare
Workers. It also works on Node.js, Bun, Deno, and browsers.## Features
- Render XML as a string, iterator, or stream.
- Render XML with indentation.## Support platforms
- Node.js
- Deno
- Bun
- Browser
- Edge runtime like Cloudflare Workers, Vercel Edge Functions## Installation
### Node.js / Bun
Install package from npm. You can also use yarn/pnpm instead of npm.
If you are using Bun, you can install with `bun add` command.```sh
npm install @shun-shobon/littlexml
```You can import from the package as `@shun-shobon/littlexml`.
```ts
import { element, renderToString } from "@shun-shobon/littlexml";
```### Deno
You can directly import from `npm:@shun-shobon/littlexml`.
```ts
import { element, renderToString } from "npm:[email protected]";
```### Browser
You can directly import from `unpkg.com`.
```js
import {
element,
renderToString,
} from "https://unpkg.com/@shun-shobon/[email protected]";
```## Example
This example is rendering a sitemap.
```typescript
import { element, renderToString } from "@shun-shobon/littlexml";const root = element("urlset")
.attr("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9")
.attr("xmlns:image", "http://www.google.com/schemas/sitemap-image/1.1")
.child(
element("url")
.child(element("loc").text("https://example.com/"))
.child(element("lastmod").text("2020-01-01"))
.child(element("changefreq").text("daily"))
.child(element("priority").text("0.8"))
.child(
element("image:image")
.child(element("image:loc").text("https://example.com/image.png"))
.child(element("image:caption").text("caption")),
),
);const xml = renderToString(root, { version: "1.0", indent: 2 });
console.log(xml);
```console output:
```xml
https://example.com/
2020-01-01
daily
0.8
https://example.com/image.png
caption
```