Gathering detailed insights and metrics for convert-source-map
Gathering detailed insights and metrics for convert-source-map
Gathering detailed insights and metrics for convert-source-map
Gathering detailed insights and metrics for convert-source-map
@types/convert-source-map
TypeScript definitions for convert-source-map
source-map-to-comment
Convert a Source Map object to a comment
@prantlf/convert-source-map
Converts a source-map from/to different formats and allows adding/changing properties.
map-to-source
map convert source file
Converts a source-map from/to different formats.
npm install convert-source-map
Typescript
Module System
Node Version
NPM Version
99.8
Supply Chain
100
Quality
78.3
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
13,055,973,351
Last Day
15,776,005
Last Week
92,853,274
Last Month
451,512,664
Last Year
3,906,684,816
MIT License
172 Stars
115 Commits
58 Forks
9 Watchers
4 Branches
27 Contributors
Updated on May 01, 2025
Latest Version
2.0.0
Package Id
convert-source-map@2.0.0
Unpacked Size
15.48 kB
Size
4.84 kB
File Count
4
NPM Version
8.11.0
Node Version
16.14.2
Cumulative downloads
Total Downloads
Last Day
-1.5%
15,776,005
Compared to previous day
Last Week
-9.5%
92,853,274
Compared to previous week
Last Month
18.3%
451,512,664
Compared to previous month
Last Year
30.9%
3,906,684,816
Compared to previous year
2
Converts a source-map from/to different formats and allows adding/changing properties.
1var convert = require('convert-source-map'); 2 3var json = convert 4 .fromComment('//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYnVpbGQvZm9vLm1pbi5qcyIsInNvdXJjZXMiOlsic3JjL2Zvby5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSIsInNvdXJjZVJvb3QiOiIvIn0=') 5 .toJSON(); 6 7var modified = convert 8 .fromComment('//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYnVpbGQvZm9vLm1pbi5qcyIsInNvdXJjZXMiOlsic3JjL2Zvby5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSIsInNvdXJjZVJvb3QiOiIvIn0=') 9 .setProperty('sources', [ 'SRC/FOO.JS' ]) 10 .toJSON(); 11 12console.log(json); 13console.log(modified);
1{"version":3,"file":"build/foo.min.js","sources":["src/foo.js"],"names":[],"mappings":"AAAA","sourceRoot":"/"} 2{"version":3,"file":"build/foo.min.js","sources":["SRC/FOO.JS"],"names":[],"mappings":"AAAA","sourceRoot":"/"}
Prior to v2.0.0, the fromMapFileComment
and fromMapFileSource
functions took a String directory path and used that to resolve & read the source map file from the filesystem. However, this made the library limited to nodejs environments and broke on sources with querystrings.
In v2.0.0, you now need to pass a function that does the file reading. It will receive the source filename as a String that you can resolve to a filesystem path, URL, or anything else.
If you are using convert-source-map
in nodejs and want the previous behavior, you'll use a function like such:
1+ var fs = require('fs'); // Import the fs module to read a file 2+ var path = require('path'); // Import the path module to resolve a path against your directory 3- var conv = convert.fromMapFileSource(css, '../my-dir'); 4+ var conv = convert.fromMapFileSource(css, function (filename) { 5+ return fs.readFileSync(path.resolve('../my-dir', filename), 'utf-8'); 6+ });
Returns source map converter from given object.
Returns source map converter from given json string.
Returns source map converter from given uri encoded json string.
Returns source map converter from given base64 encoded json string.
Returns source map converter from given base64 or uri encoded json string prefixed with //# sourceMappingURL=...
.
Returns source map converter from given filename
by parsing //# sourceMappingURL=filename
.
readMap
must be a function which receives the source map filename and returns either a String or Buffer of the source map (if read synchronously), or a Promise
containing a String or Buffer of the source map (if read asynchronously).
If readMap
doesn't return a Promise
, fromMapFileComment
will return a source map converter synchronously.
If readMap
returns a Promise
, fromMapFileComment
will also return Promise
. The Promise
will be either resolved with the source map converter or rejected with an error.
Synchronous read in Node.js:
1var convert = require('convert-source-map');
2var fs = require('fs');
3
4function readMap(filename) {
5 return fs.readFileSync(filename, 'utf8');
6}
7
8var json = convert
9 .fromMapFileComment('//# sourceMappingURL=map-file-comment.css.map', readMap)
10 .toJSON();
11console.log(json);
Asynchronous read in Node.js:
1var convert = require('convert-source-map');
2var { promises: fs } = require('fs'); // Notice the `promises` import
3
4function readMap(filename) {
5 return fs.readFile(filename, 'utf8');
6}
7
8var converter = await convert.fromMapFileComment('//# sourceMappingURL=map-file-comment.css.map', readMap)
9var json = converter.toJSON();
10console.log(json);
Asynchronous read in the browser:
1var convert = require('convert-source-map'); 2 3async function readMap(url) { 4 const res = await fetch(url); 5 return res.text(); 6} 7 8const converter = await convert.fromMapFileComment('//# sourceMappingURL=map-file-comment.css.map', readMap) 9var json = converter.toJSON(); 10console.log(json);
Finds last sourcemap comment in file and returns source map converter or returns null
if no source map comment was found.
Finds last sourcemap comment in file and returns source map converter or returns null
if no source map comment was found.
readMap
must be a function which receives the source map filename and returns either a String or Buffer of the source map (if read synchronously), or a Promise
containing a String or Buffer of the source map (if read asynchronously).
If readMap
doesn't return a Promise
, fromMapFileSource
will return a source map converter synchronously.
If readMap
returns a Promise
, fromMapFileSource
will also return Promise
. The Promise
will be either resolved with the source map converter or rejected with an error.
Returns a copy of the underlying source map.
Converts source map to json string. If space
is given (optional), this will be passed to
JSON.stringify when the
JSON string is generated.
Converts source map to uri encoded json string.
Converts source map to base64 encoded json string.
Converts source map to an inline comment that can be appended to the source-file.
By default, the comment is formatted like: //# sourceMappingURL=...
, which you would
normally see in a JS source file.
When options.encoding == 'uri'
, the data will be uri encoded, otherwise they will be base64 encoded.
When options.multiline == true
, the comment is formatted like: /*# sourceMappingURL=... */
, which you would find in a CSS source file.
Adds given property to the source map. Throws an error if property already exists.
Sets given property to the source map. If property doesn't exist it is added, otherwise its value is updated.
Gets given property of the source map.
Returns src
with all source map comments removed
Returns src
with all source map comments pointing to map files removed.
Provides a fresh RegExp each time it is accessed. Can be used to find source map comments.
Breaks down a source map comment into groups: Groups: 1: media type, 2: MIME type, 3: charset, 4: encoding, 5: data.
Provides a fresh RegExp each time it is accessed. Can be used to find source map comments pointing to map files.
Returns a comment that links to an external source map via file
.
By default, the comment is formatted like: //# sourceMappingURL=...
, which you would normally see in a JS source file.
When options.multiline == true
, the comment is formatted like: /*# sourceMappingURL=... */
, which you would find in a CSS source file.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
security policy file detected
Details
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
Found 12/30 approved changesets -- score normalized to 4
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More