Files
discordeno/plugins/bot/util/validateLength.ts
Skillz4Killz ffe7cdbc6f feat: base plugin lib idea (#2308)
* feat: base plugin lib idea

* fix: stuff

* fmt

* fix: imports and exports

* fix: errors & tests

* fix: remove logs
2022-06-18 18:46:37 -04:00

12 lines
483 B
TypeScript

/** Validates the length of a string in JS. Certain characters in JS can have multiple numbers in length in unicode and discords api is in python which treats length differently. */
export function validateLength(text: string, options: { max?: number; min?: number }) {
const length = [...text].length;
// Text is too long
if (options.max && length > options.max) return false;
// Text is too short
if (options.min && length < options.min) return false;
return true;
}