Skip to content

Commit

Permalink
🎉 version 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
whatwewant committed Nov 7, 2018
0 parents commit ccb8db0
Show file tree
Hide file tree
Showing 11 changed files with 391 additions and 0 deletions.
67 changes: 67 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# https://github.com/github/gitignore/blob/master/Node.gitignore

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# next.js build output
.next

yarn.lock

lib
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
20 changes: 20 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
language: node_js

node_js:
- "8"
- "10"

after_success: npm run test && npm run coverage

jobs:
include:
- stage: npm release
node_js: 10
script: echo "deploying to npm"
deploy:
provider: npm
email: uniquecolesmith@gmail.com
api_key: $NPM_AUTH_TOKEN
skip_cleanup: true
on:
tags: true
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 Eason

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:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# is-up

[![NPM version](https://img.shields.io/npm/v/@zcorky/is-up.svg?style=flat)](https://www.npmjs.com/package/@zcorky/is-up)
[![Coverage Status](https://img.shields.io/coveralls/zcorky/is-up.svg?style=flat)](https://coveralls.io/r/zcorky/is-up)
[![Dependencies](https://david-dm.org/@zcorky/is-up/status.svg)](https://david-dm.org/@zcorky/is-up)
[![Build Status](https://travis-ci.com/zcorky/is-up.svg?branch=master)](https://travis-ci.com/zcorky/is-up)
![license](https://img.shields.io/github/license/zcorky/is-up.svg)
[![issues](https://img.shields.io/github/issues/zcorky/is-up.svg)](https://github.com/zcorky/is-up/issues)

> Check whether a website is up or down using the [isitup.org](https://isitup.org/) API
### Install

```
$ npm install @zcorky/is-up
```

### Usage

```javascript
import isUp from '@zcorky/is-up';
// const isUp = require('@zcorky/is-up').isUp;

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

### Related
* [sindresorhus/is-up](https://github.com/sindresorhus/is-up)
Empty file added docs/.keep
Empty file.
60 changes: 60 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"name": "@zcorky/is-up",
"version": "1.0.0",
"description": "Give a is-up for your app.",
"main": "lib/index.js",
"repository": "https://github.com/zcorky/is-up",
"author": "Zero",
"license": "MIT",
"scripts": {
"build": "npm run clean && tsc",
"clean": "rimraf -rf lib",
"test": "NODE_ENV=test nyc mocha test/*.spec.ts --exit --timeout 10000",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"prepublish": "npm run build"
},
"devDependencies": {
"@types/mocha": "^5.2.5",
"@types/node": "^10.9.4",
"@types/sinon": "^5.0.2",
"@zcorky/is": "^1.0.1",
"chai": "^4.1.2",
"chai-spies": "^1.0.0",
"coveralls": "^3.0.2",
"mocha": "^5.2.0",
"nyc": "^13.0.1",
"rimraf": "^2.6.2",
"sinon": "^6.3.4",
"source-map-support": "^0.5.9",
"ts-node": "^7.0.1",
"tslint": "^5.10.0",
"tslint-eslint-rules": "^5.3.1",
"tslint-jsdoc-rules": "^0.1.2",
"typescript": "^3.1.1"
},
"files": [
"lib/"
],
"nyc": {
"check-coverage": true,
"include": [
"src/**/*.ts"
],
"extension": [
".ts"
],
"require": [
"ts-node/register",
"source-map-support/register"
],
"sourceMap": true,
"instrument": true
},
"publishConfig": {
"access": "public"
},
"dependencies": {
"@zcorky/fz": "^1.0.2",
"isomorphic-fetch": "^2.2.1"
}
}
28 changes: 28 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import fz from '@zcorky/fz';
import * as engine from 'isomorphic-fetch';

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

export const isUp = async (url: string) => {
const _url = encodeURIComponent(url.replace(/^(?:https?:)?\/\//, ''));
const { status_code: statusCode } = await fz.get(`https://isitup.org/${_url}.json`, {
engine,
headers: {
userAgent: 'https://github.com/zcorky/is-up',
},
}).json() as any;

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

return statusCode === STATUS_CODES.isUp;
}

export default isUp;

// module.exports = isUp;
24 changes: 24 additions & 0 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { expect } from 'chai';

import isUp from '../src/index';

console.log(typeof isUp);

describe('is-up', () => {
it('up', async () => {
expect(await isUp('https://google.com')).to.be.true;
});

it('down', async () => {
expect(await isUp('https://example.abc.com')).to.be.false;
});

it('invalid domain', async () => {
try {
await isUp('unicorn');
throw new Error('never match');
} catch (e) {
expect(e).to.match(/Invalid domain/);
}
});
});
22 changes: 22 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"compilerOptions": {
"moduleResolution": "node",
"module": "commonjs",
"target": "es5",
"strictNullChecks": true,
"noImplicitThis": false,
"noUnusedLocals": true,
"noImplicitAny": false,
"outDir": "lib",
"lib": ["dom", "es2015"],
"declaration": true,
"sourceMap": false,
"removeComments": true,
"baseUrl": "./",
"paths": {
"@/*": ["src/*"],
"lib/*": ["src/*"]
}
},
"include": ["src/**/*.ts"]
}

0 comments on commit ccb8db0

Please sign in to comment.