Debian Codegraph @

debian/missing-sources/livereload.js/options.js

raw
1 class Options {
2 constructor () {
3 this.https = false;
4 this.host = null;
5 this.port = 35729;
6
7 this.snipver = null;
8 this.ext = null;
9 this.extver = null;
10
11 this.mindelay = 1000;
12 this.maxdelay = 60000;
13 this.handshake_timeout = 5000;
14 }
15
16 set (name, value) {
17 if (typeof value === 'undefined') {
18 return;
19 }
20
21 if (!isNaN(+value)) {
22 value = +value;
23 }
24
25 this[name] = value;
26 }
27 }
28
29 Options.extract = function (document) {
30 for (let element of Array.from(document.getElementsByTagName('script'))) {
31 var m, src;
32 if ((src = element.src) && (m = src.match(new RegExp(`^[^:]+://(.*)/z?livereload\\.js(?:\\?(.*))?$`)))) {
33 var mm;
34 const options = new Options();
35
36 options.https = src.indexOf('https') === 0;
37
38 if ((mm = m[1].match(new RegExp(`^([^/:]+)(?::(\\d+))?(\\/+.*)?$`)))) {
39 options.host = mm[1];
40 if (mm[2]) {
41 options.port = parseInt(mm[2], 10);
42 }
43 }
44
45 if (m[2]) {
46 for (let pair of m[2].split('&')) {
47 var keyAndValue;
48
49 if ((keyAndValue = pair.split('=')).length > 1) {
50 options.set(keyAndValue[0].replace(/-/g, '_'), keyAndValue.slice(1).join('='));
51 }
52 }
53 }
54
55 return options;
56 }
57 }
58
59 return null;
60 };
61
62 exports.Options = Options;