UNPKG

@yamada-ui/react

Version:

React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion

28 lines (26 loc) 999 B
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs'); const require_utils_index = require('../../utils/index.cjs'); let react = require("react"); react = require_rolldown_runtime.__toESM(react); //#region src/components/highlight/use-highlight.ts const escapeRegexp = (term) => term.replace(/[|\\{}()[\]^$+*?.-]/g, (char) => `\\${char}`); const createRegexp = (query) => { query = query.filter(Boolean).map((text) => escapeRegexp(text.trim())); if (query.length) return new RegExp(`(${query.join("|")})`, "ig"); }; const useHighlight = ({ query, text }) => { return (0, react.useMemo)(() => { const regexp = createRegexp((0, require_utils_index.utils_exports.toArray)(query)); if (!regexp) return [{ match: false, text }]; return text.split(regexp).filter(Boolean).map((text$1) => ({ match: regexp.test(text$1), text: text$1 })); }, [text, query]); }; //#endregion exports.useHighlight = useHighlight; //# sourceMappingURL=use-highlight.cjs.map