From b5fbe0153b6784d2b24c929dceeb42280d497561 Mon Sep 17 00:00:00 2001 From: mmcwilliams Date: Fri, 14 Jun 2019 11:58:35 -0400 Subject: [PATCH] Refactor intval module into Typescript. --- app/lib/intval/index.js | 135 ++++++++++++++++++------------------ app/lib/intval/index.js.map | 1 + cli/lib/intval/index.js | 135 ++++++++++++++++++------------------ cli/lib/intval/index.js.map | 1 + lib/intval/Readme.md | 0 lib/intval/index.js | 68 ++++++++++++++++++ lib/intval/index.js.map | 1 + lib/intval/package.json | 11 +++ src/intval/index.ts | 72 +++++++++++++++++++ 9 files changed, 286 insertions(+), 138 deletions(-) create mode 100644 app/lib/intval/index.js.map create mode 100644 cli/lib/intval/index.js.map create mode 100644 lib/intval/Readme.md create mode 100644 lib/intval/index.js create mode 100644 lib/intval/index.js.map create mode 100644 lib/intval/package.json create mode 100644 src/intval/index.ts diff --git a/app/lib/intval/index.js b/app/lib/intval/index.js index 0275b26..0ecb0fd 100644 --- a/app/lib/intval/index.js +++ b/app/lib/intval/index.js @@ -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 \ No newline at end of file +module.exports.Intval = Intval; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/app/lib/intval/index.js.map b/app/lib/intval/index.js.map new file mode 100644 index 0000000..b951f19 --- /dev/null +++ b/app/lib/intval/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/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AAED,MAAM,CAAC,OAAO,CAAC,MAAM,GAAG,MAAM,CAAA"} \ No newline at end of file diff --git a/cli/lib/intval/index.js b/cli/lib/intval/index.js index 0275b26..0ecb0fd 100644 --- a/cli/lib/intval/index.js +++ b/cli/lib/intval/index.js @@ -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 \ No newline at end of file +module.exports.Intval = Intval; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/cli/lib/intval/index.js.map b/cli/lib/intval/index.js.map new file mode 100644 index 0000000..b951f19 --- /dev/null +++ b/cli/lib/intval/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,CA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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,OAAO,CAAE,EAAa;QAC5B,MAAM,SAAS,GAAY,CAAC,IAAI,IAAI,EAAE,CAAA;QACtC,MAAM,GAAG,GAAY,GAAG,IAAI,CAAC,QAAQ,SAAS,CAAA;QAC9C,MAAM,IAAI,GAAS;YAClB,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"} \ No newline at end of file diff --git a/lib/intval/Readme.md b/lib/intval/Readme.md new file mode 100644 index 0000000..e69de29 diff --git a/lib/intval/index.js b/lib/intval/index.js new file mode 100644 index 0000000..0ecb0fd --- /dev/null +++ b/lib/intval/index.js @@ -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 \ No newline at end of file diff --git a/lib/intval/index.js.map b/lib/intval/index.js.map new file mode 100644 index 0000000..b951f19 --- /dev/null +++ b/lib/intval/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,IA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AC,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,OAAO,CAAE,EAAa;QAC5B,MAAM,SAAS,GAAY,CAAC,IAAI,IAAI,EAAE,CAAA;QACtC,MAAM,GAAG,GAAY,GAAG,IAAI,CAAC,QAAQ,SAAS,CAAA;QAC9C,MAAM,IAAI,GAAS;YAClB,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"} \ No newline at end of file diff --git a/lib/intval/package.json b/lib/intval/package.json new file mode 100644 index 0000000..d888b72 --- /dev/null +++ b/lib/intval/package.json @@ -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" +} diff --git a/src/intval/index.ts b/src/intval/index.ts new file mode 100644 index 0000000..ff9a744 --- /dev/null +++ b/src/intval/index.ts @@ -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 \ No newline at end of file