Skip to content

feat: update dependencies + add TypeScript types #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
npm-debug.*
test/coverage
.nyc_output
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
strict-peer-dependencies=false
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: node_js
node_js:
- "4"
- "6"
- "12"
- "16"
script: "npm run test-travis"
2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function isLinkWorking(link: string): Promise<boolean>
export = isLinkWorking
64 changes: 32 additions & 32 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function isOnlineAsPromise() {
isOnlineCache = new Promise((resolve, reject) => {
isOnline((err, online) => {
if (err) {
delete isOnlineCache.promise; // Do not cache errors
delete isOnlineCache.promise; // Do not cache errors
/* istanbul ignore next */
reject(err);
} else {
Expand All @@ -32,14 +32,14 @@ function isOnlineAsPromise() {

function checkConnectivity(requestErr) {
return isOnlineAsPromise()
.catch(() => { throw requestErr; })
.then((online) => {
if (!online) {
throw requestErr;
}
.catch(() => { throw requestErr; })
.then((online) => {
if (!online) {
throw requestErr;
}

return false;
});
return false;
});
}

class DevNull extends WritableStream {
Expand All @@ -50,7 +50,7 @@ class DevNull extends WritableStream {

function tryHead(link, gotOptions) {
return got.head(link, gotOptions)
.then(() => true);
.then(() => true);
}

function tryGet(link, options, gotOptions) {
Expand All @@ -65,29 +65,29 @@ function tryGet(link, options, gotOptions) {
}

stream
.on('request', (req_) => { req = req_; })
.on('response', (res) => {
res.on('error', () => {}); // Swallow any response errors, because we are going to abort the request
setImmediate(() => req.abort());
resolve(true);
})
.on('error', (err, body, res) => {
res && res.on('error', () => {}); // Swallow any response errors, because we are going to abort the request
setImmediate(() => req.abort());

if (err instanceof got.MaxRedirectsError || err instanceof got.HTTPError || err instanceof got.UnsupportedProtocolError) {
return resolve(false);
}
.on('request', (req_) => { req = req_; })
.on('response', (res) => {
res.on('error', () => {}); // Swallow any response errors, because we are going to abort the request
setImmediate(() => req.abort());
resolve(true);
})
.on('error', (err, body, res) => {
res && res.on('error', () => {}); // Swallow any response errors, because we are going to abort the request
setImmediate(() => req.abort());

if (err instanceof got.MaxRedirectsError || err instanceof got.HTTPError || err instanceof got.UnsupportedProtocolError) {
return resolve(false);
}

/* istanbul ignore else */
if (err instanceof got.RequestError) {
return resolve(options.checkConnectivity ? checkConnectivity(err) : false);
}

/* istanbul ignore else */
if (err instanceof got.RequestError) {
return resolve(options.checkConnectivity ? checkConnectivity(err) : false);
}

/* istanbul ignore next */
reject(err);
})
.pipe(new DevNull());
/* istanbul ignore next */
reject(err);
})
.pipe(new DevNull());
});
}

Expand All @@ -113,7 +113,7 @@ function isLinkWorking(link, options) {
};

return tryHead(link, gotOptions)
.catch(() => tryGet(link, options, gotOptions));
.catch(() => tryGet(link, options, gotOptions));
}

module.exports = isLinkWorking;
Expand Down
29 changes: 15 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
"description": "Checks if a given link is working or broken",
"main": "index.js",
"scripts": {
"lint": "eslint '{*.js,test/**/*.js}' --ignore-pattern=test/coverage",
"test": "mocha --bail",
"test-cov": "istanbul cover --dir test/coverage _mocha -- --bail && echo Coverage lies in test/coverage/lcov-report/index.html",
"test-travis": "istanbul cover _mocha --report lcovonly -- --bail && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"
"lint": "eslint *.js test/**/*.js --ignore-pattern=test/coverage",
"test": "mocha --timeout 10000 --bail",
"test-cov": "nyc --dir test/coverage _mocha -- --timeout 10000 --bail && echo Coverage lies in test/coverage/lcov-report/index.html",
"test-travis": "nyc _mocha --report lcovonly -- --timeout 10000 --bail && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"
},
"types": "./index.d.ts",
"bugs": {
"url": "https://github.com/IndigoUnited/node-is-link-working/issues/"
},
Expand All @@ -29,18 +30,18 @@
"author": "IndigoUnited <[email protected]> (http://indigounited.com)",
"license": "MIT",
"dependencies": {
"got": "^7.0.0",
"is-online": "^7.0.0"
"got": "^11.8.5",
"is-online": "^9.0.1"
},
"devDependencies": {
"@satazor/eslint-config": "^3.0.0",
"chai": "^4.0.0",
"coveralls": "^2.11.6",
"eslint": "^3.0.0",
"istanbul": "^0.4.1",
"mocha": "^3.0.2",
"mock-require": "^2.0.0",
"nock": "^9.0.0",
"@satazor/eslint-config": "^3.2.0",
"chai": "^4.3.6",
"coveralls": "^3.1.1",
"eslint": "^8.21.0",
"mocha": "^10.0.0",
"mock-require": "^3.0.3",
"nock": "^13.2.9",
"nyc": "^15.1.0",
"promise-delay": "^2.1.0"
},
"engines": {
Expand Down
Loading