mirror of
https://github.com/sern-handler/handler
synced 2026-06-06 01:16:55 +00:00
added arg preprocessors
This commit is contained in:
23
src/handler/utils/preprocessors/args.ts
Normal file
23
src/handler/utils/preprocessors/args.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { Err, Ok, Result } from "ts-results";
|
||||
import type { possibleOutput } from "../../../types/handler/handler";
|
||||
|
||||
|
||||
export namespace Utils {
|
||||
/**
|
||||
* Wrapper type taking `Ok(T)` or `Err(possibleOutput)` e.g `Result<T, possibleOutput`
|
||||
*/
|
||||
type ArgType<T> = Result<T, possibleOutput>
|
||||
/**
|
||||
*
|
||||
* @param {string} arg
|
||||
* @param {possibleOutput} onFailure
|
||||
* @returns {ArgType<number>} Attempts to use Number.parseInt() on `arg`
|
||||
*/
|
||||
export function parseInt(arg: string, onFailure: possibleOutput): ArgType<number> {
|
||||
const val = Number.parseInt(arg);
|
||||
return val === NaN ? Err(onFailure) : Ok(val);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Sern } from "./handler/sern/sern";
|
||||
|
||||
|
||||
module.exports = Sern;
|
||||
export default Sern;
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { Ok, Result } from 'ts-results';
|
||||
import type { Awaitable, Client, Message, MessagePayload} from 'discord.js';
|
||||
import type { MessageOptions } from 'child_process';
|
||||
import type Sern from '../..';
|
||||
import type { Sern } from '../../handler/sern/sern';
|
||||
|
||||
export type Visibility = "private" | "public"
|
||||
export type possibleOutput = string | MessagePayload & MessageOptions
|
||||
|
||||
Reference in New Issue
Block a user