Refactor for using koa and dicebear

This commit is contained in:
Juan Sebastián Montoya 2024-09-26 01:13:22 -05:00
parent 41f480e2a6
commit 1840e5a786
17 changed files with 976 additions and 1129 deletions

20
src/utils/server.ts Normal file
View file

@ -0,0 +1,20 @@
import { NetworkInterfaceInfo, networkInterfaces } from "os";
export const startServerLog = (port: number) => async () => {
const net = Object.values(networkInterfaces())
.flat()
.filter((v) => v?.family === "IPv4")
.sort((v) => (v!.internal ? -1 : 1)) as Array<NetworkInterfaceInfo>;
console.info("Server started successfully!");
console.info("You can now use the service.");
net.forEach(({ internal, address }) =>
console.info(
`\t${(internal ? "Local:" : "On Your Network:").padEnd(
20,
" "
)}http://${address}:${port}`
)
);
};

18
src/utils/type-guards.ts Normal file
View file

@ -0,0 +1,18 @@
import { ValidationError } from "joi";
export const isValidationError = (error: unknown): error is ValidationError =>
error instanceof ValidationError;
export const isValue = <T>(value: T | Array<T> | undefined): value is T =>
!!value && !Array.isArray(value);
export const isSize = (value: unknown): value is string =>
!Array.isArray(value) &&
!isNaN(parseInt(value as string)) &&
parseInt(value as string) <= 512 &&
parseInt(value as string) >= 16;
export const isStyle =
(validStyles: string[]) =>
<T>(value: T | Array<T> | undefined): value is T =>
!!value && !Array.isArray(value) && validStyles.includes(value as string);