applay-utils 1.0.1 → 1.0.2
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 +1 -1
- package/utils/{query.js → querys.js} +3 -3
- package/utils/tools.js +21 -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,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,21 @@
|
|
|
1
|
+
var tools = {
|
|
2
|
+
'csv2json':(csv)=>{
|
|
3
|
+
var csvLinhas = csv.split('\n');
|
|
4
|
+
var header = csvLinhas.shift().split(';');
|
|
5
|
+
// console.log('csvLinhas',csvLinhas);
|
|
6
|
+
// console.log('header',header);
|
|
7
|
+
var dataCSv = csvLinhas.filter(e=>e!='').map(e=>e.split(';').reduce((n,p,i)=>{n[header[i]]=p;return n},{}))
|
|
8
|
+
return dataCSv;
|
|
9
|
+
},
|
|
10
|
+
'post':(url,data,headers)=>new Promise(resolve=>{
|
|
11
|
+
axios.post(url, data, {headers:headers})
|
|
12
|
+
.then((response)=>{
|
|
13
|
+
resolve({status:true,data:response.data});
|
|
14
|
+
})
|
|
15
|
+
.catch((error)=>{
|
|
16
|
+
resolve({status:false,error});
|
|
17
|
+
});
|
|
18
|
+
})
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = tools;
|