https://github.com/synonymdev/result
Result helper class
https://github.com/synonymdev/result
Last synced: about 1 year ago
JSON representation
Result helper class
- Host: GitHub
- URL: https://github.com/synonymdev/result
- Owner: synonymdev
- License: mit
- Created: 2022-08-02T16:28:28.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-07-27T10:02:32.000Z (over 2 years ago)
- Last Synced: 2025-03-15T02:24:31.129Z (about 1 year ago)
- Language: TypeScript
- Size: 63.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Result helper class
### Description
Result helper class
## Getting started
```bash
yarn add @synonymdev/result
#or
npm i -s @synonymdev/result
````
## Usage
```javascript
import { ok, err } from '@synonymdev/result';
```
```typescript
const func = (): Result => {
return ok(42);
// OR
return err('error message');
// OR
return err(new Error('error message'));
}
const result = func();
if (result.isOk()) {
console.log(result.value); //42
}
if (result.isErr()) {
console.error(result.error.message); // "error message"
}
```
## Development
### `yarn build`
Builds library ready for production use.
### `yarn test`
Unit tests.
### `yarn format`
Code formatting.
### `yarn lint`
Code linting.
### `yarn prepublish`
Prepares code for publishing by building and bumping package version.