# searchability

> A simple interface to pair a sting with built-in search functions

Latest version **2.0.2** (published 2022-05-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install searchability
pnpm add searchability
yarn add searchability
bun add searchability
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2022-05-16 |
| First published | 2021-07-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | David Paige |
| Maintainers | pseudosma |
| Keywords | string, search, searchable, searchability |

## Links

- npm: https://www.npmjs.com/package/searchability
- Repository: https://github.com/pseudosma/searchability
- Issues: https://github.com/pseudosma/searchability/issues
- npm.io page: https://npm.io/package/searchability

## 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

- 2.0.2 (latest) — 2022-05-16
- 2.0.1 — 2021-10-08
- 2.0.0 — 2021-10-01
- 1.0.0 — 2021-07-12

## README

# Searchability [![Test](https://github.com/pseudosma/searchability/actions/workflows/push.yml/badge.svg?branch=master)](https://github.com/pseudosma/searchability/actions/workflows/push.yml) [![Coverage Status](https://coveralls.io/repos/github/pseudosma/searchability/badge.svg?branch=master)](https://coveralls.io/github/pseudosma/searchability?branch=master) ![License](https://img.shields.io/npm/l/searchability)

Searchability provides a simple interface, a **Searchable**, to pair a string with some of the built-in search functions - `endsWith`, `includes`, or `startsWith`. 

```typescript
interface Searchable {
  searchTerm: string;
  searchType: SearchType;
};

enum SearchType {
  EndsWith,
  Includes,
  StartsWith
}
```

Users are free to build their own logic to interpret a Searchable, but a dedicated **Search** function is provided that picks the correct search based on the **SearchType** enum.

```typescript
const Search = (searchable: Searchable, searchString: string, position?: number): boolean
```

## Usage

The intended usage of a Searchable is to provide a compact option for any type-based searches, as the following example illustrates:

```typescript
import { Searchable, Search, SearchKey } from "searchability";

type SearchKey = string | Searchable | RegExp;

const searchString: string = "Lorem ipsum";
const k: SearchKey = {searchTerm: "Lorem", searchKey: SearchKey.StartsWith}
```

```typescript
function matchFound(k: SearchKey) => boolean {
  switch (typeof k) {
    case "string":
      return k === searchString;
    case "Searchable"
      return Search(k, searchString);
    case "RegExp"
      return k.exec(searchString);
    }
}
```

## Install with [npm](https://www.npmjs.com/)

```bash
npm i searchability --save
```
This package is provided in the ES2015 module format.

## Contributing

Pull requests are always welcome. For bugs and feature requests, [please create an issue](https://github.com/pseudosma/searchability/issues).

## License

Copyright (c) 2021 David Paige.  
Released under the MIT license.

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