Security News
cURL Project and Go Security Teams Reject CVSS as Broken
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
@cspotcode/source-map-consumer
Advanced tools
@cspotcode/source-map-consumer is a JavaScript library that allows you to work with source maps. Source maps are files that map from the transformed source to the original source, enabling better debugging and error reporting by showing the original source code.
Basic Usage
This code demonstrates how to create a SourceMapConsumer instance with a raw source map object and log the sources.
const { SourceMapConsumer } = require('@cspotcode/source-map-consumer');
const rawSourceMap = { /* raw source map object */ };
SourceMapConsumer.with(rawSourceMap, null, consumer => {
console.log(consumer.sources);
});
Mapping a Generated Position to an Original Position
This code shows how to map a position in the generated code back to the original source position.
const { SourceMapConsumer } = require('@cspotcode/source-map-consumer');
const rawSourceMap = { /* raw source map object */ };
SourceMapConsumer.with(rawSourceMap, null, consumer => {
const pos = consumer.originalPositionFor({ line: 2, column: 10 });
console.log(pos);
});
Mapping an Original Position to a Generated Position
This code demonstrates how to map a position in the original source code to the corresponding position in the generated code.
const { SourceMapConsumer } = require('@cspotcode/source-map-consumer');
const rawSourceMap = { /* raw source map object */ };
SourceMapConsumer.with(rawSourceMap, null, consumer => {
const pos = consumer.generatedPositionFor({ source: 'source.js', line: 2, column: 10 });
console.log(pos);
});
Iterating Over Mappings
This code shows how to iterate over all mappings in the source map.
const { SourceMapConsumer } = require('@cspotcode/source-map-consumer');
const rawSourceMap = { /* raw source map object */ };
SourceMapConsumer.with(rawSourceMap, null, consumer => {
consumer.eachMapping(mapping => {
console.log(mapping);
});
});
The 'source-map' package is a popular library for working with source maps. It provides similar functionalities to @cspotcode/source-map-consumer, such as parsing source maps, mapping positions, and iterating over mappings. It is widely used and well-documented.
The 'source-map-support' package provides source map support for stack traces in Node.js and browsers. It allows you to map stack traces from transpiled code back to the original source code, making debugging easier. While it focuses more on stack trace mapping, it complements the functionalities provided by @cspotcode/source-map-consumer.
A smaller version of @cspotcode/source-map which includes only the consumer, not the generator.
NOTE: the type declarations are incorrect. They include declarations for things from @cspotcode/source-map which are omitted from this package.
This is a delibrate, pragmatic choice. The declarations for things which are included -- the consumer -- should be correct.
FAQs
Generates and consumes source maps
The npm package @cspotcode/source-map-consumer receives a total of 546,688 weekly downloads. As such, @cspotcode/source-map-consumer popularity was classified as popular.
We found that @cspotcode/source-map-consumer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.