-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
6,820 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/.nyc_output | ||
/dist | ||
/node_modules | ||
/test/dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Monapt | ||
|
||
[![npm version](https://badge.fury.io/js/monapt.svg)](http://badge.fury.io/js/monapt) | ||
[![Build Status](https://circleci.com/gh/jiaweihli/monapt/tree/1.0.svg?style=shield)](https://circleci.com/gh/jiaweihli/monapt/tree/1.0) | ||
[![Coverage Status](https://coveralls.io/repos/github/jiaweihli/monapt/badge.svg?branch=1.0)](https://coveralls.io/github/jiaweihli/monapt?branch=1.0) | ||
|
||
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/) | ||
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-green.svg)](https://conventionalcommits.org) | ||
|
||
Monapt helps you better manage `null`, `undefined`, exceptions, and other mildly interesting | ||
phenomena. It handles them through the | ||
[`Option`](http://danielwestheide.com/blog/2012/12/19/the-neophytes-guide-to-scala-part-5-the-option-type.html), | ||
[`Try`](http://danielwestheide.com/blog/2012/12/26/the-neophytes-guide-to-scala-part-6-error-handling-with-try.html), | ||
and [`Future`](http://danielwestheide.com/blog/2013/01/09/the-neophytes-guide-to-scala-part-8-welcome-to-the-future.html) | ||
abstractions. | ||
|
||
|
||
## Setup | ||
|
||
```bash | ||
$ npm install monapt | ||
``` | ||
|
||
## APIs | ||
|
||
### Usage | ||
|
||
```typescript | ||
import { Option } from 'monapt'; | ||
|
||
Option(1) | ||
.map((x) => x * 2) | ||
.getOrElse(() => 4); | ||
``` | ||
|
||
Docs are undergoing a redesign, and will be published on a separate site. | ||
In the meantime, the sources for the [`Option`](https://github.com/jiaweihli/monapt/tree/master/src/option), | ||
[`Future`](https://github.com/jiaweihli/monapt/tree/master/src/future), and | ||
[`Try`](https://github.com/jiaweihli/monapt/tree/master/src/try) classes are readable. | ||
|
||
You can also take a look at the [tests](https://github.com/jiaweihli/monapt/tree/master/test) to get | ||
a feel for how to use them. | ||
|
||
## Changes in 1.0 | ||
|
||
1.0 was a complete rewrite of Monapt - including everything from the implementation to the tooling | ||
to the tests. The result is almost the same API, but more true to the original Scala interface. | ||
|
||
## Migrating from 0.7.1 | ||
|
||
### Breaking Changes | ||
|
||
- All default exports have been removed [to avoid ambiguity](https://github.com/palantir/tslint/issues/1182#issue-151780453). | ||
- `Future` now depends on `when.Promise`, and uses it internally when representing promises. | ||
- `Future#onFailure` has been removed. | ||
- `Future#onSuccess` has been removed. | ||
- `Future#reject` has been removed. | ||
- `Monapt::flatten` has been renamed to `Option::flatten`. | ||
- `Monapt::future` has been renamed to `Future::create`. It now accepts a | ||
`when.Promise<A> | when.Thenable<A> | A`. | ||
- `Option#reject` has been renamed to `Option#filterNot`. | ||
- `Try#reject` has been removed. | ||
|
||
These are all backed by type definitions, so compiling your code via TypeScript should reveal any | ||
breakages. | ||
|
||
## Credits | ||
|
||
This repo couldn't have been possible without [yaakaito/monapt](https://github.com/yaakaito/monapt). | ||
In his absence, I'll continue improving upon his hard work. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const path = require('path'); | ||
|
||
module.exports = { | ||
entry: './src/monapt.ts', | ||
output: { | ||
filename: 'monapt.js', | ||
library: 'Monapt', | ||
libraryTarget: 'umd', | ||
path: path.resolve(__dirname, 'dist') | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.ts$/, | ||
loader: 'ts-loader' | ||
} | ||
] | ||
}, | ||
resolve: { | ||
modules: [ | ||
'node_modules' | ||
], | ||
extensions: ['.ts', '.js'] | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
version: 2 | ||
jobs: | ||
build: | ||
working_directory: ~/monapt | ||
docker: | ||
- image: node:boron | ||
environment: | ||
- COVERALLS_REPO_TOKEN: "mMDS1eSfES0hTguOkxWQOLDHbLJdfZLAa" | ||
steps: | ||
- checkout | ||
- restore_cache: | ||
key: node-{{ .Branch }}-{{ checksum "package.json" }} | ||
- run: | ||
name: Installing JS dependencies | ||
command: npm install | ||
- save_cache: | ||
key: node-{{ .Branch }}-{{ checksum "package.json" }} | ||
paths: | ||
- "node_modules" | ||
- run: | ||
name: Running tests | ||
command: npm run test | ||
- run: | ||
name: Reporting code coverage to Coveralls | ||
command: npm run coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
{ | ||
"name": "monapt", | ||
"version": "1.0.0", | ||
"description": "Eliminate null/undefined errors in JS...and more!", | ||
"author": { | ||
"name": "Kevin Li", | ||
"email": "[email protected]", | ||
"url": "https://jiawei.li/" | ||
}, | ||
"license": "MIT", | ||
"homepage": "https://github.com/jiaweihli/monapt#readme", | ||
"bugs": { | ||
"url": "https://github.com/jiaweihli/monapt/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/jiaweihli/monapt.git" | ||
}, | ||
"scripts": { | ||
"build": "webpack --config build.webpack.config.js", | ||
"commit": "git-cz", | ||
"commitmsg": "validate-commit-msg", | ||
"coverage": "nyc report --reporter=text-lcov | coveralls", | ||
"lint:ts": "tslint --format verbose --project ./src/tsconfig.json --type-check './src/**/*.ts' && tslint --format verbose --config ./test/tslint.json --project ./test/tsconfig.json --type-check --exclude './test/dist/**/*.ts' './test/**/*.ts'", | ||
"smoke:ts": "tsc --noEmit --pretty --project ./src/tsconfig.json && tsc --noEmit --pretty --project ./test/tsconfig.json", | ||
"test": "webpack --config test.webpack.config.js && nyc ava --verbose", | ||
"watch": "webpack --config build.webpack.config.js --watch" | ||
}, | ||
"main": "dist/monapt.js", | ||
"typings": "dist/src/monapt.d.ts", | ||
"files": [ | ||
"dist/", | ||
"README.md" | ||
], | ||
"keywords": [ | ||
"option", | ||
"optional", | ||
"future", | ||
"try", | ||
"monad", | ||
"functional", | ||
"util", | ||
"scala", | ||
"type", | ||
"types" | ||
], | ||
"dependencies": { | ||
"when": "3.7.8" | ||
}, | ||
"devDependencies": { | ||
"@types/when": "2.4.29", | ||
"ava": "0.20.0", | ||
"commitizen": "2.9.6", | ||
"conventional-changelog-cli": "1.3.1", | ||
"conventional-commit-types": "2.1.0", | ||
"coveralls": "2.13.1", | ||
"cracks": "3.1.2", | ||
"cz-conventional-changelog": "2.0.0", | ||
"glob": "7.1.2", | ||
"husky": "0.14.1", | ||
"istanbul-instrumenter-loader": "2.0.0", | ||
"nyc": "11.0.3", | ||
"semantic-release": "6.3.6", | ||
"ts-loader": "2.2.1", | ||
"tslint": "5.1.0", | ||
"typescript": "2.3.4", | ||
"validate-commit-msg": "2.12.2", | ||
"webpack": "2.6.1" | ||
}, | ||
"config": { | ||
"commitizen": { | ||
"path": "./node_modules/cz-conventional-changelog" | ||
}, | ||
"validate-commit-msg": { | ||
"types": "conventional-commit-types", | ||
"scope": { | ||
"required": false, | ||
"allowed": [ | ||
"*" | ||
], | ||
"validate": true, | ||
"multiple": false | ||
}, | ||
"warnOnFail": true, | ||
"maxSubjectLength": 100, | ||
"subjectPattern": ".+", | ||
"subjectPatternErrorMsg": "subject does not match subject pattern!", | ||
"helpMessage": "", | ||
"autoFix": false | ||
} | ||
}, | ||
"release": { | ||
"verifyRelease": { | ||
"path": "cracks", | ||
"paths": [ | ||
"test", | ||
"package.json" | ||
], | ||
"silent": true | ||
} | ||
} | ||
} |
Oops, something went wrong.