applay-utils 1.0.1 → 1.0.3
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/index.js +3 -2
- package/package.json +2 -1
- package/utils/{query.js → querys.js} +3 -3
- package/utils/tools.js +23 -0
package/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
var
|
|
1
|
+
var tools = require('./utils/tools.js');
|
|
2
|
+
var querys = require('./utils/querys.js');
|
|
2
3
|
|
|
3
4
|
var utils = Object.assign({
|
|
4
5
|
mdb:require('./utils/mdb'),
|
|
5
6
|
crypto:require('./utils/crypto'),
|
|
6
7
|
jwt:require('./utils/jwt')
|
|
7
|
-
},
|
|
8
|
+
},tools,querys);
|
|
8
9
|
|
|
9
10
|
module.exports = utils;
|
|
10
11
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "applay-utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Utilitary tools for Applay applications",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"author": "William Stuani",
|
|
14
14
|
"license": "ISC",
|
|
15
15
|
"dependencies": {
|
|
16
|
+
"axios": "^1.2.1",
|
|
16
17
|
"crypto-js": "^4.1.1",
|
|
17
18
|
"jsonwebtoken": "^8.5.1",
|
|
18
19
|
"mongodb": "^4.12.1"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
1
|
+
var querys = {
|
|
2
2
|
'findAsync': (db, collection, filter) => new Promise(resolve => db.collection(collection).find(filter).toArray((err, result) => resolve(result))),
|
|
3
3
|
'findLimitAsync': (db, collection, filter, limit) => new Promise(resolve => db.collection(collection).find(filter).limit(limit).toArray((err, result) => resolve(result))),
|
|
4
4
|
'distinctAsync': (db, collection, filter, campo) => new Promise(resolve => db.collection(collection).distinct(campo, filter, (err, result) => resolve(result))),
|
|
@@ -52,5 +52,5 @@ var utils = {
|
|
|
52
52
|
});
|
|
53
53
|
})
|
|
54
54
|
}
|
|
55
|
-
|
|
56
|
-
module.exports =
|
|
55
|
+
|
|
56
|
+
module.exports = querys;
|
package/utils/tools.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const axios = require('axios');
|
|
2
|
+
|
|
3
|
+
var tools = {
|
|
4
|
+
'csv2json':(csv)=>{
|
|
5
|
+
var csvLinhas = csv.split('\n');
|
|
6
|
+
var header = csvLinhas.shift().split(';');
|
|
7
|
+
// console.log('csvLinhas',csvLinhas);
|
|
8
|
+
// console.log('header',header);
|
|
9
|
+
var dataCSv = csvLinhas.filter(e=>e!='').map(e=>e.split(';').reduce((n,p,i)=>{n[header[i]]=p;return n},{}))
|
|
10
|
+
return dataCSv;
|
|
11
|
+
},
|
|
12
|
+
'post':(url,data,headers)=>new Promise(resolve=>{
|
|
13
|
+
axios.post(url, data, {headers:headers})
|
|
14
|
+
.then((response)=>{
|
|
15
|
+
resolve({status:true,data:response.data});
|
|
16
|
+
})
|
|
17
|
+
.catch((error)=>{
|
|
18
|
+
resolve({status:false,error});
|
|
19
|
+
});
|
|
20
|
+
})
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = tools;
|