What is @types/convert-source-map?
@types/convert-source-map provides TypeScript type definitions for the convert-source-map package, which is used to convert between different formats of source maps, such as from inline to external and vice versa.
What are @types/convert-source-map's main functionalities?
Converting Inline Source Map to Object
This feature allows you to convert an inline source map (embedded in a comment) to a source map object.
const convert = require('convert-source-map');
const inlineSourceMap = '//# sourceMappingURL=data:application/json;base64,...';
const sm = convert.fromComment(inlineSourceMap);
console.log(sm.toObject());
Converting Source Map Object to JSON
This feature allows you to convert a source map object to a JSON string.
const convert = require('convert-source-map');
const sm = convert.fromObject({ version: 3, file: 'out.js', sources: ['foo.js'], names: [], mappings: 'AAAA' });
console.log(sm.toJSON());
Adding Source Map Comment to File
This feature allows you to add a source map comment to a file's content.
const convert = require('convert-source-map');
const sm = convert.fromObject({ version: 3, file: 'out.js', sources: ['foo.js'], names: [], mappings: 'AAAA' });
const fileContent = 'console.log("Hello World");';
const fileWithSourceMap = fileContent + '\n' + sm.toComment();
console.log(fileWithSourceMap);
Other packages similar to @types/convert-source-map
source-map
The source-map package provides a library for generating and consuming source maps. It offers more comprehensive functionalities for working with source maps, including parsing, generating, and manipulating them. It is more feature-rich compared to convert-source-map.
inline-source-map
The inline-source-map package is a simpler alternative that focuses on generating inline source maps. It is less comprehensive than convert-source-map but can be useful for projects that only need to work with inline source maps.