File tree Expand file tree Collapse file tree 1 file changed +9
-12
lines changed
Expand file tree Collapse file tree 1 file changed +9
-12
lines changed Original file line number Diff line number Diff line change @@ -18,24 +18,21 @@ export const truncateString = (str: string, length: number): string => {
1818} ;
1919
2020/**
21- * Sanitizes a string for Discord Activity .
21+ * Sanitizes a string for Discord Rich Presence activity, ensuring it meets length requirements .
2222 * @param input - The string to sanitize.
23- * @returns The sanitized string or undefined.
23+ * @param fallback - A fallback string to use if the input is empty or whitespace. Defaults to 'undefined'.
24+ * @returns The sanitized string, compliant with Discord's requirements.
2425 */
25- export function sanitizeActivityText ( input ?: string ) : string {
26- if ( ! input ) {
27- return 'undefined' ;
28- }
29-
30- const trimmed = input . trim ( ) ;
31- let safeString = truncateString ( trimmed , 128 ) ;
26+ export function sanitizeActivityText ( input : string | undefined , fallback : string = 'undefined' ) : string {
27+ const text = ( input && input . trim ( ) ) ? input . trim ( ) : fallback . trim ( ) ;
28+ let safeString = truncateString ( text , 128 ) ;
3229
33- if ( safeString . length < = 0 ) {
34- return 'undefined' ;
30+ if ( safeString . length == = 0 ) {
31+ return 'undefined' ; // change if necessary
3532 }
3633
3734 if ( safeString . length < 2 ) {
38- safeString = safeString + '⠀' ; // change if you have better replacement
35+ safeString = safeString . padEnd ( 2 , '⠀' ) ; // change if necessary
3936 }
4037
4138 return safeString ;
You can’t perform that action at this time.
0 commit comments