Refactor intval module into Typescript.
This commit is contained in:
parent
da7d14e898
commit
b5fbe0153b
|
@ -1,71 +1,68 @@
|
|||
'use strict'
|
||||
|
||||
const req = require('request')
|
||||
|
||||
'use strict';
|
||||
class Intval {
|
||||
constructor (url) {
|
||||
this._baseUrl = `http://${url}`
|
||||
}
|
||||
async move () {
|
||||
return new Promise ((resolve, reject) => {
|
||||
const timeStart = +new Date()
|
||||
const url = `${this._baseUrl}/frame`
|
||||
//console.log(url)
|
||||
return req(url, (err, res, body) => {
|
||||
let ms = (+new Date()) - timeStart
|
||||
if (err) {
|
||||
return reject(err)
|
||||
}
|
||||
return resolve(ms)
|
||||
})
|
||||
})
|
||||
}
|
||||
async setDir (dir) {
|
||||
return new Promise ((resolve, reject) => {
|
||||
const timeStart = +new Date()
|
||||
const url = `${this._baseUrl}/dir?dir=${dir}`
|
||||
//console.log(url)
|
||||
return req(url, (err, res, body) => {
|
||||
let ms = (+new Date()) - timeStart
|
||||
if (err) {
|
||||
return reject(err)
|
||||
}
|
||||
return resolve(ms)
|
||||
})
|
||||
})
|
||||
}
|
||||
async setExposure (exposure, cb) {
|
||||
return new Promise ((resolve, reject) => {
|
||||
const timeStart = +new Date()
|
||||
const url = `${this._baseUrl}/exposure?exposure=${exposure}`
|
||||
//console.log(url)
|
||||
return req(url, (err, res, body) => {
|
||||
let ms = (+new Date()) - timeStart
|
||||
if (err) {
|
||||
return reject(err)
|
||||
}
|
||||
return resolve(ms)
|
||||
})
|
||||
})
|
||||
}
|
||||
connect (cb) {
|
||||
const timeStart = +new Date()
|
||||
const url = `${this._baseUrl}/status`
|
||||
const opts = {
|
||||
method : 'GET',
|
||||
uri : url,
|
||||
timeout: 5000
|
||||
}
|
||||
|
||||
req(opts, (err, res, body) => {
|
||||
let ms = (+new Date()) - timeStart
|
||||
if (err) {
|
||||
//console.error(err)
|
||||
return cb(err, ms)
|
||||
}
|
||||
cb(null, ms, body)
|
||||
})
|
||||
}
|
||||
constructor(url) {
|
||||
this._baseUrl = `http://${url}`;
|
||||
this.req = require('request');
|
||||
}
|
||||
async move() {
|
||||
return new Promise((resolve, reject) => {
|
||||
const timeStart = +new Date();
|
||||
const url = `${this._baseUrl}/frame`;
|
||||
//console.log(url)
|
||||
return this.req(url, (err, res, body) => {
|
||||
let ms = (+new Date()) - timeStart;
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
return resolve(ms);
|
||||
});
|
||||
});
|
||||
}
|
||||
async setDir(dir) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const timeStart = +new Date();
|
||||
const url = `${this._baseUrl}/dir?dir=${dir}`;
|
||||
//console.log(url)
|
||||
return this.req(url, (err, res, body) => {
|
||||
let ms = (+new Date()) - timeStart;
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
return resolve(ms);
|
||||
});
|
||||
});
|
||||
}
|
||||
async setExposure(exposure, cb) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const timeStart = +new Date();
|
||||
const url = `${this._baseUrl}/exposure?exposure=${exposure}`;
|
||||
//console.log(url)
|
||||
return this.req(url, (err, res, body) => {
|
||||
let ms = (+new Date()) - timeStart;
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
return resolve(ms);
|
||||
});
|
||||
});
|
||||
}
|
||||
connect(cb) {
|
||||
const timeStart = +new Date();
|
||||
const url = `${this._baseUrl}/status`;
|
||||
const opts = {
|
||||
method: 'GET',
|
||||
uri: url,
|
||||
timeout: 5000
|
||||
};
|
||||
this.req(opts, (err, res, body) => {
|
||||
let ms = (+new Date()) - timeStart;
|
||||
if (err) {
|
||||
//console.error(err)
|
||||
return cb(err, ms);
|
||||
}
|
||||
cb(null, ms, body);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Intval
|
||||
module.exports.Intval = Intval;
|
||||
//# sourceMappingURL=index.js.map
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/intval/index.ts"],"names":[],"mappings":"AAAA,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AAA;aAClB;YACD,EAAE,CAAC,IAAI,EAAE,EAAE,EAAE,IAAI,CAAC,CAAA;QACnB,CAAC,CAAC,CAAA;IACH,CAAC;CACD;AAED,MAAM,CAAC,OAAO,CAAC,MAAM,GAAG,MAAM,CAAA"}
|
|
@ -1,71 +1,68 @@
|
|||
'use strict'
|
||||
|
||||
const req = require('request')
|
||||
|
||||
'use strict';
|
||||
class Intval {
|
||||
constructor (url) {
|
||||
this._baseUrl = `http://${url}`
|
||||
}
|
||||
async move () {
|
||||
return new Promise ((resolve, reject) => {
|
||||
const timeStart = +new Date()
|
||||
const url = `${this._baseUrl}/frame`
|
||||
//console.log(url)
|
||||
return req(url, (err, res, body) => {
|
||||
let ms = (+new Date()) - timeStart
|
||||
if (err) {
|
||||
return reject(err)
|
||||
}
|
||||
return resolve(ms)
|
||||
})
|
||||
})
|
||||
}
|
||||
async setDir (dir) {
|
||||
return new Promise ((resolve, reject) => {
|
||||
const timeStart = +new Date()
|
||||
const url = `${this._baseUrl}/dir?dir=${dir}`
|
||||
//console.log(url)
|
||||
return req(url, (err, res, body) => {
|
||||
let ms = (+new Date()) - timeStart
|
||||
if (err) {
|
||||
return reject(err)
|
||||
}
|
||||
return resolve(ms)
|
||||
})
|
||||
})
|
||||
}
|
||||
async setExposure (exposure, cb) {
|
||||
return new Promise ((resolve, reject) => {
|
||||
const timeStart = +new Date()
|
||||
const url = `${this._baseUrl}/exposure?exposure=${exposure}`
|
||||
//console.log(url)
|
||||
return req(url, (err, res, body) => {
|
||||
let ms = (+new Date()) - timeStart
|
||||
if (err) {
|
||||
return reject(err)
|
||||
}
|
||||
return resolve(ms)
|
||||
})
|
||||
})
|
||||
}
|
||||
connect (cb) {
|
||||
const timeStart = +new Date()
|
||||
const url = `${this._baseUrl}/status`
|
||||
const opts = {
|
||||
method : 'GET',
|
||||
uri : url,
|
||||
timeout: 5000
|
||||
}
|
||||
|
||||
req(opts, (err, res, body) => {
|
||||
let ms = (+new Date()) - timeStart
|
||||
if (err) {
|
||||
//console.error(err)
|
||||
return cb(err, ms)
|
||||
}
|
||||
cb(null, ms, body)
|
||||
})
|
||||
}
|
||||
constructor(url) {
|
||||
this._baseUrl = `http://${url}`;
|
||||
this.req = require('request');
|
||||
}
|
||||
async move() {
|
||||
return new Promise((resolve, reject) => {
|
||||
const timeStart = +new Date();
|
||||
const url = `${this._baseUrl}/frame`;
|
||||
//console.log(url)
|
||||
return this.req(url, (err, res, body) => {
|
||||
let ms = (+new Date()) - timeStart;
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
return resolve(ms);
|
||||
});
|
||||
});
|
||||
}
|
||||
async setDir(dir) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const timeStart = +new Date();
|
||||
const url = `${this._baseUrl}/dir?dir=${dir}`;
|
||||
//console.log(url)
|
||||
return this.req(url, (err, res, body) => {
|
||||
let ms = (+new Date()) - timeStart;
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
return resolve(ms);
|
||||
});
|
||||
});
|
||||
}
|
||||
async setExposure(exposure, cb) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const timeStart = +new Date();
|
||||
const url = `${this._baseUrl}/exposure?exposure=${exposure}`;
|
||||
//console.log(url)
|
||||
return this.req(url, (err, res, body) => {
|
||||
let ms = (+new Date()) - timeStart;
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
return resolve(ms);
|
||||
});
|
||||
});
|
||||
}
|
||||
connect(cb) {
|
||||
const timeStart = +new Date();
|
||||
const url = `${this._baseUrl}/status`;
|
||||
const opts = {
|
||||
method: 'GET',
|
||||
uri: url,
|
||||
timeout: 5000
|
||||
};
|
||||
this.req(opts, (err, res, body) => {
|
||||
let ms = (+new Date()) - timeStart;
|
||||
if (err) {
|
||||
//console.error(err)
|
||||
return cb(err, ms);
|
||||
}
|
||||
cb(null, ms, body);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Intval
|
||||
module.exports.Intval = Intval;
|
||||
//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AAC,GAAG,SAAS,CAAA;YAC3C,IAAI,GAAG,EAAE;gBACR,oBAAoB;gBACpB,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;aAClB;YACD,EAAE,CAAC,IAAI,EAAE,EAAE,EAAE,IAAI,CAAC,CAAA;QACnB,CAAC,CAAC,CAAA;IACH,CAAC;CACD;AAED,MAAM,CAAC,OAAO,CAAC,MAAM,GAAG,MAAM,CAAA"}
|
|
@ -0,0 +1,68 @@
|
|||
'use strict';
|
||||
class Intval {
|
||||
constructor(url) {
|
||||
this._baseUrl = `http://${url}`;
|
||||
this.req = require('request');
|
||||
}
|
||||
async move() {
|
||||
return new Promise((resolve, reject) => {
|
||||
const timeStart = +new Date();
|
||||
const url = `${this._baseUrl}/frame`;
|
||||
//console.log(url)
|
||||
return this.req(url, (err, res, body) => {
|
||||
let ms = (+new Date()) - timeStart;
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
return resolve(ms);
|
||||
});
|
||||
});
|
||||
}
|
||||
async setDir(dir) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const timeStart = +new Date();
|
||||
const url = `${this._baseUrl}/dir?dir=${dir}`;
|
||||
//console.log(url)
|
||||
return this.req(url, (err, res, body) => {
|
||||
let ms = (+new Date()) - timeStart;
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
return resolve(ms);
|
||||
});
|
||||
});
|
||||
}
|
||||
async setExposure(exposure, cb) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const timeStart = +new Date();
|
||||
const url = `${this._baseUrl}/exposure?exposure=${exposure}`;
|
||||
//console.log(url)
|
||||
return this.req(url, (err, res, body) => {
|
||||
let ms = (+new Date()) - timeStart;
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
return resolve(ms);
|
||||
});
|
||||
});
|
||||
}
|
||||
connect(cb) {
|
||||
const timeStart = +new Date();
|
||||
const url = `${this._baseUrl}/status`;
|
||||
const opts = {
|
||||
method: 'GET',
|
||||
uri: url,
|
||||
timeout: 5000
|
||||
};
|
||||
this.req(opts, (err, res, body) => {
|
||||
let ms = (+new Date()) - timeStart;
|
||||
if (err) {
|
||||
//console.error(err)
|
||||
return cb(err, ms);
|
||||
}
|
||||
cb(null, ms, body);
|
||||
});
|
||||
}
|
||||
}
|
||||
module.exports.Intval = Intval;
|
||||
//# sourceMappingURL=index.js.map
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/intval/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,MAAM,MAAM;IAGX,YAAa,GAAY;QACxB,IAAI,CAAC,QAAQ,GAAG,UAAU,GAAG,EAAE,CAAA;QAC/B,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,SAAS,CAAC,CAAA;IAC9B,CAAC;IACM,KAAK,CAAC,IAAI;QAChB,OAAO,IAAI,OAAO,CAAE,CAAC,OAAa,EAAE,MAAY,EAAE,EAAE;YACnD,MAAM,SAAS,GAAY,CAAC,IAAI,IAAI,EAAE,CAAA;YACtC,MAAM,GAAG,GAAY,GAAG,IAAI,CAAC,QAAQ,QAAQ,CAAA;YAC7C,kBAAkB;YAClB,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAW,EAAE,GAAS,EAAE,IAAa,EAAE,EAAE;gBAC9D,IAAI,EAAE,GAAY,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,GAAG,SAAS,CAAA;gBAC3C,IAAI,GAAG,EAAE;oBACR,OAAO,MAAM,CAAC,GAAG,CAAC,CAAA;iBAClB;gBACD,OAAO,OAAO,CAAC,EAAE,CAAC,CAAA;YACnB,CAAC,CAAC,CAAA;QACH,CAAC,CAAC,CAAA;IACH,CAAC;IACM,KAAK,CAAC,MAAM,CAAE,GAAa;QACjC,OAAO,IAAI,OAAO,CAAE,CAAC,OAAa,EAAE,MAAY,EAAE,EAAE;YACnD,MAAM,SAAS,GAAY,CAAC,IAAI,IAAI,E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B,MAAM,EAAG,KAAK;YACd,GAAG,EAAG,GAAG;YACT,OAAO,EAAE,IAAI;SACb,CAAA;QAED,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,GAAW,EAAE,GAAS,EAAE,IAAa,EAAE,EAAE;YACxD,IAAI,EAAE,GAAY,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,GAAG,SAAS,CAAA;YAC3C,IAAI,GAAG,EAAE;gBACR,oBAAoB;gBACpB,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;aAClB;YACD,EAAE,CAAC,IAAI,EAAE,EAAE,EAAE,IAAI,CAAC,CAAA;QACnB,CAAC,CAAC,CAAA;IACH,CAAC;CACD;AAED,MAAM,CAAC,OAAO,CAAC,MAAM,GAAG,MAAM,CAAA"}
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"name": "intval",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC"
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
'use strict'
|
||||
|
||||
class Intval {
|
||||
private _baseUrl : string
|
||||
private req : any
|
||||
constructor (url : string) {
|
||||
this._baseUrl = `http://${url}`
|
||||
this.req = require('request')
|
||||
}
|
||||
public async move () {
|
||||
return new Promise ((resolve : any, reject : any) => {
|
||||
const timeStart : number = +new Date()
|
||||
const url : string = `${this._baseUrl}/frame`
|
||||
//console.log(url)
|
||||
return this.req(url, (err : Error, res : any, body : string) => {
|
||||
let ms : number = (+new Date()) - timeStart
|
||||
if (err) {
|
||||
return reject(err)
|
||||
}
|
||||
return resolve(ms)
|
||||
})
|
||||
})
|
||||
}
|
||||
public async setDir (dir : boolean) {
|
||||
return new Promise ((resolve : any, reject : any) => {
|
||||
const timeStart : number = +new Date()
|
||||
const url : string = `${this._baseUrl}/dir?dir=${dir}`
|
||||
//console.log(url)
|
||||
return this.req(url, (err : Error, res : any, body : string) => {
|
||||
let ms : number = (+new Date()) - timeStart
|
||||
if (err) {
|
||||
return reject(err)
|
||||
}
|
||||
return resolve(ms)
|
||||
})
|
||||
})
|
||||
}
|
||||
public async setExposure (exposure : number, cb : Function) {
|
||||
return new Promise ((resolve : any, reject : any) => {
|
||||
const timeStart : number = +new Date()
|
||||
const url : string = `${this._baseUrl}/exposure?exposure=${exposure}`
|
||||
//console.log(url)
|
||||
return this.req(url, (err : Error, res : any, body : string) => {
|
||||
let ms : number = (+new Date()) - timeStart
|
||||
if (err) {
|
||||
return reject(err)
|
||||
}
|
||||
return resolve(ms)
|
||||
})
|
||||
})
|
||||
}
|
||||
public connect (cb : Function) {
|
||||
const timeStart : number = +new Date()
|
||||
const url : string = `${this._baseUrl}/status`
|
||||
const opts : any = {
|
||||
method : 'GET',
|
||||
uri : url,
|
||||
timeout: 5000
|
||||
}
|
||||
|
||||
this.req(opts, (err : Error, res : any, body : string) => {
|
||||
let ms : number = (+new Date()) - timeStart
|
||||
if (err) {
|
||||
//console.error(err)
|
||||
return cb(err, ms)
|
||||
}
|
||||
cb(null, ms, body)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.Intval = Intval
|
Loading…
Reference in New Issue