# @basd/formatter

> A comprehensive text formatting and manipulation library written in JS.

Latest version **0.0.2** (published 2023-10-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install @basd/formatter
pnpm add @basd/formatter
yarn add @basd/formatter
bun add @basd/formatter
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2023-10-08 |
| First published | 2023-09-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 25.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Basedwon |
| Maintainers | basedwon |
| Keywords | text-formatting, text-manipulation, tokenize, normalize, stop-words, string-utility, search-query, case-conversion, punctuation |

## Links

- npm: https://www.npmjs.com/package/@basd/formatter
- Repository: https://gitlab.com/frenware/utils/formatter
- Homepage: https://gitlab.com/frenware/utils/formatter#readme
- Issues: https://gitlab.com/frenware/utils/formatter/issues
- npm.io page: https://npm.io/package/@basd/formatter

## Dependencies (1)

- [basd](https://npm.io/package/basd.md) ^1.0.13

## 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.0.2 (latest) — 2023-10-08
- 0.0.1 — 2023-10-08
- 0.0.0 — 2023-09-29

## README

# Formatter

[![npm](https://img.shields.io/npm/v/@basd/formatter?style=flat&logo=npm)](https://www.npmjs.com/package/@basd/formatter)
[![pipeline](https://gitlab.com/frenware/utils/formatter/badges/master/pipeline.svg)](https://gitlab.com/frenware/utils/formatter/-/pipelines)
[![license](https://img.shields.io/npm/l/@basd/formatter)](https://gitlab.com/frenware/utils/formatter/-/blob/master/LICENSE)
[![downloads](https://img.shields.io/npm/dw/@basd/formatter)](https://www.npmjs.com/package/@basd/formatter) 

[![Gitlab](https://img.shields.io/badge/Gitlab%20-%20?logo=gitlab&color=%23383a40)](https://gitlab.com/frenware/utils/formatter)
[![Twitter](https://img.shields.io/badge/@basdwon%20-%20?logo=twitter&color=%23383a40)](https://twitter.com/basdwon)
[![Discord](https://img.shields.io/badge/Basedwon%20-%20?logo=discord&color=%23383a40)](https://discordapp.com/users/basedwon)

A comprehensive text formatting and manipulation library written in JS. It aims to offer a simple and efficient way to format, normalize, tokenize, and filter text in various scenarios.

## Installation

Install the package with:

```bash
npm install @basd/formatter
```

## Usage

First, import the `Formatter` library.

```js
import Formatter from '@basd/formatter'
```
or
```js
const Formatter = require('@basd/formatter')
```

Or import `TextFormatter` and `StopWordFilter` classes like this:

```js
const { TextFormatter, StopWordFilter } = require('@basd/formatter')
```

### TextFormatter

```js
const formatter = new TextFormatter()

console.log(formatter.normalizeSearchQuery('hello & world | earth'))
// Output: 'HELLO AND WORLD OR EARTH'

console.log(formatter.toUpperCase('hello world'))
// Output: 'HELLO WORLD'

console.log(formatter.toLowerCase('HELLO WORLD'))
// Output: 'hello world'

console.log(formatter.stripPunctuation('hello, world!'))
// Output: 'hello world'

const tokens = formatter.tokenize('This is an example.')
console.log(tokens)
// Output: ['this', 'is', 'an', 'example']
```

### StopWordFilter

```js
const stopWordFilter = new StopWordFilter(['a', 'an', 'the'])
console.log(stopWordFilter.filter(['this', 'is', 'a', 'test']))
// Output: ['this', 'is', 'test']
```

## Documentation

- [API Reference](/docs/api.md)

### TextFormatter

#### Methods

- `normalizeSearchQuery(text: string): string`
- `stripPunctuation(text: string): string`
- `toUpperCase(text: string): string`
- `toLowerCase(text: string): string`
- `splitWords(text: string): Array<string>`
- `filterStopWords(words: Array<string>): Array<string>`
- `normalize(text: string, upper: boolean = false): string`
- `tokenize(text: string, filterStopWords: boolean = true): Array<string>`
- `setStopWords(stopWords: Array<string>)`: Set a new list of stop words.

### StopWordFilter

#### Methods

- `filter(words: Array<string>): Array<string>`
- `setStopWords(stopWords: Array<string>)`: Set a new list of stop words.

#### Static Methods

- `get defaultStopWords(): Array<string>`: Get the default list of stop words.
- `get extendedStopWords(): Array<string>`: Get an extended list of stop words. (`extendedStopWords` must be imported or defined.)

## Tests

In order to run the test suite, simply clone the repository and install its dependencies:

```bash
git clone https://gitlab.com/frenware/utils/formatter.git
cd formatter
npm install
```

To run the tests:

```bash
npm test
```

## Contributing

Thank you! Please see our [contributing guidelines](/docs/contributing.md) for details.

## Donations

If you find this project useful and want to help support further development, please send us some coin. We greatly appreciate any and all contributions. Thank you!

**Bitcoin (BTC):**
```
1JUb1yNFH6wjGekRUW6Dfgyg4J4h6wKKdF
```

**Monero (XMR):**
```
46uV2fMZT3EWkBrGUgszJCcbqFqEvqrB4bZBJwsbx7yA8e2WBakXzJSUK8aqT4GoqERzbg4oKT2SiPeCgjzVH6VpSQ5y7KQ
```

## License

@basd/formatter is [MIT licensed](https://gitlab.com/frenware/utils/formatter/-/blob/master/LICENSE).

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