Socket
Socket
Sign inDemoInstall

source-map-js

Package Overview
Dependencies
Maintainers
0
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

source-map-js

Generates and consumes source maps


Version published
Weekly downloads
32M
increased by10.33%
Maintainers
0
Weekly downloads
 
Created

What is source-map-js?

The source-map-js npm package is a library for generating and consuming source maps, which are files that map from the transformed source to the original source, enabling the user to see the original source before it was transformed. This is particularly useful for debugging minified code or transpiled code, such as TypeScript or Babel output.

What are source-map-js's main functionalities?

Generating a source map

This feature allows you to generate a source map that describes how the code has been transformed. The code sample is a JSON representation of a source map.

{"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,KACb,IAAI,IAAM,SAAUE,GAClB,OAAOA"}

Consuming a source map

This feature allows you to consume a source map to retrieve the original position of a piece of code. The code sample shows how to use the SourceMapConsumer to get the original position of a code snippet.

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

Creating a source map generator

This feature allows you to create a source map generator which can be used to add mappings. The code sample demonstrates how to instantiate a SourceMapGenerator and add a mapping to it.

const sourceMap = require('source-map-js');
const generator = new sourceMap.SourceMapGenerator({
  file: 'min.js',
  sourceRoot: 'http://example.com/www/js/'
});
generator.addMapping({
  generated: { line: 1, column: 0 },
  original: { line: 1, column: 0 },
  source: 'one.js'
});
console.log(generator.toString());

Other packages similar to source-map-js

FAQs

Package last updated on 08 Sep 2024

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