#

API Docs for: 3.10.3
Show: Inherited Protected Private Deprecated

# Text.AccentFold Class

Defined in: `text/js/text-accentfold.js:16`
Module: text-accentfold
Parent Module: text

Provides a basic accent folding implementation that converts common accented letters (like "á") to their non-accented forms (like "a").

This implementation is not comprehensive, and should only be used as a last resort when accent folding can't be done on the server. A comprehensive accent folding implementation would require much more character data to be sent to the browser, resulting in a significant performance penalty. This implementation strives for a compromise between usefulness and performance.

Accent folding is a destructive operation that can't be reversed, and may change or destroy the actual meaning of the text depending on the language. It should not be used on strings that will later be displayed to a user, unless this is done with the understanding that linguistic meaning may be lost and that you may in fact confuse or insult the user by doing so.

When used for matching, accent folding is likely to produce erroneous matches for languages in which characters with diacritics are considered different from their base characters, or where correct folding would map to other character sequences than just stripped characters. For example, in German "ü" is a character that's clearly different from "u" and should match "ue" instead. The word "betrügen" means "to defraud", while "betrugen" is the past tense of "to behave". The name "Müller" is expected to match "Mueller", but not "Muller". On the other hand, accent folding falls short for languages where different base characters are expected to match. In Japanese, for example, hiragana and katakana characters with the same pronunciation ("あ" and "ア") are commonly treated as equivalent for lookups, but accent folding treats them as different.

- Index
- Methods

## Item Index

### Methods

- canFold static
- compare static
- filter static
- fold static

## Methods

### `canFold`

(

- `string`

)
Boolean static

Defined in `text/js/text-accentfold.js:64`

Returns `true` if the specified string contains one or more characters that can be folded, `false` otherwise.

#### Parameters:

- `string` String

  String to test.

#### Returns:

Boolean:

### `compare`

(

- `a`
- `b`
- `func`

)
Boolean static

Defined in `text/js/text-accentfold.js:86`

Compares the accent-folded versions of two strings and returns `true` if they're the same, `false` otherwise. If a custom comparison function is supplied, the accent-folded strings will be passed to that function for comparison.

#### Parameters:

- `a` String

  First string to compare.

- `b` String

  Second string to compare.

- `func` Function

  (optional) Custom comparison function. Should return a truthy or falsy value.

#### Returns:

Boolean: Results of the comparison.

### `filter`

(

- `haystack`
- `func`

)
Array static

Defined in `text/js/text-accentfold.js:107`

Returns a copy of haystack containing only the strings for which the supplied function returns `true`.

While comparisons will be made using accent-folded strings, the returned array of matches will contain the original strings that were passed in.

#### Parameters:

- `haystack` Array

  Array of strings to filter.

- `func` Function

  Comparison function. Will receive an accent-folded haystack string as an argument, and should return a truthy or falsy value.

#### Returns:

Array: Filtered copy of haystack.

### `fold`

(

- `input`

)
String | Array static

Defined in `text/js/text-accentfold.js:132`

Accent-folds the specified string or array of strings and returns a copy in which common accented letters have been converted to their closest non-accented, lowercase forms.

#### Parameters:

- `input` String | Array

  String or array of strings to be folded.

#### Returns:

String | Array: Folded string or array of strings.