1.2.25 • Published 3 years ago
@dustinrouillard/fastify-utilities v1.2.25
Dustin's Utilities Module
Documentation for utilities
Validation
Validation Options
Name | Purpose | Type | Default |
---|---|---|---|
strict | Requires the object to contain only items that constraints exist for | boolean | false |
required | Requires the object to contain at least the items in the array | string[] | [] |
Validation Constraints
Name | Purpose | Type | Default |
---|---|---|---|
email | Requires the specified value pass the email specfic regex | 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 |
allowed | List of strings or numbers that are allowed | (string \| number)[] | null |
casing | Desired casing to validate the item for | string (any, upper, lower) | null |
type | If specified a type the typeof will be compared | string | null |
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="dstn:*" which will allow the output of this log line |
Changing/disabling colors
Included is a function to change the configuation of the logger, such as the colors or to disable them altogether.
The configurable options are
Name | Default |
---|---|
timestampColor | gray |
logColor | green |
errorColor | redBright |
debugColor | blueBright |
disableColors | false |
debugAnnotation | dstn |
Request logging
• Request Method \
• Request Path \
• Status Code \
• Response Time in ms
\
• Client IP Address \
• Response Size B/KB/MB/GB
Request Responses
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 |
1.2.23
3 years ago
1.2.24
3 years ago
1.2.22
3 years ago
1.2.25
3 years ago
1.2.19
3 years ago
1.2.20
3 years ago
1.2.21
3 years ago
1.2.18
3 years ago
1.2.12
3 years ago
1.2.13
3 years ago
1.2.10
3 years ago
1.2.11
3 years ago
1.2.16
3 years ago
1.2.17
3 years ago
1.2.14
3 years ago
1.2.15
3 years ago
1.2.8
3 years ago
1.2.9
3 years ago
1.2.7
3 years ago
1.2.6
3 years ago
1.2.0
4 years ago
1.2.1
4 years ago
1.0.9
4 years ago
1.0.8
4 years ago
1.0.7
4 years ago
1.0.6
4 years ago
1.0.5
4 years ago
1.0.4
4 years ago