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);
cap("Hello, world!", 5, false);
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");
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();
id(5);
id(5, 5);
id(5, 5, "abc");
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);
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");
Parameters
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);
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]);
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();
uuid(5);
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");
validate.discord.webhook("https://discord.com/api/webhooks/invalid/webhook");
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")
validate.email("hello world")