# accentize

> Turn any string into an accentized regex for searching, find patterns, querying, filtering...

Latest version **1.0.3** (published 2020-07-15) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2020-07-15 |
| First published | 2020-07-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 13.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Maintainers | nicknish09 |
| Keywords | accent, unaccent, npm, package, nicknish, regex, regex-accent, accent-regex, regex-search, accent-javascript, accent-search-javascript, accent-query, regex-query, accent-pattern, accent-match, accent-transform-regex |

## Links

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

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.3 (latest) — 2020-07-15
- 1.0.2 — 2020-07-15
- 1.0.1 — 2020-07-15
- 1.0.0 — 2020-07-15

## README

# Accentize

![badge of version](https://img.shields.io/badge/npm-v1.0.3-green)

  

Transform any string into an accentized regex to match any pattern for filtering, querying, searching, etc...

  

**match a string sample**

![test match](https://i.imgur.com/aVAqz55.gif)

  

**filter array sample**

![filter array](https://i.imgur.com/ibQvtLW.gif)

  

## Installation

```$ yarn add accentize```

  

or with npm

  

```$ npm install --save accentize ```


## Usage
**Turn string into a accentized regex:**
```
const accentize = require('accentize');

accentize("hello world")
// returns the regex: /\s*[hⓗｈĥḣḧȟḥḩḫẖħⱨⱶɥ][eⓔｅèéêềếễểẽēḕḗĕėëẻěȅȇẹệȩḝęḙḛɇɛǝ][lⓛｌŀĺľḷḹļḽḻſłƚɫⱡꝉꞁꝇ][lⓛｌŀĺľḷḹļḽḻſłƚɫⱡꝉꞁꝇ][oⓞｏòóôồốỗổõṍȭṏōṑṓŏȯȱöȫỏőǒȍȏơờớỡởợọộǫǭøǿɔꝋꝍɵ]\s*\s*[wⓦｗẁẃŵẇẅẘẉⱳ][oⓞｏòóôồốỗổõṍȭṏōṑṓŏȯȱöȫỏőǒȍȏơờớỡởợọộǫǭøǿɔꝋꝍɵ][rⓡｒŕṙřȑȓṛṝŗṟɍɽꝛꞧꞃ][lⓛｌŀĺľḷḹļḽḻſłƚɫⱡꝉꞁꝇ][dⓓｄḋďḍḑḓḏđƌɖɗꝺ]\s*/i
```

**Test if a string is a accent version of other:**
```
const accentize = require('accentize');

let accentizedString = accentize("hello world") 
accentizedString.test("hello world") // true
accentizedString.test("hèllô wórld") // true
accentizedString.test("hêlló world") // true
```

**Filter a array where strings can be accent versions:**
```
const accentize = require('accentize');

let  arrayToFilter  = [{name: "João Luís"}, {name: "Mária Ríta"}, {name: "Ísis Môàna"}]
let accentizedString = accentize("joao luis")

let  filteredArray  =  arrayToFilter.filter(user  =>  user.name.match(accentizedString))
// [{"name":"João Luís"}]
```

**With MongoDB queries:**

Suppose you have a Mongo DB with users, represented with the following array:
```
db.getCollection("users") 
// 
[
  {_id: "5ef689", name: "João Luís"},
  {_id: "5efkl9", name: "Mária Ríta"}, 
  {_id: "5ef6a8", name: "Ísis Môàna"}
]
```
You want to make a query to find user with the name Ísis Môàna, by searching for isis moana. Then use:
```
const accentize = require('accentize');

db.users.find({"name": accentize("isis moana")})
// {_id: "5ef6a8", name: "Ísis Môàna"}

db.users.find({"name": accentize("is oana", true)}) // would work with the second param true, the findAll param
```
Notice the second param as true in the second example, it is the findAll param, to include .* in the accentized regex, so the database will find everything that matches, making a query similar to %LIKE%.

## Why

Usually when we deal with accents the most common approach is to remove the accent from words and then compare/do what you have to do, like:
```
let normalizedString = someFunctionToRemoveAccent("hèllô wórld") // returns hello world
normalizedString === "hello world" // true	
```
What accentize does is kinda the opposite, it transforms a regular string into a regex that will match any versions of that string with accents:

```
// ES6
import accentize from 'accentize';
// commonjs
const accentize = require('accentize');

let accentizedString = accentize("hello world") 
// returns the regex: /\s*[hⓗｈĥḣḧȟḥḩḫẖħⱨⱶɥ][eⓔｅèéêềếễểẽēḕḗĕėëẻěȅȇẹệȩḝęḙḛɇɛǝ][lⓛｌŀĺľḷḹļḽḻſłƚɫⱡꝉꞁꝇ][lⓛｌŀĺľḷḹļḽḻſłƚɫⱡꝉꞁꝇ][oⓞｏòóôồốỗổõṍȭṏōṑṓŏȯȱöȫỏőǒȍȏơờớỡởợọộǫǭøǿɔꝋꝍɵ]\s*\s*[wⓦｗẁẃŵẇẅẘẉⱳ][oⓞｏòóôồốỗổõṍȭṏōṑṓŏȯȱöȫỏőǒȍȏơờớỡởợọộǫǭøǿɔꝋꝍɵ][rⓡｒŕṙřȑȓṛṝŗṟɍɽꝛꞧꞃ][lⓛｌŀĺľḷḹļḽḻſłƚɫⱡꝉꞁꝇ][dⓓｄḋďḍḑḓḏđƌɖɗꝺ]\s*/i

accentizedString.test("hello world") // true
accentizedString.test("hèllô wórld") // true
accentizedString.test("hêlló world") // true
```
With the accentized regex **you can test any variant of a string with accent using the normalized string!**

Works with **case insensitivity** too:
```
let stringToFind = "hÉllò Wôrld"
let accentizedString = accentize("hello world")
accentizedString.test(stringToFind) // true
```

## Params
```
function accentize(stringToAccentize, findAll) { ... }
```
**stringToAccentize**: the string that will be accentized

**findAll**: if is true the accentized regex will have the .* operator between words, so it can match more precisely multi word strings.

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