cap(str: string, length: number, ellipsis: boolean): string
Parameters
str (string) The string to cap
length (number) How many characters to cap the string at
ellipsis (boolean = true) Whether or not to add an ellipsis to the end of the string
Returns
string: Capped string if the string is longer than the length
Example
import { cap } from "william.js";

cap("Hello, world!", 5, true);
//=> "Hello..."

cap("Hello, world!", 5, false);
//=> "Hello"
gravatar(email: string): string
Parameters
email (string) The email address to get the Gravatar of
Returns
string: Gravatar URL
Example
import { gravatar } from "william.js";

gravatar("hello@example.com");
//=> "https://gravatar.com/avatar/cb8419c1d471d55fbca0d63d1fb2b6ac"
id(length: number, amount: number, alphabet: string): (string | Array<string>)
Parameters
length (number = 32) The length of the ID
amount (number = 1) The amount of IDs to generate
alphabet (string = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") The alphabet to use
Returns
(string | Array<string>): A single ID or an array of IDs
Example
import { id } from "william.js";

id();
//=> "w9Jjy2L0R8Jg0W0X7t0w9H5Q2Y9V1E0C"

id(5);
//=> "w9Jjy"

id(5, 5);
//=> [
//=>   "w9Jjy",
//=>   "u5V5J",
//=>   "Q9T8l",
//=>   "B6T7Y",
//=>   "S4K4P"
//=> ]

id(5, 5, "abc");
//=> [
//=>   "bbaac",
//=>   "cbcca",
//=>   "abccb",
//=>   "cbcca",
//=>   "acbab"
//=> ]
random(min: number, max: number): number
Parameters
min (number) The minimum number to generate
max (number) The maximum number to generate
Returns
number: A random number between the min and max
Example
import { random } from "william.js";

random(1, 10);
//=> 5
getDirs(path: string): Promise<Array<string>>
Parameters
path (string) The path to find directories in
Returns
Promise<Array<string>>: An array of all the directories in the path
Example
import { util } from "william.js";

await util.getDirs("./src");
//=> ["functions", "util"]
md5Hex(data: (Uint8Array | string | ReadonlyArray<(Uint8Array | string)>)): string
Parameters
data ((Uint8Array | string | ReadonlyArray<(Uint8Array | string)>)) The data to hash
Returns
string: An MD5 hash of the input data
Example
import fs from "node:fs";
import { util } from "william.js";

const buffer = fs.readFileSync("unicorn.png");

util.md5Hex(buffer);
//=> "1abcb33beeb811dca15f0ac3e47b88d9"
removeDuplicates(arr: Array): Array
Parameters
arr (Array) The array to remove duplicates from
Returns
Array: The array without duplicates
Example
import { util } from "william.js";

util.removeDuplicates([1, 2, 3, 3, 4, 5, 5, 5, 6]);
//=> [1, 2, 3, 4, 5, 6]
uuid(amount: number): (string | Array<string>)
Parameters
amount (number = 1) The amount of UUIDs to generate
Returns
(string | Array<string>): A single UUID or an array of UUIDs
Example
import { uuid } from "william.js";

uuid();
//=> "80e65ae3-d006-42d6-96c8-0de8238f6e35"

uuid(5);
//=> [
//=>   "80e65ae3-d006-42d6-96c8-0de8238f6e35",
//=>   "0ffa8194-20c9-47e5-ad0f-1e29a196a021",
//=>   "9d60756e-30a3-4c68-af16-c5733a4221af",
//=>   "cd7acdca-ab33-445b-bf83-e59959b8ebb7",
//=>   "efbf566f-b4d1-4df7-8a74-0cd8b7ef2bca"
//=> ]
webhook(url: string): boolean
Parameters
url (string) The webhook URL to test
Returns
boolean: Whether the webhook URL passed the regex test
Example
import { validate } from "william.js";

validate.discord.webhook("https://discord.com/api/webhooks/1234567890/abcdefghijklmnopqrstuvwxyz");
//=> true

validate.discord.webhook("https://discord.com/api/webhooks/invalid/webhook");
//=> false
email(email: string): boolean
Parameters
email (string) The email address to test
Returns
boolean: Whether the email address passed the regex test
Example
import { validate } from "william.js";

validate.email("hello@example.com")
//=> true

validate.email("hello world")
//=> false