A package for DOM lookup and markup. Based on any input from the user (keyword/DOM selector), regular expressions are supported.
- DOM search based on keywords or selectors.
- Result mark(optional).
$ yarn add local-search
Online demo here.
// in react
let search = new LocalSearch({ useRegexp: true });
function App() {
const [keywords, setKeywords] = useState("");
useEffect(() => {
search.setSearch(keywords);
}, [keywords, search]);
function handleClick() {
search.begin().then(() => {
search.next();
});
}
function handleNext() {
search.next();
}
return <div>...</div>;
}
export type KeywordsOrSelector =
| string
| keyof HTMLElementTagNameMap
| keyof SVGElementTagNameMap;
interface IOption {
input?: KeywordsOrSelector; // keywords or selector
useRegexp?: boolean; // default: false
scope?: HTMLElement | string; // rootDom, default: document.body
}
export interface IDomFormated {
dom: HTMLElement;
type: typeof TypeSelector | typeof TypeText;
}
class LocalSearch {
setSearch(input: KeywordsOrSelector): void; // set keywords
begin(): Promise<IDomFormated[]> | undefined; // begin to search
next(): boolean; // mark one search result, returns has next search result or not
}
see from CHANGELOG.md