tiny-essentials
Version:
Collection of small, essential scripts designed to be used across various projects. These simple utilities are crafted for speed, ease of use, and versatility.
51 lines • 2.68 kB
text/typescript
/**
* Converts a string to title case where the first letter of each word is capitalized.
* All other letters are converted to lowercase.
*
* Example: "hello world" -> "Hello World"
*
* @param {string} str - The string to be converted to title case.
* @returns {string} The string converted to title case.
*/
export function toTitleCase(str: string): string;
/**
* Converts a string to title case where the first letter of each word is capitalized,
* but the first letter of the entire string is left lowercase.
*
* Example: "hello world" -> "hello World"
*
* @param {string} str - The string to be converted to title case with the first letter in lowercase.
* @returns {string} The string converted to title case with the first letter in lowercase.
*/
export function toTitleCaseLowerFirst(str: string): string;
/**
* Enables a keyboard shortcut to toggle a CSS class on the document body.
*
* This function listens for a specific key combination: `Ctrl + Alt + [key]`.
* When triggered, it prevents the default behavior and toggles the
* `detect-made-by-ai` class on the `<body>`, which can be used to apply visual
* indicators or filters on AI-generated content.
*
* If executed outside of a browser environment (e.g., in Node.js), the function logs an error and exits.
* If the `<body>` is not available at the moment the shortcut is triggered, a warning is logged.
*
* @param {string} [key='a'] - The lowercase character key to be used in combination with Ctrl and Alt.
*/
export function addAiMarkerShortcut(key?: string): void;
/**
* Trims a text string to a specified character limit, attempting to avoid cutting words in half.
* If a space is found before the limit and it's not too far from the limit (at least 60%),
* the cut is made at that space; otherwise, the text is hard-cut at the limit.
* If the input is shorter than the limit, it is returned unchanged.
*
* @param {string} text - The input text to be trimmed.
* @param {number} limit - The maximum number of characters allowed.
* @param {number} [safeCutZone=0.6] - A decimal between 0 and 1 representing the minimal acceptable position
* (as a fraction of `limit`) to cut at a space. Defaults to 0.6.
* @returns {string} - The trimmed text, possibly ending with an ellipsis ("...").
* @throws {TypeError} - Throws if `text` is not a string.
* @throws {TypeError} - Throws if `limit` is not a positive integer.
* @throws {TypeError} - Throws if `safeCutZone` is not a number between 0 and 1 (inclusive).
*/
export function safeTextTrim(text: string, limit: number, safeCutZone?: number): string;
//# sourceMappingURL=text.d.mts.map