forked from paazmaya/shuji
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (35 loc) · 1.02 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
* shuji (周氏)
* https://github.com/paazmaya/shuji
*
* Reverse engineering JavaScript and CSS sources from sourcemaps
*
* Copyright (c) Juga Paazmaya <[email protected]> (https://paazmaya.fi)
* Licensed under the MIT license
*/
'use strict';
const path = require('path');
const sourceMap = require('source-map');
/**
* @param {string} input Contents of the sourcemap file
* @param {object} options Object {verbose: boolean}
*
* @returns {object} Source contents mapped to file names
*/
module.exports = (input, options) => {
const consumer = new sourceMap.SourceMapConsumer(input);
const map = {};
if (consumer.hasContentsOfAllSources()) {
if (options.verbose) {
console.log('All sources were included in the sourcemap');
}
consumer.sources.forEach((source) => {
const contents = consumer.sourceContentFor(source);
map[path.basename(source)] = contents;
});
}
else if (options.verbose) {
console.log('Not all sources were included in the sourcemap');
}
return map;
};