1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | const innerRegex = /[#@] sourceMappingURL=([^\s'"]*)/;
|
11 | const regex = RegExp(
|
12 | "(?:" +
|
13 | "/\\*" +
|
14 | "(?:\\s*\r?\n(?://)?)?" +
|
15 | "(?:" + innerRegex.source + ")" +
|
16 | "\\s*" +
|
17 | "\\*/" +
|
18 | "|" +
|
19 | "//(?:" + innerRegex.source + ")" +
|
20 | ")" +
|
21 | "\\s*$"
|
22 | );
|
23 |
|
24 | export function insertBefore(code: string, string: string) {
|
25 | let match = code.match(regex);
|
26 | if (match) {
|
27 | return code.slice(0, match.index) + string + code.slice(match.index);
|
28 | } else {
|
29 | return code + string;
|
30 | }
|
31 | }
|