# kmp-search

> 扩展kmp算法实现查找字符串或数组在原始字符串或数组中的位置

Latest version **0.2.2** (published 2025-02-19) · 0 weekly downloads

## Install

```sh
npm install kmp-search
pnpm add kmp-search
yarn add kmp-search
bun add kmp-search
```

## Health

**Score 25/100 (F)** — status: maintenance-mode.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; low quality score; pre 1.0.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.2 |
| Published | 2025-02-19 |
| First published | 2025-02-18 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | sjk0106 |
| Keywords | kmp, search, find, string, array, index, substring, subarray, algorithm |

## Links

- npm: https://www.npmjs.com/package/kmp-search
- npm.io page: https://npm.io/package/kmp-search

## Alternatives

- [@mce/gif](https://npm.io/package/@mce/gif.md) — 2.6K weekly downloads
- [cleanse](https://npm.io/package/cleanse.md) — 173 weekly downloads
- [str](https://npm.io/package/str.md) — 127 weekly downloads
- [naming](https://npm.io/package/naming.md) — 95 weekly downloads
- [tap-telco-api](https://npm.io/package/tap-telco-api.md) — 19 weekly downloads

## Recent versions

- 0.2.2 (latest) — 2025-02-19
- 0.2.1 — 2025-02-19
- 0.2.0 — 2025-02-19
- 0.1.1 — 2025-02-18
- 0.1.0 — 2025-02-18

## README

# KMP

扩展kmp算法实现查找字符串或数组在原始字符串或数组中的位置。

## 使用

```
npm i kmp-search
```

```typescript
import { findIndex } from "kmp-search";

const stringIndex: number = findIndex("hello world", "world");
console.log(stringIndex); // 6

const numberArrayIndex: number = findIndex([1, 2, 3, 4, 5], [3, 4]);
console.log(numberArrayIndex); // 2

const objectArrayIndex: number = findIndex(
    [{ var1: 1 }, { var1: 2 }, { var1: 3, var2: "" }],
    [{ var1: 2 }, { var1: 3 }],
    (a, b) => a.var1 === b.var1,
);
console.log(objectArrayIndex); // 1，使用了自定义比较函数

const notFindIndex: number = findIndex([1, 2, 3], [2, 3, 4]);
console.log(notFindIndex); // -1，没有找到
```

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