-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathnotesto.js
67 lines (59 loc) · 1.98 KB
/
notesto.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
var rp = require('request-promise');//,
//nocrypto = require("./nocrypto.js");
// const wait = ms => new Promise(resolve => setTimeout(resolve, ms));
//
// wait(10000).then(() => saySomething("10 seconds")).catch(failureCallback);
var traceval = 2;
(function() {
var notesto = (() => ({
vn: '0.0.1',
xPOSTjson: (url,bdy) => {
return rp({ method:'POST',
uri:'http://'+url,
body:bdy,
json:true,
}).catch(x=>{throw(Error('notesto.POST('+url+bdy+') resulted in '+x))})
.then(x => { if (/\*\*ERROR\*\*/.test(x)) {
throw(Error('notesto.POST('+url+bdy+') resulted in '+x)); } return x; })},
xPOSTtxt: (url,bdy) => {
return rp({ method:'POST',
uri:'http://'+url,
body:bdy,
headers: {
'content-type': 'text/plain'
}
}).catch(x=>{throw(Error('notesto.POST('+url+bdy+') resulted in '+x))})
.then(x => { if (/\*\*ERROR\*\*/.test(x)) {
throw(Error('notesto.POST('+url+bdy+') resulted in '+x)); } return x; })},
xGET: (url) =>
rp({ method:'GET',
uri:'http://'+url,
}).catch(x=>{throw(Error('notesto.GET('+url+') resulted in '+x))})
.then(x => { if (/\*\*ERROR\*\*/.test(x)) {
throw(Error('notesto.GET('+url+') resulted in '+x)); } return x; }),
xDELETE: (url) =>
rp({ method:'DELETE',
uri:'http://'+url,
}).then(x => {console.log('DELETE',x); return x;})
.catch(x=>{throw(Error('notesto.GET('+url+') resulted in '+x))})
.then(x => { if (/\*\*ERROR\*\*/.test(x)) {
throw(Error('notesto.GET('+url+') resulted in '+x)); } return x; }),
expect: (val,msg) => {
return x => {
if (val instanceof RegExp ? val.test(x) : x === val) {
console.log(msg,'OK (',x,')')
} else {
throw(Error('notesto.expect('+val+') but got '+x+'(NOT '+msg+')'))
}
}
},
trace: (n,msg) => {
if (n<traceval) console.log('***',msg)
}
}))()
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
module.exports = notesto;
} else {
window.notesto = notesto;
}
})();