Issues (46)

scripts/utils.js (2 issues)

1
// ////////////////////////////////////////////////////////////////////////////////////
2
// Copyright © 2017 TangDongxin
3
//
4
// Permission is hereby granted, free of charge, to any person obtaining
5
// A copy of this software and associated documentation files (the "Software"),
6
// To deal in the Software without restriction, including without limitation
7
// The rights to use, copy, modify, merge, publish, distribute, sublicense,
8
// And/or sell copies of the Software, and to permit persons to whom the
9
// Software is furnished to do so, subject to the following conditions:
10
//
11
// The above copyright notice and this permission notice shall be included
12
// In all copies or substantial portions of the Software.
13
//
14
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
20
// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
// ////////////////////////////////////////////////////////////////////////////////////
22
23
24
// ===========================================
25
// UTIL TOOLS
26
// ===========================================
27
28
29
function isBASE64 (str) {
0 ignored issues
show
The parameter str is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
30
31
  try {
32
33
    const res = new Buffer(a, 'base64').toString();
34
    return res != undefined;
35
36
  } catch (e) {
37
38
    return false;
39
40
  }
41
42
}
43
44
function isJSON (str) {
45
46
  if (typeof str === 'string') {
47
48
    try {
49
50
      if (str[0] == '"') {
51
52
        str = eval(str);
53
54
      }
55
56
    } catch (e) {
57
58
      // here we just ignore the result
59
      // dlog(e);
60
61
    }
62
63
64
    try {
65
66
      const obj = eval(`(${ str })`);
0 ignored issues
show
The constant obj seems to be never used. Consider removing it.
Loading history...
67
68
      if (str[0] == '{' || str[0] == '[') {
69
70
        return true;
71
72
      }
73
74
    } catch (e) {
75
76
      dlog(e);
77
78
    }
79
80
  }
81
  return false;
82
83
}
84
85
function isLink (str) {
86
87
  if (str.startsWith('http') || str.startsWith('mailto') || str.startsWith('\'http') || str.startsWith('"http')) {
88
89
    str = eval(str);
90
91
  }
92
93
  const regex = /^http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- ./?%&=]*)?$/;
94
  return regex.test(str);
95
96
}
97
98
99
function showPopup (str, div) {
100
101
  div.innerHTML = str;
102
103
}
104