source-map
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Source-map is a JavaScript library used for generating and consuming the source map format. It was developed by Mozilla as part of their Rust and WebAssembly compilation pipeline. Source maps help improve the debugging process by offering a way to map a combined or minified file back to its original source.
Using Source Map in your JavaScript project is straightforward. You can install the package via npm by using the npm install command: npm install source-map
. Once installed, you can include it in your project with the require syntax: var sourceMap = require('source-map');
.
As an example, the following code demonstrates generating a source map:
var SourceMapGenerator = require('source-map').SourceMapGenerator;
var generator = new SourceMapGenerator({ file: 'source-mapped.js' });
generator.addMapping({
source: 'foo.js',
generated: { line: 10, column: 35 },
original: { line: 33, column: 2 },
name: 'christopher'
});
console.log(generator.toString());
The SourceMapConsumer
class can be used to read and query data from your existing source map:
var SourceMapConsumer = require('source-map').SourceMapConsumer;
var rawSourceMap = {...}; // Your existing source map
var consumer = new SourceMapConsumer(rawSourceMap);
var pos = consumer.originalPositionFor({ line: 2, column: 28 });
console.log(pos);
For browser use, you can include it using a script tag. Initialization is required before constructing any SourceMapConsumers:
<script src="https://unpkg.com/source-map@0.7.3/dist/source-map.js"></script>
<script>
sourceMap.SourceMapConsumer.initialize({
"lib/mappings.wasm": "https://unpkg.com/source-map@0.7.3/lib/mappings.wasm"
});
/* Your code here */
</script>
The documentation for the source-map npm package is available in the README file of the project's GitHub repository. The repository can be found at git+ssh://git@github.com/mozilla/source-map.git
. The README contains detailed instructions and examples on how to use the package, its API, and abundant information on source maps. Make sure to have a look at the Examples and API sections. These describe how to consume a source map, generate a new one, and use the high-level and low-level APIs.