# unified-doc-search-micromatch

> unified-doc micromatch search algorithm.

Latest version **1.0.8** (published 2020-08-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install unified-doc-search-micromatch
pnpm add unified-doc-search-micromatch
yarn add unified-doc-search-micromatch
bun add unified-doc-search-micromatch
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.8 |
| Published | 2020-08-29 |
| First published | 2020-06-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 14.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 10 |
| Author | Chris Zhou |
| Maintainers | chrisrzhou |
| Keywords | unified, doc, search, micromatch, document, file, content, unist, hast, nlp, algorithm, glob, glob-pattern, glob-matching, wildcard, bash |

## Links

- npm: https://www.npmjs.com/package/unified-doc-search-micromatch
- Repository: https://github.com/unified-doc/unified-doc
- Homepage: https://github.com/unified-doc/unified-doc/tree/main/packages/unified-doc-search-micromatch
- Issues: https://github.com/unified-doc/unified-doc/issues
- npm.io page: https://npm.io/package/unified-doc-search-micromatch

## Dependencies (2)

- [micromatch](https://npm.io/package/micromatch.md) ^4.0.2
- [unified-doc-types](https://npm.io/package/unified-doc-types.md) ^2.0.3

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 1.0.8 (latest) — 2020-08-29
- 1.0.7 — 2020-08-23
- 1.0.6 — 2020-08-20
- 1.0.5 — 2020-08-19
- 1.0.2 — 2020-08-16
- 1.0.1 — 2020-08-09
- 1.0.0 — 2020-07-19
- 0.1.3-beta.0 — 2020-07-19
- 0.1.2-beta.0 — 2020-07-04
- 0.1.1-beta.0 — 2020-06-24

## README

# unified-doc-search-micromatch

[**unified-doc**][unified-doc] [`micromatch`][micromatch] search algorithm.

## Install

```sh
npm install unified-doc-search-micromatch
```

## Use

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

```js
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
```ts
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`][micromatch] documentation for configurable options and match behaviors.


#### Related interfaces
```ts
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>;
}
```

<!-- Definitions -->
[micromatch]: https://github.com/micromatch/micromatch
[unified-doc]: https://github.com/unified-doc/unified-doc

---
_Source: https://npm.io/package/unified-doc-search-micromatch · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
