5180 fichiers 38.5 Mo 0 téléchargements 238 vues mis à jour il y a 5 heures ui
nitro-v36-with-renderer-v36 / src / api / housekeeping / HousekeepingSearch.ts
HousekeepingSearch.ts 1.1 Ko Télécharger le fichier
/**
 * What the housekeeping global search box asks for:
 *   "#12" -> user 12, "s:411" / "stanza:411" / "room:411" -> room 411,
 *   anything else of two or more characters -> a name search,
 *   empty -> show the recent lookups.
 */
export type HousekeepingSearchQuery =
    | { kind: 'empty' }
    | { kind: 'user-id'; id: number }
    | { kind: 'room-id'; id: number }
    | { kind: 'text'; text: string }
    | { kind: 'too-short' };

const ROOM_PREFIX = /^(?:s|stanza|room|r):\s*#?(\d+)$/i;
const USER_ID = /^#(\d+)$/;

export const parseHousekeepingSearch = (raw: string): HousekeepingSearchQuery => {
    const text = (raw || '').trim();

    if (!text) return { kind: 'empty' };

    const room = ROOM_PREFIX.exec(text);

    if (room) {
        const id = parseInt(room[1]);

        return id > 0 ? { kind: 'room-id', id } : { kind: 'too-short' };
    }

    const user = USER_ID.exec(text);

    if (user) {
        const id = parseInt(user[1]);

        return id > 0 ? { kind: 'user-id', id } : { kind: 'too-short' };
    }

    return text.length >= 2 ? { kind: 'text', text } : { kind: 'too-short' };
};
15Sujets
1Dépôts
20Membres
2En ligne
Profile
Inscrit
Dernière visite
Messages
0
Votes positifs
0
Votes négatifs
0

Nous utilisons des cookies pour assurer le bon fonctionnement du site et améliorer votre expérience. en savoir plus

Autoriser