-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUtils.js
65 lines (61 loc) · 1.61 KB
/
Utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
(function (sandbox) {
function isNative(func)
{
var toString = Function.prototype.toString;
var expr = /function [a-zA-Z_][a-zA-Z0-9_]*\(\)[ \t\n]*\{[ \t\n]*\[native code\][ \t\n]*\}/;
var res = (toString.call(func)).match(expr);
return (res !== null && res[0] === toString.call(func))
}
const isNumber = (n) => n instanceof Number || typeof n == 'number';
const isString = (s) => s instanceof String || typeof s == 'string';
function fillArray(value, len)
{
if (len <= 0 || typeof len != 'number') return [];
var a = [value];
while (a.length * 2 <= len) a = a.concat(a);
if (a.length < len) a = a.concat(a.slice(0, len - a.length));
return a;
}//https://stackoverflow.com/questions/12503146/create-an-array-with-same-element-repeated-multiple-times
function getTypeName(v)
{
if (v === null)
return "null";
if (typeof v == 'undefined')
return "undefined";
return v.constructor.name;
}
function getPropertyObj(obj, prop)
{
if (typeof obj[prop] == 'undefined')
{
obj[prop] = {};
}
return obj[prop];
}
function Utils(){}
Utils.prototype.isNative = isNative;
Utils.prototype.fillArray = fillArray;
Utils.prototype.isNumber = isNumber;
Utils.prototype.isString = isString;
Utils.prototype.getTypeName = getTypeName;
Utils.prototype.getPropertyObj = getPropertyObj;
Utils.prototype.isHex = function (c)
{
return c >= '0' && c <= '9' ||
c >= 'a' && c <= 'f' ||
c >= 'A' && c <= 'Z';
};
Utils.prototype.allSame = function (arr)
{
if (arr.length < 2)
return true;
const f = arr[0];
for (let i = 1; i < arr.length; i++)
{
if (arr[i] !== f)
return false;
}
return true;
};
sandbox.dtaUtils = new Utils();
})(J$);