blob: 216de5e52af08fd1346d7ad8519a4a66b13a84c2 (
plain)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
Overview [![Build Status](https://travis-ci.org/lydell/source-map-url.png?branch=master)](https://travis-ci.org/lydell/source-map-url)
========
[![browser support](https://ci.testling.com/lydell/source-map-url.png)](https://ci.testling.com/lydell/source-map-url)
Tools for working with sourceMappingURL comments.
```js
var sourceMappingURL = require("source-map-url")
var code = [
"!function(){...}();",
"/*# sourceMappingURL=foo.js.map */"
].join("\n")
sourceMappingURL.existsIn(code)
// true
sourceMappingURL.getFrom(code)
// foo.js.map
code = sourceMappingURL.insertBefore(code, "// License: MIT\n")
// !function(){...}();
// // License: MIT
// /*# sourceMappingURL=foo.js.map */
code = sourceMappingURL.removeFrom(code)
// !function(){...}();
// // License: MIT
sourceMappingURL.existsIn(code)
// false
sourceMappingURL.getFrom(code)
// null
code += "//# sourceMappingURL=/other/file.js.map"
// !function(){...}();
// // License: MIT
// //# sourceMappingURL=/other/file.js.map
```
Installation
============
- `npm install source-map-url`
- `bower install source-map-url`
- `component install lydell/source-map-url`
Works with CommonJS, AMD and browser globals, through UMD.
Usage
=====
### `sourceMappingURL.getFrom(code)` ###
Returns the url of the sourceMappingURL comment in `code`. Returns `null` if
there is no such comment.
### `sourceMappingURL.existsIn(code)` ###
Returns `true` if there is a sourceMappingURL comment in `code`, or `false`
otherwise.
### `sourceMappingURL.removeFrom(code)` ###
Removes the sourceMappingURL comment in `code`. Does nothing if there is no
such comment. Returns the updated `code`.
### `sourceMappingURL.insertBefore(code, string)` ###
Inserts `string` before the sourceMappingURL comment in `code`. Appends
`string` to `code` if there is no such comment.
Lets you append something to a file without worrying about burying the
sourceMappingURL comment (by keeping it at the end of the file).
### `sourceMappingURL.regex` ###
The regex that is used to match sourceMappingURL comments. It matches both `//`
and `/**/` comments, thus supporting both JavaScript and CSS.
Tests
=====
Start by running `npm test`, which lints the code and runs the test suite in Node.js.
To run the tests in a browser, run `testling` (`npm install -g testling`) or `testling -u`.
License
=======
[The X11 (“MIT”) License](LICENSE).
|