-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit f4c90a7
Showing
17 changed files
with
3,094 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,3 @@ | ||
{ | ||
"extends": "@invisible" | ||
} |
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 @@ | ||
# Node shiz | ||
node_modules | ||
coverage | ||
complexity | ||
complexity.md | ||
dist | ||
.nyc_output | ||
|
||
# ignore the docs for now. We may decide to publish this later | ||
docs | ||
|
||
|
||
# Logs | ||
npm-debug.log* | ||
*.log | ||
|
||
# Env files | ||
*.env* | ||
|
||
# Temporary files | ||
*~ | ||
*.bak | ||
|
||
# Files generated by merge conflicts | ||
*.BASE | ||
*.LOCAL | ||
*.REMOTE | ||
*.orig | ||
|
||
# Each project can have an ignore subdirectory | ||
ignore | ||
|
||
### OSX ### | ||
.DS_Store | ||
.AppleDouble | ||
.LSOverride | ||
|
||
# Icon must end with two \r | ||
Icon | ||
|
||
# Thumbnails | ||
._* | ||
|
||
# Files that might appear in the root of a volume | ||
.DocumentRevisions-V100 | ||
.fseventsd | ||
.Spotlight-V100 | ||
.TemporaryItems | ||
.Trashes | ||
.VolumeIcon.icns | ||
|
||
# Directories potentially created on remote AFP share | ||
.AppleDB | ||
.AppleDesktop | ||
Network Trash Folder | ||
Temporary Items | ||
.apdisk | ||
|
||
*.sublime-project | ||
*.sublime-workspace | ||
|
||
# Require cache for node | ||
.cache-require-paths.json | ||
|
||
# Lcov output from Istanbul | ||
lcov.info | ||
|
||
# eslint cache | ||
.eslint-cache | ||
.eslintcache |
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,34 @@ | ||
{ | ||
"tags": { | ||
"allowUnknownTags": true, | ||
"dictionaries": ["jsdoc","closure"] | ||
}, | ||
"source": { | ||
"include": ["./src"], | ||
"includePattern": ".js$", | ||
"excludePattern": "(node_modules/|docs|pegjs)" | ||
}, | ||
"plugins": [ | ||
"plugins/markdown", | ||
"plugins/summarize" | ||
], | ||
"templates": { | ||
"cleverLinks": false, | ||
"monospaceLinks": true, | ||
"systemName": "remoteFileExplorer", | ||
"linenums": true, | ||
"collapseSymbols": false, | ||
"inverseNav": true | ||
}, | ||
"opts": { | ||
"template": "./node_modules/docdash", | ||
"encoding": "utf8", | ||
"recurse": true, | ||
"destination": "./docs/", | ||
"private": true | ||
}, | ||
"docdash": { | ||
"static": false, // Display the static members inside the navbar | ||
"sort": true // Sort the methods in the navbar | ||
} | ||
} |
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 @@ | ||
8.5.0 |
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,23 @@ | ||
{ | ||
"all": true, | ||
"branches": 80, | ||
"cache": true, | ||
"eager": true, | ||
"check-coverage": false, | ||
"exclude": [ | ||
"src/migrations/*.js" | ||
], | ||
"include": [ | ||
"src/**/*.js" | ||
], | ||
"report-dir": "./coverage", | ||
"reporter": [ | ||
"text-summary" | ||
], | ||
"watermarks": { | ||
"branches": [75, 90], | ||
"functions": [75, 90], | ||
"lines": [75, 90], | ||
"statements": [75, 90] | ||
} | ||
} |
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,52 @@ | ||
# go-for-it | ||
|
||
[](https://circleci.com/gh/gunar/go-for-it) | ||
|
||
Async Control Flow without Exceptions nor Monads. | ||
|
||
Read the blog post | ||
> TODO | ||
|
||
## Installation | ||
``` | ||
npm install go-for-it | ||
``` | ||
|
||
## Example | ||
|
||
```js | ||
const go = require('go-for-it') | ||
|
||
const toUpper = async string => { | ||
if (string === 'invalid') throw Error('Invalid input') | ||
return string.toUpperCase() | ||
} | ||
const errorHandler = () => { console.log('There has been an error. I\'ll handle it.') } | ||
const print = console.log | ||
|
||
const foo = async input => { | ||
const [err, value] = await go(toUpper(input)) | ||
if (err) return errorHandler(err) | ||
print(value) | ||
} | ||
|
||
// Works normally. | ||
foo('gunar') | ||
// "GUNAR" | ||
|
||
// Business Logic Error gets handled by errorHandler(). | ||
foo('invalid') | ||
// "There has been an error. I'll handle it." | ||
|
||
// Runtime Exceptions DO NOT get handled by errorHandler(), | ||
foo(555555).catch(e => { | ||
// but can be caught. | ||
console.log(e) | ||
// TypeError: string.toUpperCase is not a function | ||
}) | ||
``` | ||
|
||
## License | ||
|
||
MIT [http://gunar.mit-license.org]() |
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,26 @@ | ||
dependencies: | ||
override: | ||
- yarn | ||
|
||
machine: | ||
environment: | ||
# For yarn | ||
PATH: "${PATH}:${HOME}/${CIRCLE_PROJECT_REPONAME}/node_modules/.bin" | ||
|
||
LOGGER_LEVEL: silly | ||
NODE_ENV: test | ||
|
||
node: | ||
version: "8.5.0" | ||
|
||
timezone: America/Los_Angeles | ||
|
||
test: | ||
override: | ||
- yarn test | ||
|
||
deployment: | ||
release: | ||
branch: master | ||
commands: | ||
- publish |
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,29 @@ | ||
'use strict' | ||
|
||
const toUpper = async string => { | ||
if (string === 'invalid') return [Error('Invalid input')] | ||
return [null, string.toUpperCase()] | ||
} | ||
const errorHandler = () => { console.log('There has been an error. I\'ll handle it.') } | ||
const print = console.log | ||
|
||
const foo = async input => { | ||
const [err, value] = await toUpper(input) | ||
if (err) return errorHandler(err) | ||
print(value) | ||
} | ||
|
||
// Works normally. | ||
foo('gunar') | ||
// "GUNAR" | ||
|
||
// Business Logic Error gets handled by errorHandler(). | ||
foo('invalid') | ||
// "There has been an error. I'll handle it." | ||
|
||
// Runtime Exceptions DO NOT get handled by errorHandler(), | ||
foo(555555).catch(e => { | ||
// but can be caught. | ||
console.log(e) | ||
// TypeError: string.toUpperCase is not a function | ||
}) |
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,32 @@ | ||
'use strict' | ||
|
||
// await-to-js | ||
const to = promise => | ||
promise | ||
.then(data => [undefined, data]) | ||
.catch(err => [err, undefined]) | ||
|
||
const toUpper = async string => { | ||
if (string === 'invalid') throw Error('Invalid input') | ||
return string.toUpperCase() | ||
} | ||
const errorHandler = () => { console.log('There has been an error. I\'ll handle it.') } | ||
const print = console.log | ||
|
||
const foo = async input => { | ||
const [err, value] = await to(toUpper(input)) | ||
if (err) return errorHandler(err) | ||
print(value) | ||
} | ||
|
||
// Works normally. | ||
foo('gunar') | ||
// "GUNAR" | ||
|
||
// Business Logic Error gets handled by errorHandler(). | ||
foo('invalid') | ||
// "There has been an error. I'll handle it." | ||
|
||
// Runtime Exceptions ALSO get handled by errorHandler(). | ||
foo(555555) | ||
// "There has been an error. I'll handle it." |
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,30 @@ | ||
const toUpper = (string, cb) => { | ||
if (string === 'invalid') return cb(Error('Invalid input')) | ||
return cb(null, string.toUpperCase()) | ||
} | ||
|
||
const errorHandler = () => { | ||
console.log('There has been an error. I\'ll handle it.') | ||
} | ||
|
||
const print = (err, value) => { | ||
if (err) return errorHandler(err) | ||
console.log(value) | ||
} | ||
|
||
// Works normally. | ||
toUpper('gunar', print) | ||
// "GUNAR" | ||
|
||
// Business Logic Error gets handled by errorHandler(). | ||
toUpper('invalid', print) | ||
// "There has been an error. I'll handle it." | ||
|
||
// Runtime Exceptions don't get handled by errorHandler(), | ||
try { | ||
toUpper(555555, print) | ||
} catch (e) { | ||
// but can be caught by try/catch. | ||
console.log(e) | ||
// TypeError: string.toUpperCase is not a function | ||
} |
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,31 @@ | ||
'use strict' | ||
|
||
const go = require('go-for-it') | ||
|
||
const toUpper = async string => { | ||
if (string === 'invalid') throw Error('Invalid input') | ||
return string.toUpperCase() | ||
} | ||
const errorHandler = () => { console.log('There has been an error. I\'ll handle it.') } | ||
const print = console.log | ||
|
||
const foo = async input => { | ||
const [err, value] = await go(toUpper(input)) | ||
if (err) return errorHandler(err) | ||
print(value) | ||
} | ||
|
||
// Works normally. | ||
foo('gunar') | ||
// "GUNAR" | ||
|
||
// Business Logic Error gets handled by errorHandler(). | ||
foo('invalid') | ||
// "There has been an error. I'll handle it." | ||
|
||
// Runtime Exceptions DO NOT get handled by errorHandler(), | ||
foo(555555).catch(e => { | ||
// but can be caught. | ||
console.log(e) | ||
// TypeError: string.toUpperCase is not a function | ||
}) |
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,26 @@ | ||
const toUpper = async string => { | ||
if (string === 'invalid') { | ||
// there are multiple ways to do this instead of Promise.reject() | ||
return Promise.reject(Error('Invalid input')) | ||
} | ||
// Redundant Promise.resolve() because async functions always return Promises | ||
return Promise.resolve(string.toUpperCase()) | ||
} | ||
|
||
const errorHandler = () => { | ||
console.log('There has been an error. I\'ll handle it.') | ||
} | ||
|
||
const print = console.log | ||
|
||
// Works normally. | ||
toUpper('gunar').then(print, errorHandler) | ||
// "GUNAR" | ||
|
||
// Business Logic Error gets handled by errorHandler(). | ||
toUpper('invalid').then(print, errorHandler) | ||
// "There has been an error. I'll handle it." | ||
|
||
// Runtime Exceptions ALSO get handled by errorHandler(). | ||
toUpper(555555).then(print, errorHandler) | ||
// "There has been an error. I'll handle it." |
Oops, something went wrong.