New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@dataxquare/sitemapper

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dataxquare/sitemapper

Parser for XML Sitemaps to be used with Robots.txt and web crawlers

latest
Source
npmnpm
Version
1.2.0
Version published
Maintainers
1
Created
Source
Sitemapper - A powerful XML sitemap parser for Node.js

Test Codecov npm version Monthly Downloads Libraries.io dependency status for latest release License MIT

📋 Overview

Sitemapper is a Node.js module that makes it easy to parse XML sitemaps. It supports single sitemaps, sitemap indexes with multiple sitemaps, and various sitemap formats including image and video sitemaps.

🚀 Installation

# Using npm
npm install sitemapper --save

# Using yarn
yarn add sitemapper

# Using pnpm
pnpm add sitemapper

🏃‍♂️ Quick Start

Module Usage

import Sitemapper from 'sitemapper';

const sitemap = new Sitemapper({
  timeout: 10000, // 10 second timeout
});

sitemap
  .fetch('https://gosla.sh/sitemap.xml')
  .then(({ url, sites }) => {
    console.log('Sites: ', sites);
  })
  .catch((error) => console.error(error));

CLI Usage

You can also use Sitemapper directly from the command line:

# Using npx
npx sitemapper https://gosla.sh/sitemap.xml

💻 Examples

Promise Example

import Sitemapper from 'sitemapper';

const sitemap = new Sitemapper();

sitemap
  .fetch('https://wp.seantburke.com/sitemap.xml')
  .then(({ url, sites }) => {
    console.log(`Sitemap URL: ${url}`);
    console.log(`Found ${sites.length} URLs`);
    console.log(sites);
  })
  .catch((error) => console.error(error));

Async/Await Example

import Sitemapper from 'sitemapper';

async function parseSitemap() {
  const Google = new Sitemapper({
    url: 'https://www.google.com/work/sitemap.xml',
    timeout: 15000, // 15 seconds
    concurrency: 10,
  });

  try {
    const { sites } = await Google.fetch();
    console.log(`Found ${sites.length} URLs in the sitemap`);
    console.log(sites);
  } catch (error) {
    console.error('Error fetching sitemap:', error);
  }
}

parseSitemap();

Advanced Example with Proxy

import Sitemapper from 'sitemapper';
import { HttpsProxyAgent } from 'hpagent';

const sitemapper = new Sitemapper({
  url: 'https://gosla.sh/sitemap.xml',
  timeout: 30000,
  concurrency: 5,
  retries: 2,
  debug: true,
  proxyAgent: new HttpsProxyAgent({
    proxy: 'http://localhost:8080',
  }),
  requestHeaders: {
    'User-Agent': 'Mozilla/5.0 (compatible; SitemapperBot/1.0)',
  },
  fields: {
    loc: true,
    lastmod: true,
    sitemap: true,
  },
});

sitemapper
  .fetch()
  .then(({ sites }) => console.log(sites))
  .catch((error) => console.error(error));

⚙️ Configuration Options

Sitemapper can be customized with the following options:

OptionTypeDefaultDescription
urlStringundefinedThe URL of the sitemap to parse
timeoutNumber15000Maximum timeout in milliseconds for each request
concurrencyNumber10Maximum number of concurrent requests when crawling multiple sitemaps
retriesNumber0Number of retry attempts for failed requests
debugBooleanfalseEnable debug logging
rejectUnauthorizedBooleantrueReject invalid SSL certificates (like self-signed or expired)
requestHeadersObject{}Additional HTTP headers to include with requests
lastmodNumberundefinedOnly return URLs with lastmod timestamp newer than this value
proxyAgentHttpProxyAgent | HttpsProxyAgentundefinedInstance of hpagent for proxy support
exclusionsArray<RegExp>[]Array of regex patterns to exclude URLs from results
fieldsObjectundefinedSpecify which fields to include in the results (see below)

Available Fields

Important: When using the fields option, the return format changes from an array of URL strings to an array of objects containing your selected fields.

For the fields option, specify which fields to include by setting them to true:

FieldDescription
locURL location of the page
sitemapURL of the sitemap containing this URL (useful for sitemap indexes)
lastmodDate of last modification
changefreqHow frequently the page is likely to change
priorityPriority of this URL relative to other URLs
image:locURL location of the image (for image sitemaps)
image:titleTitle of the image (for image sitemaps)
image:captionCaption of the image (for image sitemaps)
video:titleTitle of the video (for video sitemaps)
video:descriptionDescription of the video (for video sitemaps)
video:thumbnail_locThumbnail URL of the video (for video sitemaps)

Example Default Output (without fields)

// Returns an array of URL strings
[
  'https://wp.seantburke.com/?p=234',
  'https://wp.seantburke.com/?p=231',
  'https://wp.seantburke.com/?p=185',
];

Example Output with Fields

// Returns an array of objects
[
  {
    loc: 'https://wp.seantburke.com/?p=234',
    lastmod: '2015-07-03T02:05:55+00:00',
    priority: 0.8,
  },
  {
    loc: 'https://wp.seantburke.com/?p=231',
    lastmod: '2015-07-03T01:47:29+00:00',
    priority: 0.8,
  },
];

🧩 CLI Usage

Sitemapper includes a simple CLI tool for basic sitemap parsing directly from the command line:

npx sitemapper <sitemap-url>

Example

npx sitemapper https://gosla.sh/sitemap.xml

Output

The CLI will display the sitemap URL and list all URLs found in the sitemap:

Sitemap URL: https://gosla.sh/sitemap.xml

Found URLs:
1. https://gosla.sh/page1
2. https://gosla.sh/page2
3. https://gosla.sh/page3
...

CLI Options

Currently, the CLI supports the --timeout parameter to set the request timeout in milliseconds:

npx sitemapper https://gosla.sh/sitemap.xml --timeout=5000

Note: The CLI implementation is basic and does not yet support all options available in the JavaScript API. More advanced features like fields filtering, concurrency control, and different output formats require using the JavaScript API directly.

🤝 Contributing

Contributions from experienced engineers are highly valued. When contributing, please consider:

Guidelines

  • Maintain backward compatibility where possible
  • Consider performance implications, particularly for large sitemaps
  • Add TypeScript types
  • Add tests for your change
  • Update documentation and examples
  • Check for typos
  • Code should pass ESLint, Prettier, Spell Check and TypeScript checks
  • Try not to bloat the main dependencies with new packages, dev dependencies are fine
  • If adding packages, make sure to run npm install with the latest NPM version to update package-lock.json

Pull Request Process

  • PRs should be focused on a single concern/feature
  • Include sufficient context in the PR description
  • Reference any relevant issues
  • Run npm test locally to verify your changes pass the test
    • Sometimes the tests will fail since they reference real world sitemaps. Try running it again.
  • PRs will not run github actions by default, they need to be run manually by @seantomburke

For substantial changes, consider opening an issue for discussion before implementation.

Note: The CI pipeline enforces TypeScript type checking, linting rules, formatting standards, and test coverage thresholds.

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

Keywords

parse

FAQs

Package last updated on 01 Oct 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts