mirror of
https://github.com/outline/outline.git
synced 2026-12-02 17:52:07 +03:00
* Add missing JSDoc to exported members in app and server utils Documents all exported functions, classes, enums, and constants in app/utils and server/utils that were missing JSDoc, per the project documentation guidelines. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AsEQYA8zN813thxu7GjjzU * Use @returns tag to match codebase convention Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AsEQYA8zN813thxu7GjjzU --------- Co-authored-by: Claude <noreply@anthropic.com>
42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
/**
|
|
* Converts an emoji character to a data URL that can be used as an image
|
|
* source.
|
|
*
|
|
* @param text the emoji character to convert.
|
|
* @returns a data URL containing the emoji rendered as an SVG.
|
|
*/
|
|
export function emojiToUrl(text: string) {
|
|
return `data:image/svg+xml;data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>${text}</text></svg>`;
|
|
}
|
|
|
|
/**
|
|
* Generates a valid emoji name from a filename by:
|
|
* - Removing file extension
|
|
* - Converting to lowercase
|
|
* - Replacing spaces and dashes with underscores
|
|
* - Removing invalid characters (only allowing lowercase letters and underscores)
|
|
* - Removing numbers
|
|
* - Removing leading/trailing underscores
|
|
*
|
|
* @param filename the name of the file.
|
|
* @returns a valid emoji name string.
|
|
*/
|
|
export function generateEmojiNameFromFilename(filename: string): string {
|
|
// Remove file extension
|
|
const nameWithoutExt = filename.replace(/\.[^.]+$/, "");
|
|
|
|
// Convert to lowercase, replace spaces and dashes with underscores
|
|
let name = nameWithoutExt
|
|
.toLowerCase()
|
|
.replace(/\s+/g, "_")
|
|
.replace(/-+/g, "_");
|
|
|
|
// Remove all characters that aren't lowercase letters or underscores (including numbers)
|
|
name = name.replace(/[^a-z_]/g, "");
|
|
|
|
// Remove leading/trailing underscores and collapse multiple underscores
|
|
name = name.replace(/^_+|_+$/g, "").replace(/_+/g, "_");
|
|
|
|
return name;
|
|
}
|