Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kkristof200/ts-successerrorcallbacks
https://github.com/kkristof200/ts-successerrorcallbacks
Last synced: 11 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/kkristof200/ts-successerrorcallbacks
- Owner: kkristof200
- License: mit
- Created: 2020-09-27T14:37:13.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2020-09-27T14:49:28.000Z (about 4 years ago)
- Last Synced: 2024-10-07T07:50:53.591Z (about 1 month ago)
- Language: TypeScript
- Size: 1.95 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# successerror
simplified optional success/error callbacks
## Install
```bash
npm i successerror
```## Usage
```typescript
import fs from 'fs'
import { SuccessErrorCallback, Solver } from './successErrorCallbacks';// With these callbacks, functions like this can be created with optional callbacks
function remove(path: string, ...callbacks: SuccessErrorCallback[]) {
fs.unlink(path, Solver.with(callbacks).solve)
}// So the functions can be called like this
const dummyPath = 'dummyPath'
// Order doesn't matter
remove(dummyPath,
(() => { console.log('success') }), // successCallback
(err => console.log(err)) // errorCallback
)
remove(dummyPath,
(err => console.log(err)), // errorCallback
(() => { console.log('success') }) // successCallback
)// Use only success or only error callback
remove(dummyPath, (err => console.log(err))) // only errorCallback
remove(dummyPath, (() => { console.log('success') })) // only successCallback// Use no callback
remove(dummyPath) // no callback
```