@mohtasimalam/clean-title
Version:
Advanced text cleaner
31 lines (29 loc) • 1.25 kB
TypeScript
/**
* Clean a title string by removing special characters, converting to lowercase, removing unnecessary tags,
* extra spaces, and diacritics, ensuring a clean and normalized title.
*
* @param {string} str - The title string to clean.
* @returns {string} The cleaned title string, truncated to a maximum of 255 characters.
*
* @example
* // Basic usage:
* cleanTitle("Official Music Video - AMAZING 🎶 song!")
* // returns "amazing song"
*
* @example
* // Removes unnecessary words, extra spaces, and diacritics:
* cleanTitle("L'animation Of My Life - Official Audio")
* // returns "l animation of my life"
*
* @description
* This function performs the following operations in sequence:
* 1. Removes special characters while preserving alphanumeric characters and spaces.
* 2. Converts all characters to lowercase.
* 3. Removes commonly used, unnecessary words in titles such as "official," "music video," and "lyrics."
* 4. Replaces multiple spaces with a single space.
* 5. Removes any leading or trailing whitespace.
* 6. Normalizes characters to remove diacritics (e.g., "é" becomes "e").
* 7. Truncates the final string to 255 characters.
*/
declare const cleanTitle: (str: string) => string;
export { cleanTitle };