# sitemapd

> Runtime-neutral sitemap parsing and bounded traversal

Latest version **0.2.3** (published 2026-10-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install sitemapd
pnpm add sitemapd
yarn add sitemapd
bun add sitemapd
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.2.3 |
| Published | 2026-10-12 |
| First published | 2026-07-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=18.0.0 |
| Dependencies | 1 |
| Unpacked size | 87.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 440 |
| Author | Harlan Wilton |
| Maintainers | harlan_zw |
| Keywords | sitemap, xml, rss, atom, crawler |

## Links

- npm: https://www.npmjs.com/package/sitemapd
- Repository: https://github.com/nuxt-modules/sitemap
- Homepage: https://github.com/nuxt-modules/sitemap/tree/main/packages/sitemapd#readme
- Issues: https://github.com/nuxt-modules/sitemap/issues
- Funding: https://github.com/sponsors/harlan-zw
- npm.io page: https://npm.io/package/sitemapd

## Dependencies (1)

- [fast-xml-parser](https://npm.io/package/fast-xml-parser.md) ^5.11.2

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 0.2.3 (latest) — 2026-10-12
- 0.2.2 — 2026-08-09
- 0.2.1 — 2026-08-03
- 0.2.0 — 2026-07-29
- 0.1.0 — 2026-07-29

## README

# sitemapd

Runtime-neutral sitemap parsing and bounded traversal for Node, browsers, [Bun](https://bun.sh),
and workerd.

```ts
import { collectSitemap } from 'sitemapd/parse'

const result = await collectSitemap(response.body!)
```

Use `sitemapd` for an injected reader and `sitemapd/fetch` for the generic Fetch
adapter. Network authority, DNS security, storage, and product policy remain
the host's responsibility.

## Bounded traversal

`createSitemapReader()` accepts injected document loading and target
authorization. Its `walk()` method owns one aggregate breadth-first budget
across every root and descendant:

```ts
import { createSitemapReader } from 'sitemapd'

const reader = createSitemapReader({
  loadDocument,
  authorizeTarget,
  limits: {
    maxDepth: 3,
    maxDocuments: 100,
    maxUrls: 2_000_000,
  },
})

const digests = new Map<string, string>()
const result = await reader.walk(roots, {
  concurrency: 4,
  retention: 'none',
  async onDocument(document) {
    if (document.document._tag === 'urlset')
      digests.set(document.resolvedUrl, await digest(document.document.entries))
  },
})
```

Reads may finish out of order. The reader visits each document once in
deterministic breadth-first order while preserving root and index-child order.
The visitor is awaited serially and applies backpressure to traversal.

`retention: 'all'` is the default and retains deduplicated URL entries plus
index references in the result. `retention: 'none'` returns empty aggregate
arrays after the visitor processes each document. This keeps only the bounded
scheduler window and caller-owned reductions in memory. The `entriesRetained`
discriminator narrows these result shapes.

`maxUrls` counts URL records in breadth-first commit order, including duplicates.
This conservative accounting is identical in both retention modes.
`urlsObserved` and `referencesObserved` expose the aggregate counters. Reaching
any traversal budget returns an explicit partial result.

Passing an `AbortSignal` stops scheduling, aborts active reads cooperatively,
and returns a partial result with the `cancelled` reason. A visitor rejection or
an unexpected loader or authorizer exception aborts active reads and rejects
`walk()` with the original error. Tagged read failures remain values in the
walk result.

Body stream and iterator failures return a read failure with `reason: 'load'`.
The reader preserves recognized loader `code` values and maps other body failures to `network`.
Native `AbortError` and `TimeoutError` failures map to `cancelled` and `timeout`.
Traversal records these failures and continues eligible sibling documents.
Parser configuration errors and unexpected loader or authorizer exceptions still reject the operation.

Partial results expose a breadth-first `frontier`. Pass that frontier into a
later `walk()` together with the previously committed document URLs to continue
without resetting depth or reading a document twice:

```ts
const first = await reader.walk(roots, {
  maxDocuments: 40,
  retention: 'none',
})

if (first._tag === 'partial' && first.frontier.length > 0) {
  const resumed = await reader.walk(first.frontier, {
    seenDocuments: committedDocumentUrls,
    maxDocuments: 40,
    retention: 'none',
  })
}
```

The frontier contains only scheduler work that remained eligible. Children
blocked by `maxDepth` are excluded, so resuming cannot bypass the original depth
limit. Read failures remain tagged values; the host decides whether to add a
failed entry to a later frontier.

---
_Source: https://npm.io/package/sitemapd · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
