-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
84 lines (69 loc) · 1.9 KB
/
index.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
'use strict';
const existInThisRadius = (checkPoint, centerPoint, km) => {
var ky = 40000 / 360;
var kx = Math.cos(Math.PI * centerPoint.lat / 180.0) * ky;
var dx = Math.abs(centerPoint.lng - checkPoint.lng) * kx;
var dy = Math.abs(centerPoint.lat - checkPoint.lat) * ky;
return Math.sqrt(dx * dx + dy * dy) <= km;
};
const Ellipsis = (props) => {
return ((props.title).length > props.limit) ?
(((props.title).substring(0, props.limit)) + '..') : props.title;
};
function addBytes(add) {
var bytes = null;
bytes += add;
return bytes;
};
function objSize(objectList, stack, value) {
objectList.push(value);
for (var i in value) {
stack.push(value[i]);
}
};
function nonObjSize(bytes, value) {
if (typeof value === 'boolean')
bytes = addBytes(4);
else if (typeof value === 'string')
bytes = addBytes(value.length * 2);
else if (typeof value === 'number')
bytes = addBytes(8);
return bytes;
};
const getSize = (object) => {
var objectList = [];
var stack = [object];
var bytes = 0;
while (stack.length) {
var value = stack.pop();
if (
typeof value === 'object'
&& objectList.indexOf(value) === -1
)
objSize(objectList, stack, value);
else
bytes = nonObjSize(bytes, value);
}
return bytes;
};
const debounce = (func, wait, immediate) => {
var timeout;
return function() {
var context = this;
var args = arguments;
var later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
};
};
module.exports = {
debounce,
getSize,
existInThisRadius,
Ellipsis,
};