npm package: @jackdouglas/ts-utilities
Description: Jack's Utilities & Functions
Author: Jack Douglas
Latest version: 1.0.8
Deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

# Jack's Utility Module

Mostly Notify Code

---

## Documentation for utilities

#### Validation Options

| Name          | Purpose                                                             | Type       | Default |
| ------------- | ------------------------------------------------------------------- | ---------- | ------- |
| `exact`       | Requires the object to match exactly to the contraint keys provided | `boolean`  | `false` |
| `required`    | Requires the object to contain at least the items in the array      | `string[]` | `null`  |
| `whitelisted` | Requires the object to contain only items that are in the array     | `string[]` | `null`  |

#### Validation Constraints

| Name        | Purpose                                                   | Type                             | Default |
| ----------- | --------------------------------------------------------- | -------------------------------- | ------- |
| `email`     | Requires the specified value pass the email specfic regex | `boolean`                        | `false` |
| `lowercase` | Requires the value to be lowercase only                   | `boolean`                        | `false` |
| `uppercase` | Requires the value to be uppercase only                   | `boolean`                        | `false` |
| `number`    | Requires the value to be number only                      | `boolean`                        | `false` |
| `length`    | Requires the value to meet the min or max length          | `{ min?: number, max?: number }` | `null`  |
| `nullable`  | Specifies if the value is allow to be unset or null       | `boolean`                        | `true`  |
| `trim`      | Removes whitespace from the string                        | `boolean`                        | `true`  |

---

### Logging

#### Traditional logging

Also bundled is a logging utility

This logging utility exposes the following methods

| Name    | Purpose                                                                                                                                              |
| ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Log`   | `console.log` but with the twist of color,time and other logger benefits                                                                             |
| `Error` | `console.error` same as log with different colors, and registers as an error on our error tracking                                                   |
| `Debug` | `console.log` nearly the same as `Log` but with the twist of an env variable check for `DEBUG="jack:*"` which will allow the output of this log line |

#### Request logging

Included is an express middleware to handle logging of request details

##### Things that get logged when a request is received

• Request Method \
• Request Path \
• Status Code \
• Response Time in `ms` \
• Client IP Address \
• ~~Response Size `B/KB/MB/GB`~~ _soon_

### Request Responses

This request utility exposes the following methods

| Name      | Response Format                            | Parameters                                                |     |
| --------- | ------------------------------------------ | --------------------------------------------------------- | --- |
| `Success` | `{ success: true, data }`                  | `res: Response, status: number, data?: any`               |     |
| `Failed`  | `{ error: true, code, data }`              | `res: Response, status: number, code: string, data?: any` |     |
| `Missing` | `{ error: true, code: 'route_not_found' }` | `res: Response`                                           |     |
| `Catch`   | `{ error: true, code: 'catch', data }`     | `res: Response, data?: any`                               |     |