server-reach-by-image
Advanced tools
Comparing version 1.0.7 to 1.0.8
@@ -27,6 +27,4 @@ function _classCallCheck(instance, Constructor) { | ||
var errors = { | ||
load_timeout: 'Loading image timed out', | ||
load_fail: 'Loading image failed', | ||
param_missing_urls: 'Url param(s) not specified', | ||
param_timeout_integer: 'Timeout param should be an integer' | ||
E_LOAD_TIMEOUT: 'Loading image timed out', | ||
E_LOAD_FAIL: 'Loading image failed' | ||
}; | ||
@@ -52,14 +50,11 @@ | ||
return new Promise(function (resolve, reject) { | ||
/* eslint-disable prefer-promise-reject-errors */ | ||
var fail = function fail(msg) { | ||
return reject({ | ||
msg: new Error(msg), | ||
status: false | ||
}); | ||
var fail = function fail(code) { | ||
return reject(Object.assign(new Error(errors[code]), { | ||
status: false, | ||
code: code | ||
})); | ||
}; | ||
/* eslint-disable no-undef */ | ||
var img = new window.Image(); | ||
var img = new Image(); | ||
img.onload = function () { | ||
@@ -73,3 +68,3 @@ return resolve({ | ||
img.onerror = function (e) { | ||
return fail(errors.load_fail); | ||
return fail('E_LOAD_FAIL'); | ||
}; | ||
@@ -79,3 +74,3 @@ | ||
setTimeout(function () { | ||
return fail(errors.load_timeout); | ||
return fail('E_LOAD_TIMEOUT'); | ||
}, _this.options.timeout); | ||
@@ -88,3 +83,3 @@ }); | ||
if (!this.options.url || !this.options.imgUrl) { | ||
throw new Error(errors.param_missing_urls); | ||
throw new Error('Url param(s) not specified'); | ||
} | ||
@@ -99,3 +94,3 @@ | ||
if (!Number.isInteger(this.options.timeout)) { | ||
throw new Error(errors.param_timeout_integer); | ||
throw new TypeError('Timeout param should be an integer'); | ||
} | ||
@@ -108,2 +103,3 @@ } | ||
ServerReachByImage.errors = Object.keys(errors); | ||
module.exports = ServerReachByImage; |
@@ -33,6 +33,4 @@ (function (global, factory) { | ||
var errors = { | ||
load_timeout: 'Loading image timed out', | ||
load_fail: 'Loading image failed', | ||
param_missing_urls: 'Url param(s) not specified', | ||
param_timeout_integer: 'Timeout param should be an integer' | ||
E_LOAD_TIMEOUT: 'Loading image timed out', | ||
E_LOAD_FAIL: 'Loading image failed' | ||
}; | ||
@@ -58,14 +56,11 @@ | ||
return new Promise(function (resolve, reject) { | ||
/* eslint-disable prefer-promise-reject-errors */ | ||
var fail = function fail(msg) { | ||
return reject({ | ||
msg: new Error(msg), | ||
status: false | ||
}); | ||
var fail = function fail(code) { | ||
return reject(Object.assign(new Error(errors[code]), { | ||
status: false, | ||
code: code | ||
})); | ||
}; | ||
/* eslint-disable no-undef */ | ||
var img = new window.Image(); | ||
var img = new Image(); | ||
img.onload = function () { | ||
@@ -79,3 +74,3 @@ return resolve({ | ||
img.onerror = function (e) { | ||
return fail(errors.load_fail); | ||
return fail('E_LOAD_FAIL'); | ||
}; | ||
@@ -85,3 +80,3 @@ | ||
setTimeout(function () { | ||
return fail(errors.load_timeout); | ||
return fail('E_LOAD_TIMEOUT'); | ||
}, _this.options.timeout); | ||
@@ -94,3 +89,3 @@ }); | ||
if (!this.options.url || !this.options.imgUrl) { | ||
throw new Error(errors.param_missing_urls); | ||
throw new Error('Url param(s) not specified'); | ||
} | ||
@@ -105,3 +100,3 @@ | ||
if (!Number.isInteger(this.options.timeout)) { | ||
throw new Error(errors.param_timeout_integer); | ||
throw new TypeError('Timeout param should be an integer'); | ||
} | ||
@@ -114,4 +109,5 @@ } | ||
ServerReachByImage.errors = Object.keys(errors); | ||
module.exports = ServerReachByImage; | ||
}))); |
@@ -1,2 +0,2 @@ | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n():"function"==typeof define&&define.amd?define(n):n()}(0,function(){"use strict";function t(t,n){for(var e=0;e<n.length;e++){var o=n[e];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}var n={timeout:2500},e="Loading image timed out",o="Loading image failed",i="Url param(s) not specified",r="Timeout param should be an integer",a=function(){function a(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}(this,a),this.options=Object.assign({},n,t),this.validateParams()}var s,u,c;return s=a,(u=[{key:"load",value:function(){var t=this;return new Promise(function(n,i){var r=function(t){return i({msg:new Error(t),status:!1})},a=new Image;a.onload=function(){return n({msg:null,status:!0})},a.onerror=function(t){return r(o)},a.src="".concat(t.options.url).concat(t.options.imgUrl,"?").concat((new Date).getTime()),setTimeout(function(){return r(e)},t.options.timeout)})}},{key:"validateParams",value:function(){if(!this.options.url||!this.options.imgUrl)throw new Error(i);if(this.options.url=this.options.url.replace(/\/+$/,""),this.options.imgUrl.startsWith("/")||(this.options.imgUrl="/".concat(this.options.imgUrl)),!Number.isInteger(this.options.timeout))throw new Error(r)}}])&&t(s.prototype,u),c&&t(s,c),a}();module.exports=a}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e():"function"==typeof define&&define.amd?define(e):e()}(0,function(){"use strict";function t(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}var e={timeout:2500},n={E_LOAD_TIMEOUT:"Loading image timed out",E_LOAD_FAIL:"Loading image failed"},o=function(){function o(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,o),this.options=Object.assign({},e,t),this.validateParams()}var i,r,a;return i=o,(r=[{key:"load",value:function(){var t=this;return new Promise(function(e,o){var i=function(t){return o(Object.assign(new Error(n[t]),{status:!1,code:t}))},r=new window.Image;r.onload=function(){return e({msg:null,status:!0})},r.onerror=function(t){return i("E_LOAD_FAIL")},r.src="".concat(t.options.url).concat(t.options.imgUrl,"?").concat((new Date).getTime()),setTimeout(function(){return i("E_LOAD_TIMEOUT")},t.options.timeout)})}},{key:"validateParams",value:function(){if(!this.options.url||!this.options.imgUrl)throw new Error("Url param(s) not specified");if(this.options.url=this.options.url.replace(/\/+$/,""),this.options.imgUrl.startsWith("/")||(this.options.imgUrl="/".concat(this.options.imgUrl)),!Number.isInteger(this.options.timeout))throw new TypeError("Timeout param should be an integer")}}])&&t(i.prototype,r),a&&t(i,a),o}();o.errors=Object.keys(n),module.exports=o}); | ||
//# sourceMappingURL=server-reach-by-image.min.js.map |
{ | ||
"name": "server-reach-by-image", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"description": "Check can you reach a specific server (address or ip) by using image hosted on that server.", | ||
@@ -5,0 +5,0 @@ "main": "dist/server-reach-by-image.min.js", |
@@ -23,7 +23,11 @@ # Server Reach By Image | ||
```js | ||
import ServerReachByImage from 'server-reach-by-image'; | ||
import ServerReachByImage, { errors } from 'server-reach-by-image'; | ||
const options = {}; | ||
const serverByImage = new ServerReachByImage(options); | ||
serverByImage.load().then(success).catch(fail); | ||
serverByImage.load() | ||
.then(data => {}) | ||
.catch({ code: errors.E_LOAD_FAIL }, e => {}) | ||
.catch({ code: errors.E_LOAD_TIMEOUT }, e => {}) | ||
.catch(e => {}); | ||
``` | ||
@@ -30,0 +34,0 @@ Fail method will receive error message as first parameter. |
@@ -5,6 +5,4 @@ const defaults = { | ||
const errors = { | ||
load_timeout: 'Loading image timed out', | ||
load_fail: 'Loading image failed', | ||
param_missing_urls: 'Url param(s) not specified', | ||
param_timeout_integer: 'Timeout param should be an integer' | ||
E_LOAD_TIMEOUT: 'Loading image timed out', | ||
E_LOAD_FAIL: 'Loading image failed' | ||
}; | ||
@@ -20,12 +18,10 @@ | ||
return new Promise((resolve, reject) => { | ||
/* eslint-disable prefer-promise-reject-errors */ | ||
const fail = msg => reject({ msg: new Error(msg), status: false }); | ||
const fail = code => reject(Object.assign(new Error(errors[code]), { status: false, code })); | ||
/* eslint-disable no-undef */ | ||
const img = new Image(); | ||
const img = new window.Image(); | ||
img.onload = () => resolve({ msg: null, status: true }); | ||
img.onerror = e => fail(errors.load_fail); | ||
img.onerror = e => fail('E_LOAD_FAIL'); | ||
img.src = `${this.options.url}${this.options.imgUrl}?${new Date().getTime()}`; | ||
setTimeout(() => fail(errors.load_timeout), this.options.timeout); | ||
setTimeout(() => fail('E_LOAD_TIMEOUT'), this.options.timeout); | ||
}); | ||
@@ -36,3 +32,3 @@ } | ||
if (!this.options.url || !this.options.imgUrl) { | ||
throw new Error(errors.param_missing_urls); | ||
throw new Error('Url param(s) not specified'); | ||
} | ||
@@ -46,3 +42,3 @@ | ||
if (!Number.isInteger(this.options.timeout)) { | ||
throw new Error(errors.param_timeout_integer); | ||
throw new TypeError('Timeout param should be an integer'); | ||
} | ||
@@ -52,2 +48,3 @@ } | ||
ServerReachByImage.errors = Object.keys(errors); | ||
module.exports = ServerReachByImage; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12
43
15576
230