applay-utils 1.2.7 → 1.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "applay-utils",
3
- "version": "1.2.7",
3
+ "version": "1.2.9",
4
4
  "description": "Utilitary tools for Applay applications",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
package/utils/mdb.js CHANGED
@@ -1,5 +1,5 @@
1
1
  var MongoBase = require('mongodb');
2
- var ObjectID = require('mongodb').ObjectID;
2
+ var ObjectId = require('mongodb').ObjectId;
3
3
 
4
4
  var MDB = {
5
5
  status:{},
@@ -168,6 +168,8 @@ function build(data,model,user) {
168
168
  }
169
169
 
170
170
  module.exports = {
171
+ ObjectId,
172
+ ObjectID: ObjectId,
171
173
  connect,
172
174
  connectAsync,
173
175
  stopCustom,
package/utils/tools.js CHANGED
@@ -39,7 +39,54 @@ var tools = {
39
39
  }
40
40
  client.end()
41
41
  })
42
- })
42
+ }),
43
+ /**
44
+ * @param {number} milliseconds Valor em milisegundos para ser convertido
45
+ * @returns Retorna uma string no formato **0h 0m 0s** ou retorna **--** em caso de erro
46
+ */
47
+ 'findDistance': (posA, posB) => {
48
+ let rad;
49
+ function deg2rad(deg) {
50
+ rad = deg * Math.PI / 180; // radians = degrees * pi/180
51
+ return rad;
52
+ }
53
+ function round(x) {
54
+ return Math.round(x * 1000) / 1000;
55
+ }
56
+ var Rm = 3961; // mean radius of the earth (miles) at 39 degrees from the equator
57
+ var Rk = 6373; // mean radius of the earth (km) at 39 degrees from the equator
58
+ var t1, n1, t2, n2, lat1, lon1, lat2, lon2, dlat, dlon, a, c, dm, dk, mi, km;
59
+
60
+ // get values for lat1, lon1, lat2, and lon2
61
+ t1 = posA.lat;
62
+ n1 = posA.lng;
63
+ t2 = posB.lat;
64
+ n2 = posB.lng;
65
+
66
+ // convert coordinates to radians
67
+ lat1 = deg2rad(t1);
68
+ lon1 = deg2rad(n1);
69
+ lat2 = deg2rad(t2);
70
+ lon2 = deg2rad(n2);
71
+
72
+ // find the differences between the coordinates
73
+ dlat = lat2 - lat1;
74
+ dlon = lon2 - lon1;
75
+
76
+ // here's the heavy lifting
77
+ a = Math.pow(Math.sin(dlat / 2), 2) + Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(dlon / 2), 2);
78
+ c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); // great circle distance in radians
79
+ dm = c * Rm; // great circle distance in miles
80
+ dk = c * Rk; // great circle distance in km
81
+
82
+ // round the results down to the nearest 1/1000
83
+ mi = round(dm);
84
+ km = round(dk);
85
+
86
+ // display the result
87
+ // frm.mi.value = mi;
88
+ return km;
89
+ }
43
90
  }
44
91
 
45
92
  module.exports = tools;