Skip to content

Commit 2daeb54

Browse files
authored
feat: v0.0.2 update package - all (#15)
1 parent b31e12d commit 2daeb54

File tree

12 files changed

+265
-408
lines changed

12 files changed

+265
-408
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -129,5 +129,6 @@ dist
129129
.yarn/install-state.gz
130130
.pnp.*
131131

132-
# pnpm dependencies
132+
# dependencies
133133
pnpm-lock.yaml
134+
package-lock.json

.husky/pre-commit

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
pnpm lint && pnpm format && pnpm exec lint-staged
1+
npm run prepublish

README.md

+27-38
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Description
44

5-
A package to handle errors as a result and not throw errors
5+
A package to handle results. Success, errors or partial success as results and not throw errors
66

77
## Installation
88

@@ -19,48 +19,57 @@ pnpm install @dancastillo/nothrow
1919

2020
## Usage
2121

22+
#### TypeScript
23+
2224
```typescript
23-
import { Result } from '@dancastillo/nothrow'
25+
import {
26+
type Result,
27+
createSuccessfulResult,
28+
createFailureResult,
29+
createPartialSuccessfulResult,
30+
} from '@dancastillo/nothrow'
2431
```
2532

26-
## API Documentation
33+
## Method Documentation
2734

28-
### `successful`
35+
### `createSuccessfulResult`
2936

3037
Constructs a successful result with no errors
3138

3239
```typescript
33-
const result = Result.successful({ success: true })
40+
const result = createSuccessfulResult({ success: true })
3441
// result.data = { success: true }
35-
// result.errors = undefined
42+
// result.errors = []
3643
```
3744

38-
### `failure`
45+
### `createFailureResult`
3946

40-
Constructs a failed result with no data
47+
Constructs a failure result with no data
4148

4249
```typescript
43-
const result = Result.failure({ success: false })
44-
// result.data = undefined
45-
// result.errors = { success: false }
50+
const result = createFailureResult([{ error: true }])
51+
// result.data = null
52+
// result.errors = [{ success: false }]
4653
```
4754

48-
### `partialSuccess`
55+
### `createPartialSuccessResult`
4956

5057
Constructs a result with data and errors
5158

5259
```typescript
53-
const result = Result.partialSuccess({ success: true }, [{ error: 'Missing input' }, { error: 'Not found' }])
60+
const result = createPartialSuccessReuslt({ success: true }, [{ error: 'Missing input' }, { error: 'Not found' }])
5461
// result.data ={ success: true }
5562
// result.errors = [{ error: 'Missing input' }, { error: 'Not found' }]
5663
```
5764

58-
### `map`
65+
## API Documentation
66+
67+
### `mapTo`
5968

6069
Map the data result and errors result to the wanted type. This method takes in two functions as its arguments
6170

6271
```typescript
63-
const mappedResult = result.map(
72+
const mappedResult = result.mapTo(
6473
(data: DataType) => {
6574
return <MappedDataType>{ id: data.id }
6675
},
@@ -96,35 +105,15 @@ const mappedResult = result.mapErrors((errors: ErrorType) => {
96105

97106
### `isSuccessful`
98107

99-
Returns `TRUE` if the result was successful and no errors
108+
Returns `boolean`
100109

101110
### `isFailure`
102111

103-
Returns `TRUE` if the result was N error reults and no data
112+
Returns `boolean`
104113

105114
### `isPartialSuccess`
106115

107-
Returns `FALSE` if the result returned both a data result and error result
108-
109-
### `hasData`
110-
111-
Helper method to determine if the `Result` has data value set
112-
113-
### `getData`
114-
115-
Helper method to retrieve the `Result` data value set
116-
117-
### `hasErrors`
118-
119-
Helper method to determine if the `Result` has error values set
120-
121-
### `getErrors`
122-
123-
Helper method to retrieve the `Result` error values set
124-
125-
### `errorCount`
126-
127-
Helper method to retrieve the `Result` error values count
116+
Returns `boolean`
128117

129118
### License
130119

package.json

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
{
22
"name": "@dancastillo/nothrow",
3-
"version": "0.0.1",
4-
"description": "A package to handle errors as a result",
3+
"version": "0.0.2",
4+
"description": "A package to handle results. Success, errors or partial success as results and not throw errors",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
7+
"type": "module",
78
"exports": {
89
"./package.json": "./package.json",
910
".": {
10-
"import": "./dist/index.mjs",
11-
"require": "./dist/index.js"
11+
"import": "./dist/index.js",
12+
"require": "./dist/index.cjs"
1213
}
1314
},
1415
"homepage": "https://github.com/dancastillo/nothrow",
@@ -25,23 +26,22 @@
2526
"dist"
2627
],
2728
"keywords": [
28-
"error",
2929
"nothrow",
3030
"result",
31-
"throw"
31+
"error",
32+
"result",
33+
"partialSuccess"
3234
],
3335
"scripts": {
34-
"test": "tsc --project tsconfig.test.json && borp --coverage",
35-
"format": "prettier --check .",
36-
"format:fix": "prettier --write .",
36+
"test": "rm -rf dist && tsc --project tsconfig.test.json && borp --coverage",
37+
"format:check": "prettier --check .",
38+
"format": "prettier --write .",
3739
"lint": "eslint ./src",
3840
"prepare": "husky",
39-
"build": "tsup",
40-
"check-exports": "attw --pack .",
41-
"prepublish": "pnpm build && pnpm check-exports && pnpm lint && pnpm format && pnpm test"
41+
"build": "rm -rf dist && tsup",
42+
"prepublish": "pnpm lint && pnpm format:check && pnpm test && pnpm build"
4243
},
4344
"devDependencies": {
44-
"@arethetypeswrong/cli": "^0.17.0",
4545
"@changesets/cli": "^2.27.7",
4646
"@eslint/js": "^9.9.1",
4747
"@types/node": "^22.5.0",

src/error/error-result.ts

-17
This file was deleted.

src/error/helper/index.ts

-43
This file was deleted.

src/error/types/types.ts

-44
This file was deleted.

src/index.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
/**
22
* Result Class object
33
*/
4-
export { Result } from './result'
5-
6-
/**
7-
* Type
8-
*/
9-
export type { Undefinable } from './types'
4+
export { type Result, createSuccessfulResult, createFailureResult, createPartialSuccessfulResult } from './result.js'

0 commit comments

Comments
 (0)