Skip to content

Commit

Permalink
🐛 Fix(enviroment): change install command in readme
Browse files Browse the repository at this point in the history
  • Loading branch information
INeedJobToStartWork committed Feb 11, 2024
1 parent 526576c commit 9b47036
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 31 deletions.
8 changes: 8 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works with
multi-package repos, or single-package repos to help you version and publish your code. You can find the full
documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
11 changes: 11 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "restricted",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
}
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# oh-my-error

## 0.1.1

### Patch Changes

- update README.md

## 0.1.0 (2021-10-14)

### Minor Changes

- Add Feat: functions `myErrorWrapper`,`myErrorCatcher`,`myErrorHandler` and types
`TMyError`,`TMyErrorList`,`TMyHandler`,`TMyFunctionReturn`,`TErrorReturn`,`TDataReturn`
93 changes: 64 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
![image](https://github.com/INeedJobToStartWork/MyError/assets/97305201/03fa3e50-af28-4345-a3f7-f84d091b4eb1)

<h1 align="center">MyError</h1>
<p align="center"><b>Very Clean Error Handler!</b></p>

Expand All @@ -16,32 +17,33 @@
- [MyErrorList](#init-config)
- [MyErrorHandlerList](#init-config)
- [Sample of Code](#sample-of-code)


## Install

NPM

```bash copy
npm install myerror
npm install oh-my-error
```

PNPM

```bash copy
pnpm add myerror
pnpm add oh-my-error
```

Yarn

```bash copy
yarn add myerror
yarn add oh-my-error
```

## Types

### TMyError<T>

Error construction with optional own parameters.

```
type TMyError<T = NonNullable<unknown>> = T & {
code?: number | string;
Expand All @@ -57,13 +59,15 @@ type TMyError<T = NonNullable<unknown>> = T & {
```

### TMyErrorList

Object with TMyError structure

```
export type TMyErrorList<CustomError = NonNullable<unknown>> = Record<string, Required<TMyError<CustomError>>>;
```

### TMyHandler

Object with handlers of errors

```
Expand All @@ -74,67 +78,90 @@ export type TMyHandler<
```

### TMyFunctionReturn
Function return standard.

Function return standard.

```
export type TFunctionReturn<T> = Prettify<TDataReturn<T>> | Prettify<TErrorReturn>;
```

### TErrorReturn

Function Error return standard

```
export type TErrorReturn<CustomError = NonNullable<unknown>> = [TMyError<CustomError>, true]
```

### TDataReturn -

Function Data return standard

```
export type TDataReturn<T> = [T, false];
```

## Functions

### myErrorWrapper

Error Wrapper which works on trycatch return result in array

#### Arguments

Function is receiving 2 arguments.

```
<T extends arrowFunction<T>>(fnThatMayThrow: T) => (...args: Parameters<T>)
```
`fnThatMayThrow` - **Function** which we want to run. <br/>
`args` - Arguments which `fnThatMayThrow` should receive.

`fnThatMayThrow` - **Function** which we want to run. <br/> `args` - Arguments which `fnThatMayThrow` should receive.

#### Return

```
type MyErrorWrapperReturn<T extends arrowFunction<T>> = [ErrorTypesCatched, true] | [ReturnType<T>, false]
```

<br/>

`[ error throwed trycatch , true - status of error ]` <br/>
**or** <br/>
`[ error throwed trycatch , true - status of error ]` <br/> **or** <br/>
`[ fnThatMayThrow(...args) returntype/result , false - status of error ]`

#### Example

Wrapping currently existing function <br/>

```
const [data,error] = myErrorWrapper(readFileSync)("./PathToFile.txt")
```


### myErrorCatcher

Error Catcher work on Promises

#### Arguments

Function is receiving 2 arguments.

```
<T extends arrowFunction<T>>(fnThatMayThrow: T) => async (...args: Parameters<T>)
```
`fnThatMayThrow` - **Function** which we want to run. <br/>
`args` - Arguments which `fnThatMayThrow` should receive.

`fnThatMayThrow` - **Function** which we want to run. <br/> `args` - Arguments which `fnThatMayThrow` should receive.

#### Return

```
Promise<Prettify<ReturnType<T>>>
```

Return promise for `fnThatMayThrow` return type.

#### Example

Wrapping currently existing function.

```
const data = myErrorCatcher(readFileSync)("./PathToFile.txt").catch(()=>{
console.log("Can't load file.")
Expand All @@ -143,40 +170,50 @@ const data = myErrorCatcher(readFileSync)("./PathToFile.txt").catch(()=>{
```

### myErrorHandler

Function which handle error of your function.

#### Arguments

```
<T extends keyof K, K extends Record<T, K[T]>>(errorName: T, errorSolutions: K) =>
(...args: Parameters<K[T]>)
```
`errorCode` - `Key` in `Object` of `errorSolutions`.<br/>
`errorSolutions` - Object which Storage solutions for problem `errorCode`.<br/>

`errorCode` - `Key` in `Object` of `errorSolutions`.<br/> `errorSolutions` - Object which Storage solutions for problem
`errorCode`.<br/>

#### Return

```
Prettify<TFunctionReturn<ReturnType<K[T]>>>
```
`[ TMyError , true - status of error ]` <br/>
**or** <br/>

`[ TMyError , true - status of error ]` <br/> **or** <br/>
`[ errorSolutions[errorCode](...args) returntype/result , false - status of error ]`

#### Errors

##### EH001
errorName (key) not found in errorSolutions (object)<br/>
Check if errorName is in errorSolutions<br/>

errorName (key) not found in errorSolutions (object)<br/> Check if errorName is in errorSolutions<br/>

##### EH002
Error in execution of Solution <br/>
Check if the function `errorSolutions[errorName]()` is working properly

Error in execution of Solution <br/> Check if the function `errorSolutions[errorName]()` is working properly

## Objects

### MyErrorList

List of Errors which your function can return.

> [!IMPORTANT]
> Use `as const satisfies TMyErrorList` to work it properly. <br/>
> **Don't** forget about `const` because without this you not gonna get tips.
> Use `as const satisfies TMyErrorList` to work it properly. <br/> > **Don't** forget about `const` because without this
> you not gonna get tips.
#### Example

```
const ErrorList = {
notFound: {
Expand All @@ -196,13 +233,15 @@ const ErrorList = {
```

### TMyHandler

List of Errors handlers which your function can run.

> [!IMPORTANT]
> Use `as const satisfies TMyHandler<NonNullable<unknown>, typeof ErrorList>` to work it properly. <br/>
> **Don't** forget about `const` because without this you not gonna get tips.
> Use `as const satisfies TMyHandler<NonNullable<unknown>, typeof ErrorList>` to work it properly. <br/> > **Don't**
> forget about `const` because without this you not gonna get tips.
#### Example

```
export const readFileHandler = {
FS001: (name: string) => {
Expand All @@ -216,8 +255,8 @@ export const readFileHandler = {
} as const satisfies TMyHandler<NonNullable<unknown>, typeof ErrorList>;
```


## Sample of Code

[File with Example](https://github.com/INeedJobToStartWork/MyError/blob/main/src/tests/componentConcept/readFile.ts)

```
Expand Down Expand Up @@ -261,7 +300,3 @@ export const readFile = (path: string): TFunctionReturn<string> => {
return [result.toString(), false];
};
```




5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "@ineedj/myerror",
"version": "0.1.0",
"name": "oh-my-error",
"version": "0.1.1",
"description": "A simple error handler for nodejs",
"repository": {
"type": "git",
"url": "https://github.com/INeedJobToStartWork/MyError"
Expand Down

0 comments on commit 9b47036

Please sign in to comment.