source-map-url.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2014 Simon Lydell
  2. // X11 (“MIT”) Licensed. (See LICENSE.)
  3. void (function(root, factory) {
  4. if (typeof define === "function" && define.amd) {
  5. define(factory)
  6. } else if (typeof exports === "object") {
  7. module.exports = factory()
  8. } else {
  9. root.sourceMappingURL = factory()
  10. }
  11. }(this, function() {
  12. var innerRegex = /[#@] sourceMappingURL=([^\s'"]*)/
  13. var regex = RegExp(
  14. "(?:" +
  15. "/\\*" +
  16. "(?:\\s*\r?\n(?://)?)?" +
  17. "(?:" + innerRegex.source + ")" +
  18. "\\s*" +
  19. "\\*/" +
  20. "|" +
  21. "//(?:" + innerRegex.source + ")" +
  22. ")" +
  23. "\\s*"
  24. )
  25. return {
  26. regex: regex,
  27. _innerRegex: innerRegex,
  28. getFrom: function(code) {
  29. var match = code.match(regex)
  30. return (match ? match[1] || match[2] || "" : null)
  31. },
  32. existsIn: function(code) {
  33. return regex.test(code)
  34. },
  35. removeFrom: function(code) {
  36. return code.replace(regex, "")
  37. },
  38. insertBefore: function(code, string) {
  39. var match = code.match(regex)
  40. if (match) {
  41. return code.slice(0, match.index) + string + code.slice(match.index)
  42. } else {
  43. return code + string
  44. }
  45. }
  46. }
  47. }));