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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@remotex-labs/xmap

v6.0.1

Published

A library with a sourcemap parser and TypeScript code formatter for the CLI

Readme

xMap

Documentation npm version downloads License: MPL 2.0 Test CI Discord Ask DeepWiki

@remotex-labs/xmap is a TypeScript library for source maps, stack traces, and terminal code output. It parses Source Map v3 payloads, maps generated positions back to the original sources, normalizes error stacks from V8, SpiderMonkey, and JavaScriptCore, and renders the surrounding code with syntax highlighting and error indicators.

Key Features

  • Source map processing: parse Source Map v3 payloads and query them by generated or original position.
  • Bias-aware lookups: choose how inexact positions resolve with Bias.BOUND, LOWER_BOUND, and UPPER_BOUND.
  • Map merging: concatenate several maps into one service with SourceService.assign, keeping indices correct.
  • Stack trace parsing: turn a V8, SpiderMonkey, or JavaScriptCore stack into structured frames.
  • Error resolution: map a parsed stack back to original sources with resolveError and stackEntry.
  • Code formatting: render snippets with line numbers, custom padding, and per-line callbacks.
  • Syntax highlighting: semantic TypeScript highlighting with a customizable color scheme.
  • Tree-shakeable: side-effect-free ESM with subpath exports, so you ship only the components you import.

Installation

Install @remotex-labs/xmap using npm:

npm install @remotex-labs/xmap

Or using Yarn:

yarn add @remotex-labs/xmap

The package requires Node.js 20 or later, and works in the browser through a bundler.

Usage

Import from the root entry point, or from a subpath to pull in a single component:

import { SourceService, Bias } from '@remotex-labs/xmap';
import { parseErrorStack } from '@remotex-labs/xmap/parser.component';
import { formatCode, formatErrorCode } from '@remotex-labs/xmap/formatter.component';
import { highlightCode } from '@remotex-labs/xmap/highlighter.component';

The subpath exports are the smallest units the package offers; use them when you only need the parser, the formatter, or the highlighter and want the rest tree-shaken away.

Key Components

SourceService

Load a source map, then query it for original positions, positions with the original content, or positions with a window of surrounding code.

import { SourceService, Bias } from '@remotex-labs/xmap';

// Create from a JSON string or a parsed source map object
const sourceService = new SourceService(sourceMapJSON, 'bundle.js');

// Original position for a generated line and column
const originalPosition = sourceService.getPosition(12, 34);

// Original position for a known source file
const byOriginal = sourceService.getPositionByOriginal(3, 7, 'index.ts');

// Position with a window of surrounding code
const positionWithCode = sourceService.getPositionWithCode(12, 34, Bias.LOWER_BOUND, {
    linesAfter: 2,
    linesBefore: 2
});

Merge several maps into a single service with the static assign helper:

const merged = SourceService.assign(sourceA, sourceB);

Bias

When no segment matches the requested column exactly, Bias decides which neighbour wins:

  • Bias.BOUND - closest match, with no directional preference
  • Bias.LOWER_BOUND - prefers segments with a column less than or equal to the target
  • Bias.UPPER_BOUND - prefers segments with a column greater than or equal to the target
const exactPosition = sourceService.getPosition(10, 15, Bias.BOUND);
const beforePosition = sourceService.getPosition(10, 15, Bias.LOWER_BOUND);
const afterPosition = sourceService.getPosition(10, 15, Bias.UPPER_BOUND);

Stack Trace Parser

Parse an error stack from any supported engine into a normalized structure.

import { parseErrorStack } from '@remotex-labs/xmap/parser.component';

try {
    throw new Error('Example error');
} catch (error) {
    const parsedStack = parseErrorStack(<Error> error);

    console.log(parsedStack.name);     // "Error"
    console.log(parsedStack.message);  // "Example error"

    const frame = parsedStack.stack[0];
    console.log(frame.fileName);       // File where the error occurred
    console.log(frame.line);           // Line number
    console.log(frame.functionName);   // Function name
}

Code Highlighter

Apply semantic TypeScript highlighting, with the default scheme or one of your own.

import { highlightCode } from '@remotex-labs/xmap/highlighter.component';

const code = `
function sum(a: number, b: number): number {
  return a + b;
}
`;

// Default color scheme
const highlightedCode = highlightCode(code);

// Or override individual colors
const customHighlightedCode = highlightCode(code, {
    numberColor: (text: string): string => `\x1b[31m${ text }\x1b[0m`,
    stringColor: (text: string): string => `\x1b[32m${ text }\x1b[0m`,
    keywordColor: (text: string): string => `\x1b[36m${ text }\x1b[0m`
});

console.log(customHighlightedCode);

Highlighted code

Code Formatter

formatCode adds line numbers with configurable padding, and can run a callback on a chosen line - useful for documentation snippets and debug output.

import { formatCode } from '@remotex-labs/xmap/formatter.component';
import { highlightCode } from '@remotex-labs/xmap/highlighter.component';

const code = `
function greet(name: string) {
  console.log('Hello, ' + name);
}

greet('World');
`;

const formattedCode = formatCode(highlightCode(code), {
    action: {
        callback: (lineString, padding, lineNumber) => `*** Line ${ lineNumber } ***\n${ lineString }`,
        triggerLine: 3
    },
    padding: 8,
    startLine: 1
});

console.log(formattedCode);

Formatted code

formatErrorCode takes a resolved position and marks the offending column.

import { formatErrorCode } from '@remotex-labs/xmap/formatter.component';

const sourcePosition = {
    code: 'function divide(a, b) {\n  return a / b;\n}',
    line: 2,
    name: null,
    column: 13,
    source: '',
    endLine: 0,
    startLine: 1,
    sourceRoot: null,
    sourceIndex: 0,
    generatedLine: 0,
    generatedColumn: 0
};

const formattedError = formatErrorCode(sourcePosition, {
    color: (text) => `\x1b[31m${ text }\x1b[0m`  // Red error indicator
});

console.log(formattedError);

Formatted error

Practical Examples

Resolving a thrown error back to its source

import { SourceService, Bias } from '@remotex-labs/xmap';
import { parseErrorStack } from '@remotex-labs/xmap/parser.component';
import { formatErrorCode } from '@remotex-labs/xmap/formatter.component';
import { highlightCode } from '@remotex-labs/xmap/highlighter.component';

try {
    throw new Error('Something went wrong');
} catch (error) {
    const parsedStack = parseErrorStack(<Error> error);
    const frame = parsedStack.stack[0];

    if (frame.fileName && frame.line && frame.column) {
        const sourceService = new SourceService(sourceMapJSON);
        const position = sourceService.getPositionWithCode(
            frame.line,
            frame.column,
            Bias.LOWER_BOUND,
            { linesBefore: 2, linesAfter: 2 }
        );

        if (position) {
            position.code = highlightCode(position.code);
            console.log('Error occurred:');
            console.log(formatErrorCode(position, {
                color: (text) => `\x1b[31m${ text }\x1b[0m`
            }));
        }
    }
}

Querying a source map directly

import { SourceService } from '@remotex-labs/xmap';

const sourceMapJSON = `
{
  "version": 3,
  "sources": ["../src/core/core.component.ts", "../src/index.ts"],
  "sourceRoot": "https://github.com/remotex-labs/xMap/tree/test/",
  "sourcesContent": [
    "export class CoreModule {\\r\\n  private name: string;\\r\\n}",
    "import { CoreModule } from '@core/core.component';\\r\\nconsole.log(new CoreModule('Core Module'));"
  ],
  "mappings":
    "aAAO,IAAMA,EAAN,KAAiB,CACZ,KAER,YAAYC,EAAc,CACtB,KAAK,KAAOA,CAChB,CAEO,OAAgB,CACnB,MAAO,cAAc,KAAK,IAAI,GAClC,CACJ,ECRA,IAAMC,EAAe,IAAIC,EAAW,aAAa,EAEjD,QAAQ,IAAID,EAAa,MAAM,CAAC",
  "names": ["CoreModule", "name", "coreInstance", "CoreModule"]
}
`;

const sourceService = new SourceService(sourceMapJSON, 'bundle.js');
console.log(sourceService.getPositionByOriginal(3, 7, 'index.ts'));
console.log(sourceService.getPositionWithCode(1, 104, 1, { linesBefore: 2, linesAfter: 2 }));

Documentation

Full guides and the complete API reference live at remotex-labs.github.io/xMap.

Contributing

Contributions are welcome!
Please see our Contributing Guide for details.

Links

License

This project is licensed under the Mozilla Public License 2.0 - see the LICENSE file for details.