Skip to content
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

Simplify setup #1

Open
wants to merge 1 commit 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
7 changes: 0 additions & 7 deletions .babelrc

This file was deleted.

14 changes: 0 additions & 14 deletions .flowconfig

This file was deleted.

9 changes: 1 addition & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
lib
dist
**/*.js
**/*.flow
!src/**/*.js
!src/**/*.flow
!test/**/*.js
!test/**/*.flow
/node_modules/
6 changes: 0 additions & 6 deletions .npmignore

This file was deleted.

1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
language: node_js
sudo: false
node_js:
- 'stable'
- '8.10.0'
- '8'
- '10'
- '12'
deploy:
provider: npm
email: [email protected]
Expand Down
Empty file removed docs/.nojekyll
Empty file.
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 unreachable (value: never): never
export = unreachable
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// @flow

module.exports = function unreachable (value /*: empty */) /*: empty */ {
throw new TypeError('Internal error: Encountered impossible value: ' + JSON.stringify(value))
}
24 changes: 24 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { expectError, expectType } from 'tsd'
import unreachable = require('.')

expectType<(value: never) => never>(unreachable)

type Shape =
| { kind: 'square', size: number }
| { kind: 'rectangle', width: number, height: number }
| { kind: 'circle', radius: number }

const area = (shape: Shape): number => {
switch (shape.kind) {
case 'square':
return shape.size * shape.size
case 'rectangle':
return shape.height * shape.width
case 'circle':
return Math.PI * shape.radius ** 2
default:
return unreachable(shape)
}
}

expectError(area({ kind: 'circl', radius: 7 }))
43 changes: 11 additions & 32 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"version": "0.2.0",
"name": "unreachable",
"version": "0.2.0",
"description": "Utility function for exhaustiveness checking with typed JS (TS or Flow)",
"keywords": [
"unreachable",
Expand All @@ -16,39 +16,18 @@
"switch",
"default"
],
"main": "lib/unreachable",
"module": "src/unreachable",
"types": "src/unreachable",
"author": "Irakli Gozalishvili <[email protected]> (http:https://jeditoolkit.com)",
"repository": "https://github.com/Gozala/unreachable",
"repository": "Gozala/unreachable",
"license": "MIT",
"devDependencies": {
"babel-cli": "6.24.1",
"babel-preset-flow-node": "^1.0.2",
"babel-register": "6.24.1",
"blue-tape": "^1.0.0",
"documentation": "^5.1.0",
"flow-bin": "^0.52.0",
"flow-copy-source": "^1.2.0",
"husky": "^0.14.0",
"lint-staged": "^4.0.2",
"prettier": "^1.5.3"
},
"author": "Irakli Gozalishvili <[email protected]> (http:https://jeditoolkit.com)",
"scripts": {
"test": "npm run test:flow && npm run test:tape",
"test:tape": "blue-tape -r babel-register test/**/*.js",
"test:flow": "flow check",
"build:clear": "rm -rf lib",
"build:types": "flow-copy-source --verbose src lib",
"build:node": "babel --out-dir lib src",
"build:api": "documentation readme --section=API src/unreachable.js",
"build:docs": "documentation build --document-exported src/** -f html --o docs",
"build": "npm run build:node && npm run build:types",
"prepublish": "npm run build && npm test",
"precommit": "lint-staged",
"start": "flow-copy-source --watch --verbose src lib & babel --watch --out-dir lib src"
"prepublish": "npm test",
"test": "standard && node test && tsd"
},
"devDependencies": {
"standard": "^14.3.3",
"tsd": "^0.11.0"
},
"lint-staged": {
"*.js": ["prettier --parser flow --no-semi --write", "git add"]
"engines": {
"node": ">=8.10"
}
}
5 changes: 0 additions & 5 deletions src/unreachable.d.ts

This file was deleted.

8 changes: 0 additions & 8 deletions src/unreachable.js

This file was deleted.

9 changes: 9 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const assert = require('assert')
const unreachable = require('.')

assert.strictEqual(typeof unreachable, 'function', 'default export is a function')

assert.throws(
() => { unreachable({ kind: 'circl', radius: 7 }) },
new TypeError('Internal error: Encountered impossible value: {"kind":"circl","radius":7}')
)
30 changes: 0 additions & 30 deletions test/unreachable.js

This file was deleted.

Loading