Path: blob/master/src/packages/next/components/account/config/search/entries.ts
5537 views
/*1* This file is part of CoCalc: Copyright © 2021 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import type { IconName } from "@cocalc/frontend/components/icon";67import { search_match, search_split } from "@cocalc/util/misc";89interface Info0 {10path: string;11desc: string;12title: string;13icon?: IconName | "ai";14}1516export interface Info extends Info0 {17search: string;18}1920interface Info1 extends Info0 {21search?: string | object;22}2324const searchInfo: { [path: string]: Info } = {};2526export function register(info: Info1) {27const search = (28info.desc +29" " +30info.path +31" " +32info.title +33" " +34JSON.stringify(info.search ?? "")35).toLowerCase();36searchInfo[info.path] = { ...info, search };37}3839export function search(s: string, allowEmpty?: boolean): Info[] {40const v = search_split(s.toLowerCase().trim());41const result: Info[] = [];42if (v.length == 0 && !allowEmpty) return result;43for (const path in searchInfo) {44if (45v.length == 0 ||46(searchInfo[path].search && search_match(searchInfo[path].search, v))47) {48result.push(searchInfo[path]);49}50}51return result;52}535455