-
Notifications
You must be signed in to change notification settings - Fork 114
Expand file tree
/
Copy pathSourceMap.js
More file actions
29 lines (25 loc) · 778 Bytes
/
SourceMap.js
File metadata and controls
29 lines (25 loc) · 778 Bytes
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
import { encode } from 'sourcemap-codec';
let btoa = () => {
throw new Error('Unsupported environment: `window.btoa` or `Buffer` should be supported.');
};
if (typeof window !== 'undefined' && typeof window.btoa === 'function') {
btoa = window.btoa;
} else if (typeof Buffer === 'function') {
btoa = str => new Buffer(str).toString('base64');
}
export default class SourceMap {
constructor(properties) {
this.version = 3;
this.file = properties.file;
this.sources = properties.sources;
this.sourcesContent = properties.sourcesContent;
this.names = properties.names;
this.mappings = encode(properties.mappings);
}
toString() {
return JSON.stringify(this);
}
toUrl() {
return 'data:application/json;charset=utf-8;base64,' + btoa(this.toString());
}
}