[6a3a178] | 1 | Overview [![Build Status](https://travis-ci.org/lydell/source-map-url.png?branch=master)](https://travis-ci.org/lydell/source-map-url)
|
---|
| 2 | ========
|
---|
| 3 |
|
---|
| 4 | [![browser support](https://ci.testling.com/lydell/source-map-url.png)](https://ci.testling.com/lydell/source-map-url)
|
---|
| 5 |
|
---|
| 6 | Tools for working with sourceMappingURL comments.
|
---|
| 7 |
|
---|
| 8 | ```js
|
---|
| 9 | var sourceMappingURL = require("source-map-url")
|
---|
| 10 |
|
---|
| 11 | var code = [
|
---|
| 12 | "!function(){...}();",
|
---|
| 13 | "/*# sourceMappingURL=foo.js.map */"
|
---|
| 14 | ].join("\n")
|
---|
| 15 |
|
---|
| 16 | sourceMappingURL.existsIn(code)
|
---|
| 17 | // true
|
---|
| 18 |
|
---|
| 19 | sourceMappingURL.getFrom(code)
|
---|
| 20 | // foo.js.map
|
---|
| 21 |
|
---|
| 22 | code = sourceMappingURL.insertBefore(code, "// License: MIT\n")
|
---|
| 23 | // !function(){...}();
|
---|
| 24 | // // License: MIT
|
---|
| 25 | // /*# sourceMappingURL=foo.js.map */
|
---|
| 26 |
|
---|
| 27 | code = sourceMappingURL.removeFrom(code)
|
---|
| 28 | // !function(){...}();
|
---|
| 29 | // // License: MIT
|
---|
| 30 |
|
---|
| 31 | sourceMappingURL.existsIn(code)
|
---|
| 32 | // false
|
---|
| 33 |
|
---|
| 34 | sourceMappingURL.getFrom(code)
|
---|
| 35 | // null
|
---|
| 36 |
|
---|
| 37 | code += "//# sourceMappingURL=/other/file.js.map"
|
---|
| 38 | // !function(){...}();
|
---|
| 39 | // // License: MIT
|
---|
| 40 | // //# sourceMappingURL=/other/file.js.map
|
---|
| 41 | ```
|
---|
| 42 |
|
---|
| 43 |
|
---|
| 44 | Installation
|
---|
| 45 | ============
|
---|
| 46 |
|
---|
| 47 | - `npm install source-map-url`
|
---|
| 48 | - `bower install source-map-url`
|
---|
| 49 | - `component install lydell/source-map-url`
|
---|
| 50 |
|
---|
| 51 | Works with CommonJS, AMD and browser globals, through UMD.
|
---|
| 52 |
|
---|
| 53 |
|
---|
| 54 | Usage
|
---|
| 55 | =====
|
---|
| 56 |
|
---|
| 57 | ### `sourceMappingURL.getFrom(code)` ###
|
---|
| 58 |
|
---|
| 59 | Returns the url of the sourceMappingURL comment in `code`. Returns `null` if
|
---|
| 60 | there is no such comment.
|
---|
| 61 |
|
---|
| 62 | ### `sourceMappingURL.existsIn(code)` ###
|
---|
| 63 |
|
---|
| 64 | Returns `true` if there is a sourceMappingURL comment in `code`, or `false`
|
---|
| 65 | otherwise.
|
---|
| 66 |
|
---|
| 67 | ### `sourceMappingURL.removeFrom(code)` ###
|
---|
| 68 |
|
---|
| 69 | Removes the sourceMappingURL comment in `code`. Does nothing if there is no
|
---|
| 70 | such comment. Returns the updated `code`.
|
---|
| 71 |
|
---|
| 72 | ### `sourceMappingURL.insertBefore(code, string)` ###
|
---|
| 73 |
|
---|
| 74 | Inserts `string` before the sourceMappingURL comment in `code`. Appends
|
---|
| 75 | `string` to `code` if there is no such comment.
|
---|
| 76 |
|
---|
| 77 | Lets you append something to a file without worrying about burying the
|
---|
| 78 | sourceMappingURL comment (by keeping it at the end of the file).
|
---|
| 79 |
|
---|
| 80 | ### `sourceMappingURL.regex` ###
|
---|
| 81 |
|
---|
| 82 | The regex that is used to match sourceMappingURL comments. It matches both `//`
|
---|
| 83 | and `/**/` comments, thus supporting both JavaScript and CSS.
|
---|
| 84 |
|
---|
| 85 |
|
---|
| 86 | Tests
|
---|
| 87 | =====
|
---|
| 88 |
|
---|
| 89 | Start by running `npm test`, which lints the code and runs the test suite in Node.js.
|
---|
| 90 |
|
---|
| 91 | To run the tests in a browser, run `testling` (`npm install -g testling`) or `testling -u`.
|
---|
| 92 |
|
---|
| 93 |
|
---|
| 94 | License
|
---|
| 95 | =======
|
---|
| 96 |
|
---|
| 97 | [The X11 (“MIT”) License](LICENSE).
|
---|