Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

source-map

Package Overview
Dependencies
Maintainers
3
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

source-map

Generates and consumes source maps

  • 0.1.43
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
138M
decreased by-13.98%
Maintainers
3
Weekly downloads
 
Created

What is source-map?

The source-map npm package provides utilities for generating and consuming source maps, which are files that map from the transformed source to the original source, enabling the browser to reconstruct the original source and present it in the developer tools. Source maps are commonly used to debug minified code or transpiled code (e.g., from TypeScript or Babel) in an easier-to-read format.

What are source-map's main functionalities?

Generating a source map

This feature allows you to create a source map that maps the code from a minified file back to its original source files. The code sample represents a simple source map in JSON format.

{"version":3,"file":"min.js","names":["bar","baz","n"],"sources":["one.js","two.js"],"sourceRoot":"http://example.com/www/js/","mappings":"CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,MAAM"}

Consuming a source map

This feature allows you to consume a source map and extract information from it, such as the original source files. The code sample demonstrates how to use SourceMapConsumer to read a source map.

const sourceMap = require('source-map');
const consumer = await new sourceMap.SourceMapConsumer('{"version":3,"sources":["foo.js"],"names":["bar"],"mappings":"AAAA","file":"foo.min.js"}');
console.log(consumer.sources); // ['foo.js']

Finding the original position for a generated position

This feature allows you to find the original source position corresponding to a line and column in the generated source. The code sample shows how to retrieve the original position using SourceMapConsumer.

const sourceMap = require('source-map');
const consumer = await new sourceMap.SourceMapConsumer('{"version":3,"sources":["foo.js"],"names":["bar"],"mappings":"AAAA","file":"foo.min.js"}');
const originalPosition = consumer.originalPositionFor({ line: 1, column: 10 });
console.log(originalPosition); // { source: 'foo.js', line: 1, column: 10, name: 'bar' }

Mapping the original source back to the generated code

This feature allows you to map positions in the original source to the corresponding positions in the generated code. The code sample demonstrates how to add a mapping to a SourceMapGenerator instance.

const sourceMap = require('source-map');
const generator = new sourceMap.SourceMapGenerator({ file: 'foo.min.js' });
generator.addMapping({
  generated: { line: 1, column: 10 },
  original: { line: 1, column: 10 },
  source: 'foo.js'
});
const map = generator.toString();
console.log(map);

Other packages similar to source-map

FAQs

Package last updated on 08 Jan 2015

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc