Files
unhomoglyph/README.md
2021-11-29 14:03:02 +11:00

56 lines
1.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# unhomoglyph
[![Build Status](https://img.shields.io/travis/nodeca/unhomoglyph/master.svg?style=flat)](https://travis-ci.org/nodeca/unhomoglyph)
[![NPM version](https://img.shields.io/npm/v/unhomoglyph.svg?style=flat)](https://www.npmjs.org/package/unhomoglyph)
> Replace all homoglyphs with base characters. Useful to detect similar strings.
For example, to prohibit register similar looking nicknames at websites.
Data source - [Recommended confusable mapping for IDN](http://www.unicode.org/Public/security/latest/confusables.txt), v13.0.0.
Similar letters array in addOther.js provided by [litruv](https://github.com/litruv) and [KillAllTheHippies](https://github.com/killallthehippies).
__Note!__ Text after transform is NOT intended be read by humans. For example,
`m` will be transformed to `r` + `n`. Goal is to compare 2 strings after
transform, to check if sources looks similar or not. If sources look similar,
then transformed strings are equal.
## Install
```bash
npm i git+https://github.com/TateB/unhomoglyph.git
```
## Example
```js
const unhomoglyph = require('unhomoglyph');
console.log(unhomoglyph('AΑА')); // => AAAAAAA
console.log(unhomoglyph('m')); // => rn (r + n)
//
// Compare nicknames
//
const username1 = 'm';
const username2 = 'rn';
if (unhomoglyph(username1) === unhomoglyph(username2)) {
console.log(`"${username1}" and "${username2} look similar`);
}
```
## Update
```bash
npm run update
```
## License
[MIT](https://github.com/nodeca/unhomoglyph/blob/master/LICENSE)