Projekt

Obecné

Profil

Stáhnout (1.17 KB) Statistiky
| Větev: | Revize:
1
// Copyright 2014 Simon Lydell
2
// X11 (“MIT”) Licensed. (See LICENSE.)
3

    
4
void (function(root, factory) {
5
  if (typeof define === "function" && define.amd) {
6
    define(factory)
7
  } else if (typeof exports === "object") {
8
    module.exports = factory()
9
  } else {
10
    root.sourceMappingURL = factory()
11
  }
12
}(this, function() {
13

    
14
  var innerRegex = /[#@] sourceMappingURL=([^\s'"]*)/
15

    
16
  var regex = RegExp(
17
    "(?:" +
18
      "/\\*" +
19
      "(?:\\s*\r?\n(?://)?)?" +
20
      "(?:" + innerRegex.source + ")" +
21
      "\\s*" +
22
      "\\*/" +
23
      "|" +
24
      "//(?:" + innerRegex.source + ")" +
25
    ")" +
26
    "\\s*"
27
  )
28

    
29
  return {
30

    
31
    regex: regex,
32
    _innerRegex: innerRegex,
33

    
34
    getFrom: function(code) {
35
      var match = code.match(regex)
36
      return (match ? match[1] || match[2] || "" : null)
37
    },
38

    
39
    existsIn: function(code) {
40
      return regex.test(code)
41
    },
42

    
43
    removeFrom: function(code) {
44
      return code.replace(regex, "")
45
    },
46

    
47
    insertBefore: function(code, string) {
48
      var match = code.match(regex)
49
      if (match) {
50
        return code.slice(0, match.index) + string + code.slice(match.index)
51
      } else {
52
        return code + string
53
      }
54
    }
55
  }
56

    
57
}));
(8-8/9)