Projekt

Obecné

Profil

Stáhnout (4.38 KB) Statistiky
| Větev: | Revize:
1
# convert-source-map [![build status](https://secure.travis-ci.org/thlorenz/convert-source-map.svg?branch=master)](http://travis-ci.org/thlorenz/convert-source-map)
2

    
3
<a href="https://www.patreon.com/bePatron?u=8663953"><img alt="become a patron" src="https://c5.patreon.com/external/logo/become_a_patron_button.png" height="35px"></a>
4

    
5
Converts a source-map from/to  different formats and allows adding/changing properties.
6

    
7
```js
8
var convert = require('convert-source-map');
9

    
10
var json = convert
11
  .fromComment('//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYnVpbGQvZm9vLm1pbi5qcyIsInNvdXJjZXMiOlsic3JjL2Zvby5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSIsInNvdXJjZVJvb3QiOiIvIn0=')
12
  .toJSON();
13

    
14
var modified = convert
15
  .fromComment('//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYnVpbGQvZm9vLm1pbi5qcyIsInNvdXJjZXMiOlsic3JjL2Zvby5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSIsInNvdXJjZVJvb3QiOiIvIn0=')
16
  .setProperty('sources', [ 'SRC/FOO.JS' ])
17
  .toJSON();
18

    
19
console.log(json);
20
console.log(modified);
21
```
22

    
23
```json
24
{"version":3,"file":"build/foo.min.js","sources":["src/foo.js"],"names":[],"mappings":"AAAA","sourceRoot":"/"}
25
{"version":3,"file":"build/foo.min.js","sources":["SRC/FOO.JS"],"names":[],"mappings":"AAAA","sourceRoot":"/"}
26
```
27

    
28
## API
29

    
30
### fromObject(obj)
31

    
32
Returns source map converter from given object.
33

    
34
### fromJSON(json)
35

    
36
Returns source map converter from given json string.
37

    
38
### fromBase64(base64)
39

    
40
Returns source map converter from given base64 encoded json string.
41

    
42
### fromComment(comment)
43

    
44
Returns source map converter from given base64 encoded json string prefixed with `//# sourceMappingURL=...`.
45

    
46
### fromMapFileComment(comment, mapFileDir)
47

    
48
Returns source map converter from given `filename` by parsing `//# sourceMappingURL=filename`.
49

    
50
`filename` must point to a file that is found inside the `mapFileDir`. Most tools store this file right next to the
51
generated file, i.e. the one containing the source map.
52

    
53
### fromSource(source)
54

    
55
Finds last sourcemap comment in file and returns source map converter or returns null if no source map comment was found.
56

    
57
### fromMapFileSource(source, mapFileDir)
58

    
59
Finds last sourcemap comment in file and returns source map converter or returns null if no source map comment was
60
found.
61

    
62
The sourcemap will be read from the map file found by parsing `# sourceMappingURL=file` comment. For more info see
63
fromMapFileComment.
64

    
65
### toObject()
66

    
67
Returns a copy of the underlying source map.
68

    
69
### toJSON([space])
70

    
71
Converts source map to json string. If `space` is given (optional), this will be passed to
72
[JSON.stringify](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/JSON/stringify) when the
73
JSON string is generated.
74

    
75
### toBase64()
76

    
77
Converts source map to base64 encoded json string.
78

    
79
### toComment([options])
80

    
81
Converts source map to an inline comment that can be appended to the source-file.
82

    
83
By default, the comment is formatted like: `//# sourceMappingURL=...`, which you would
84
normally see in a JS source file.
85

    
86
When `options.multiline == true`, the comment is formatted like: `/*# sourceMappingURL=... */`, which you would find in a CSS source file.
87

    
88
### addProperty(key, value)
89

    
90
Adds given property to the source map. Throws an error if property already exists.
91

    
92
### setProperty(key, value)
93

    
94
Sets given property to the source map. If property doesn't exist it is added, otherwise its value is updated.
95

    
96
### getProperty(key)
97

    
98
Gets given property of the source map.
99

    
100
### removeComments(src)
101

    
102
Returns `src` with all source map comments removed
103

    
104
### removeMapFileComments(src)
105

    
106
Returns `src` with all source map comments pointing to map files removed.
107

    
108
### commentRegex
109

    
110
Provides __a fresh__ RegExp each time it is accessed. Can be used to find source map comments.
111

    
112
### mapFileCommentRegex
113

    
114
Provides __a fresh__ RegExp each time it is accessed. Can be used to find source map comments pointing to map files.
115

    
116
### generateMapFileComment(file, [options])
117

    
118
Returns a comment that links to an external source map via `file`.
119

    
120
By default, the comment is formatted like: `//# sourceMappingURL=...`, which you would normally see in a JS source file.
121

    
122
When `options.multiline == true`, the comment is formatted like: `/*# sourceMappingURL=... */`, which you would find in a CSS source file.
123

    
124

    
125
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/thlorenz/convert-source-map/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
(2-2/4)