summary refs log tree commit diff
path: root/src/api/util/utility/String.ts
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-08-22 22:16:11 +1000
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-08-22 22:16:11 +1000
commit8720744091e71efe0b2e5f88956e1e0a2e9ef702 (patch)
treef00521f59f3c2ece7e790f2d0b8469c051586a92 /src/api/util/utility/String.ts
parentActually respect with_mutual_guilds (diff)
parentMerge remote-tracking branch 'Puyodead1/patch/prettier-config' into staging (diff)
downloadserver-ts-8720744091e71efe0b2e5f88956e1e0a2e9ef702.tar.xz
Merge remote-tracking branch 'upstream/staging' into fix/sendMemberInProfile
Diffstat (limited to 'src/api/util/utility/String.ts')
-rw-r--r--src/api/util/utility/String.ts18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/api/util/utility/String.ts b/src/api/util/utility/String.ts
new file mode 100644

index 00000000..982b7e11 --- /dev/null +++ b/src/api/util/utility/String.ts
@@ -0,0 +1,18 @@ +import { Request } from "express"; +import { ntob } from "./Base64"; +import { FieldErrors } from "@fosscord/util"; + +export function checkLength(str: string, min: number, max: number, key: string, req: Request) { + if (str.length < min || str.length > max) { + throw FieldErrors({ + [key]: { + code: "BASE_TYPE_BAD_LENGTH", + message: req.t("common:field.BASE_TYPE_BAD_LENGTH", { length: `${min} - ${max}` }) + } + }); + } +} + +export function generateCode() { + return ntob(Date.now() + Math.randomIntBetween(0, 10000)); +}