unified-doc-search-micromatch
TypeScript icon, indicating that this package has built-in type declarations

1.0.8 • Public • Published

unified-doc-search-micromatch

unified-doc micromatch search algorithm.

Install

npm install unified-doc-search-micromatch

Use

Supports the matching features in the micromatch package when searching doc instances managed by unified-doc.

import search from 'unified-doc-search-micromatch';

const content = 'a TO the b TO the c';

expect(search(content, 'TO', { nocase: true })).toEqual([
  { start: 2, end: 4, value: 'TO' },
  { start: 11, end: 13, value: 'TO' },
]);

expect(search(content, 'to', { nocase: false })).toEqual([]);

expect(search(content, 'a*b')).toEqual([
  { start: 0, end: 10, value: 'a TO the b' },
]);

expect(search(content, 'a????')).toEqual([
  { start: 0, end: 5, value: 'a TO ' },
]);

expect(search(content, 'a TO the (b|c)')).toEqual([
  { start: 0, end: 10, value: 'a TO the b' },
]);

expect(search(content, 'a TO the (c|d)')).toEqual([]);

expect(search(content, 'a TO the !(c|d)')).toEqual([
  { start: 0, end: 9, value: 'a TO the ' },
]);

API

search(content, query[, options])

Interface

function search(
  content: string,
  query: string,
  options?: Record<string, any>,
): SearchResult[]

Uses the unified SearchAlgorithm interface to search on content with a provided query string and micromatch-specific options. Returns unified SearchResult data.

Please refer to the micromatch documentation for configurable options and match behaviors.

Related interfaces

type SearchAlgorithm = (
  /** string content to search on */
  content: string,
  /** query string */
  query: string,
  /** search algorithm options */
  options?: Record<string, any>,
) => SearchResult[];

interface SearchResult {
  /** start offset of the search result relative to the `textContent` of the `doc` */
  start: number;
  /** end offset of the search result relative to the `textContent` of the `doc` */
  end: number;
  /** matched text value in the `doc` */
  value: string;
  /** additional data can be stored here */
  data?: Record<string, any>;
}

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.85latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.85
1.0.70
1.0.60
1.0.51
1.0.21
1.0.10
1.0.01
0.1.3-beta.02
0.1.2-beta.00
0.1.1-beta.00

Package Sidebar

Install

npm i unified-doc-search-micromatch

Weekly Downloads

10

Version

1.0.8

License

MIT

Unpacked Size

14.7 kB

Total Files

13

Last publish

Collaborators

  • chrisrzhou