You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
2.3 KiB

4 years ago
  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. [![browser support](https://ci.testling.com/lydell/source-map-url.png)](https://ci.testling.com/lydell/source-map-url)
  4. Tools for working with sourceMappingURL comments.
  5. ```js
  6. var sourceMappingURL = require("source-map-url")
  7. var code = [
  8. "!function(){...}();",
  9. "/*# sourceMappingURL=foo.js.map */"
  10. ].join("\n")
  11. sourceMappingURL.existsIn(code)
  12. // true
  13. sourceMappingURL.getFrom(code)
  14. // foo.js.map
  15. code = sourceMappingURL.insertBefore(code, "// License: MIT\n")
  16. // !function(){...}();
  17. // // License: MIT
  18. // /*# sourceMappingURL=foo.js.map */
  19. code = sourceMappingURL.removeFrom(code)
  20. // !function(){...}();
  21. // // License: MIT
  22. sourceMappingURL.existsIn(code)
  23. // false
  24. sourceMappingURL.getFrom(code)
  25. // null
  26. code += "//# sourceMappingURL=/other/file.js.map"
  27. // !function(){...}();
  28. // // License: MIT
  29. // //# sourceMappingURL=/other/file.js.map
  30. ```
  31. Installation
  32. ============
  33. - `npm install source-map-url`
  34. - `bower install source-map-url`
  35. - `component install lydell/source-map-url`
  36. Works with CommonJS, AMD and browser globals, through UMD.
  37. Usage
  38. =====
  39. ### `sourceMappingURL.getFrom(code)` ###
  40. Returns the url of the sourceMappingURL comment in `code`. Returns `null` if
  41. there is no such comment.
  42. ### `sourceMappingURL.existsIn(code)` ###
  43. Returns `true` if there is a sourceMappingURL comment in `code`, or `false`
  44. otherwise.
  45. ### `sourceMappingURL.removeFrom(code)` ###
  46. Removes the sourceMappingURL comment in `code`. Does nothing if there is no
  47. such comment. Returns the updated `code`.
  48. ### `sourceMappingURL.insertBefore(code, string)` ###
  49. Inserts `string` before the sourceMappingURL comment in `code`. Appends
  50. `string` to `code` if there is no such comment.
  51. Lets you append something to a file without worrying about burying the
  52. sourceMappingURL comment (by keeping it at the end of the file).
  53. ### `sourceMappingURL.regex` ###
  54. The regex that is used to match sourceMappingURL comments. It matches both `//`
  55. and `/**/` comments, thus supporting both JavaScript and CSS.
  56. Tests
  57. =====
  58. Start by running `npm test`, which lints the code and runs the test suite in Node.js.
  59. To run the tests in a browser, run `testling` (`npm install -g testling`) or `testling -u`.
  60. License
  61. =======
  62. [The X11 (“MIT”) License](LICENSE).