Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

server-reach-by-image

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

server-reach-by-image - npm Package Compare versions

Comparing version 1.0.4 to 1.0.5

reach.js

49

index.js

@@ -1,48 +0,1 @@

const defaults = {
timeout: 2500
};
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'
};
class ServerReachByImage {
constructor(options = {}) {
this.options = Object.assign({}, defaults, options);
this.validateParams();
}
load() {
return new Promise((resolve, reject) => {
/* eslint-disable prefer-promise-reject-errors */
const fail = msg => reject({ msg: new Error(msg), status: false });
/* eslint-disable no-undef */
const img = new Image();
img.onload = () => resolve({ msg: null, status: true });
img.onerror = e => fail(errors.load_fail);
img.src = `${this.options.url}${this.options.imgUrl}?${new Date().getTime()}`;
setTimeout(() => fail(errors.load_timeout), this.options.timeout);
});
}
validateParams() {
if (!this.options.url || !this.options.imgUrl) {
throw new Error(errors.param_missing_urls);
}
this.options.url = this.options.url.replace(/\/+$/, '');
if (!this.options.imgUrl.startsWith('/')) {
this.options.imgUrl = `/${this.options.imgUrl}`;
}
if (!Number.isInteger(this.options.timeout)) {
throw new Error(errors.param_timeout_integer);
}
}
}
module.exports = ServerReachByImage;
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var o=e();for(var r in o)("object"==typeof exports?exports:t)[r]=o[r]}}(window,function(){return function(t){var e={};function o(r){if(e[r])return e[r].exports;var i=e[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,o),i.l=!0,i.exports}return o.m=t,o.c=e,o.d=function(t,e,r){o.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},o.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},o.t=function(t,e){if(1&e&&(t=o(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(o.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)o.d(r,i,function(e){return t[e]}.bind(null,i));return r},o.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return o.d(e,"a",e),e},o.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},o.p="",o(o.s=0)}([function(t,e){const o={timeout:2500},r={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"};t.exports=class{constructor(t={}){this.options=Object.assign({},o,t),this.validateParams()}load(){return new Promise((t,e)=>{const o=t=>e({msg:new Error(t),status:!1}),i=new Image;i.onload=(()=>t({msg:null,status:!0})),i.onerror=(t=>o(r.load_fail)),i.src=`${this.options.url}${this.options.imgUrl}?${(new Date).getTime()}`,setTimeout(()=>o(r.load_timeout),this.options.timeout)})}validateParams(){if(!this.options.url||!this.options.imgUrl)throw new Error(r.param_missing_urls);if(this.options.url=this.options.url.replace(/\/+$/,""),this.options.imgUrl.startsWith("/")||(this.options.imgUrl=`/${this.options.imgUrl}`),!Number.isInteger(this.options.timeout))throw new Error(r.param_timeout_integer)}}}])});
{
"name": "server-reach-by-image",
"version": "1.0.4",
"version": "1.0.5",
"description": "Check can you reach a specific server (address or ip) by using image hosted on that server.",

@@ -9,3 +9,5 @@ "main": "index.js",

"test": "jest",
"lint": "eslint ."
"lint": "eslint .",
"dev": "webpack --watch --mode development",
"prod": "webpack --progress --hide-modules --mode production"
},

@@ -35,5 +37,7 @@ "repository": {

"eslint-plugin-standard": "^3.1.0",
"jest": "^23.0.0"
"jest": "^23.0.0",
"webpack": "^4.10.2",
"webpack-cli": "^3.0.1"
},
"dependencies": {}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc