@alessiofrittoli/web-utils
Version:
Common TypeScript web utilities
149 lines (147 loc) • 4.72 kB
text/typescript
/**
* Make first letter uppercase.
*
* @param input The input string to convert.
* @returns The processed string.
*/
declare const ucFirst: (input: string) => string;
/**
* Make first letter lowercase.
*
* @param input The input string to convert.
* @returns The processed string.
*/
declare const lcFirst: (input: string) => string;
/**
* Convert string to camelCase.
*
* @param input The input string to convert.
* @returns The converted string to camelCase.
*/
declare const toCamelCase: (input: string) => string;
/**
* Convert string to kebab-case string.
*
* @param input The input string to convert.
* @returns The converted string to kebab-case.
*/
declare const toKebabCase: (input: string) => string;
/**
* Stringify value.
*
* @param input The value to stringify.
* @returns The stringified `input`.
*/
declare const stringifyValue: (input?: any) => string;
/**
* Parse stringified value.
*
* @param input The value to parse.
* @returns The parsed `input`.
*/
declare const parseValue: <T>(input?: string) => T | undefined;
/**
* Add leading character to a string.
*
* The given `input` won't be modified if it already contains the given `character`.
*
* @param input The string to process.
* @param character The character to add.
* @param search ( Optional ) A custom search expression. Default `character`.
*
* @returns The given string with leading character.
*/
declare const addLeadingCharacter: (input: string, character: string, search?: string | RegExp) => string;
/**
* Remove leading character from a string.
*
* @param input The string to process.
* @param character The character to remove.
*
* @returns The given string with leading character removed.
*/
declare const removeLeadingCharacter: (input: string, character: string | RegExp) => string;
/**
* Add trailing character to a string.
*
* The given `input` won't be modified if it already contains the given `character`.
*
* @param input The string to process.
* @param character The character to add.
* @param search ( Optional ) A custom search expression. Default `character`.
*
* @returns The given string with trailing character.
*/
declare const addTrailingCharacter: (input: string, character: string, search?: string | RegExp) => string;
/**
* Remove trailing character from a string.
*
* @param input The string to process.
* @param character The character to remove.
*
* @returns The given string with trailing character removed.
*/
declare const removeTrailingCharacter: (input: string, character: string | RegExp) => string;
type Recipient = string | {
/**
* The recipient name.
*
*/
name?: string;
/**
* The recipient email address.
*
*/
email: string;
};
type Recipients = Recipient | Recipient[];
/**
* Converts a single recipient or an array of recipients into a comma-separated string.
*
* Each recipient can be either a string (email address) or an object with at least an `email` property,
* and optionally a `name` property. If the recipient is an object and has a `name`, the output will be
* formatted as `"Name<email>"`. If the `name` is missing, only the email will be used.
*
* @param recipients A single `Recipient` or an array of `Recipient`. Each recipient can be a string or an object with `email` and optional `name`.
* @returns A comma-separated string of recipients formatted as `"Name<email>"` or just `"email"`.
*/
declare const recipientsToString: (recipients: Recipients) => string;
interface EmailData {
/**
* The email recipients.
*
*/
to?: Recipients;
/**
* The email carbon copy recipients.
*
*/
cc?: Recipients;
/**
* The email blind carbon copy recipients.
*
*/
bcc?: Recipients;
/**
* The email subject.
*
*/
subject?: string;
/**
* The email body.
*
*/
body?: string;
}
/**
* Converts an `EmailData` object into a properly formatted mailto URL string.
*
* This function constructs a mailto link using the provided email data, including
* recipients, subject, body, CC, and BCC fields. It encodes the parameters as URL
* search parameters and concatenates them to form a valid mailto URI.
*
* @param data The email data to convert. If omitted, defaults to an empty object.
* @returns A string representing the mailto URL.
*/
declare const emailDataToString: (data?: EmailData) => string;
export { type EmailData, type Recipient, type Recipients, addLeadingCharacter, addTrailingCharacter, emailDataToString, lcFirst, parseValue, recipientsToString, removeLeadingCharacter, removeTrailingCharacter, stringifyValue, toCamelCase, toKebabCase, ucFirst };