Skip to content

Commit

Permalink
Require Node.js 12.20 and move to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Sep 18, 2021
1 parent 26088da commit 3ced641
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 31 deletions.
4 changes: 0 additions & 4 deletions .github/funding.yml

This file was deleted.

6 changes: 2 additions & 4 deletions .github/workflows/main.yml
Expand Up @@ -10,12 +10,10 @@ jobs:
fail-fast: false
matrix:
node-version:
- 14
- 12
- 10
- 16
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm install
Expand Down
13 changes: 6 additions & 7 deletions index.js
@@ -1,24 +1,23 @@
'use strict';
const got = require('got');
import got from 'got';

const statusCodes = {
isUp: 1,
isDown: 2,
invalidDomain: 3
invalidDomain: 3,
};

module.exports = async url => {
export default async function isUp(url) {
const hostname = encodeURIComponent((new URL(url)).hostname);

const {status_code: statusCode} = await got(`https://isitup.org/${hostname}.json`, {
headers: {
'user-agent': 'https://github.com/sindresorhus/is-up'
}
'user-agent': 'https://github.com/sindresorhus/is-up',
},
}).json();

if (statusCode === statusCodes.invalidDomain) {
throw new Error('Invalid domain');
}

return statusCode === statusCodes.isUp;
};
}
2 changes: 1 addition & 1 deletion license
@@ -1,6 +1,6 @@
MIT License

Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
14 changes: 8 additions & 6 deletions package.json
Expand Up @@ -8,10 +8,12 @@
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=10"
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},
"scripts": {
"test": "xo && ava"
Expand All @@ -31,11 +33,11 @@
"offline"
],
"dependencies": {
"got": "^10.5.5"
"got": "^11.8.2"
},
"devDependencies": {
"ava": "^1.0.0",
"unique-string": "^2.0.0",
"xo": "^0.25.4"
"ava": "^3.15.0",
"unique-string": "^3.0.0",
"xo": "^0.44.0"
}
}
12 changes: 5 additions & 7 deletions readme.md
Expand Up @@ -4,19 +4,17 @@
## Install

```
$ npm install is-up
```sh
npm install is-up
```

## Usage

```js
const isUp = require('is-up');
import isUp from 'is-up';

(async () => {
console.log(await isUp('https://sindresorhus.com'));
//=> true
})();
console.log(await isUp('https://sindresorhus.com'));
//=> true
```

## Related
Expand Down
4 changes: 2 additions & 2 deletions test.js
@@ -1,6 +1,6 @@
import test from 'ava';
import uniqueString from 'unique-string';
import isUp from '.';
import isUp from './index.js';

test('up', async t => {
t.true(await isUp('https://google.com'));
Expand All @@ -11,5 +11,5 @@ test('down', async t => {
});

test('invalid domain', async t => {
await t.throwsAsync(isUp('unicorn'), 'Invalid URL: unicorn');
await t.throwsAsync(isUp('unicorn'), {message: 'Invalid URL'});
});

0 comments on commit 3ced641

Please sign in to comment.