mirror of
https://github.com/litruv/unhomoglyph.git
synced 2026-07-26 03:36:14 +10:00
Compare commits
25 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
50c1f3aa73 | ||
|
|
0f14f53ec4 | ||
|
|
7a61c5e20e | ||
|
|
87c8f30f3e | ||
|
|
9d6bc548cd | ||
|
|
193738762a | ||
|
|
af3e0a9b7c | ||
|
|
7ff0277276 | ||
|
|
d6ec78e7c1 | ||
|
|
7ac80669b0 | ||
|
|
0fca8b9920 | ||
|
|
b7a5926d98 | ||
|
|
fee537fbf9 | ||
|
|
5fa3d0af6f | ||
|
|
a6c803a17d | ||
|
|
2f17975f88 | ||
|
|
ef5dfe6afc | ||
|
|
cb57f4472e | ||
|
|
189c8c278c | ||
|
|
0b428f40cf | ||
|
|
fed5576b38 | ||
|
|
77448891d7 | ||
|
|
59c5f0e151 | ||
|
|
0bc3804849 | ||
|
|
ce667c335a |
@@ -1,5 +1,3 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- '4'
|
||||
- '6'
|
||||
sudo: false
|
||||
- node
|
||||
|
||||
35
CHANGELOG.md
35
CHANGELOG.md
@@ -1,3 +1,38 @@
|
||||
1.0.6 / 2020-05-18
|
||||
------------------
|
||||
|
||||
- Update mapping data to version 13.0.0
|
||||
http://www.unicode.org/Public/security/latest/confusables.txt
|
||||
- Encode `\u2028` & `\u2029` as text, #7.
|
||||
- Dev deps bump.
|
||||
|
||||
|
||||
1.0.5 / 2020-03-03
|
||||
------------------
|
||||
|
||||
- Include missed TS definition into npm package.
|
||||
|
||||
|
||||
1.0.4 / 2020-02-05
|
||||
------------------
|
||||
|
||||
- Added TS definition.
|
||||
|
||||
|
||||
1.0.3 / 2019-11-04
|
||||
------------------
|
||||
|
||||
- Update mapping data to version 12.1.0
|
||||
http://www.unicode.org/Public/security/latest/confusables.txt
|
||||
- Dev deps bump.
|
||||
|
||||
1.0.2 / 2017-03-05
|
||||
------------------
|
||||
|
||||
- Update mapping data to version 9.0.0
|
||||
http://www.unicode.org/Public/security/latest/confusables.txt
|
||||
|
||||
|
||||
1.0.1 / 2016-12-09
|
||||
------------------
|
||||
|
||||
|
||||
23
README.md
23
README.md
@@ -4,14 +4,21 @@
|
||||
[](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), v8.0.0.
|
||||
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 install unhomoglyph --save
|
||||
npm i git+https://github.com/TateB/unhomoglyph.git
|
||||
```
|
||||
|
||||
|
||||
@@ -21,6 +28,18 @@ npm install unhomoglyph --save
|
||||
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`);
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
44
addOther.js
Normal file
44
addOther.js
Normal file
@@ -0,0 +1,44 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const savePath = path.join(__dirname, 'data.json')
|
||||
var data = require('./data.json')
|
||||
|
||||
const similarLetters = [
|
||||
{ eng: "a", alts: "₳АаДдӔӕА̊а̊А̄а̄ӒӓӐӑꙘꙙѦѧӘәa͏aAaα𝓐𝓪𝐀🇦𝐚" },
|
||||
{ eng: "b", alts: "฿БбВвЫыЪъЬь6Ҍҍb͏Bb𝓑𝓫𝐁𝐛🇧" },
|
||||
{ eng: "c", alts: "🇨₵Сс(ҪҫС́с́c͏Cc¢𝓒𝓬𝐂𝐜" },
|
||||
{ eng: "d", alts: "ĐԂԃ🇩Ԁԁd͏Dd∂𝓓𝓭𝐃𝐝" },
|
||||
{ eng: "e", alts: "ɆЕеЁёЗ🇪зЭэЄ̈є̈Е̃е̃Е̄е̄Ё̄ё̄ӖӗЀѐԐԑЄєӠӡe͏Ee𝓔𝓮𝐄𝐞" },
|
||||
{ eng: "f", alts: "₣Ғғf͏Ff𝓕🇫𝓯𝐅𝐟" },
|
||||
{ eng: "g", alts: "₲Ԍԍg͏Gg𝓖𝓰𝐆🇬𝐠" },
|
||||
{ eng: "h", alts: "НⱧнӉӊҢңԨԩӇӈҺһԊԋ🇭h͏Hh𝓗𝓱𝐇𝐡" },
|
||||
{ eng: "i", alts: "l1ł|ӀӏЇїІіi͏Iiι𝓘𝓲🇮𝐈𝐢" },
|
||||
{ eng: "j", alts: "Јјj͏JJjנ𝓙𝓳𝐉𝐣🇯" },
|
||||
{ eng: "k", alts: "КкҚқ₭ҜҝҞҟҠҡk͏Kk𝓚𝓴𝐊🇰𝐤" },
|
||||
{ eng: "l", alts: "l͏LlⱠℓ𝓛𝓵𝐋𝐥🇱" },
|
||||
{ eng: "m", alts: "МмӍӎm͏₥Mm𝓜𝓶𝐌𝐦🇲" },
|
||||
{ eng: "n", alts: "ИиЙйЛлП₦пԤԥn͏Nn𝓝𝓷𝐍𝐧🇳" },
|
||||
{ eng: "o", alts: "ОоЮюФф0ӪØӫӦӧО̄о̄ꙔꙕѲѳѺѻꙪꙫꙨꙩꚚꚛӨө🇴o͏Ooσ𝓞𝓸𝐎𝐨" },
|
||||
{ eng: "p", alts: "РрР̌р̌Ҏҏp͏P₱pρ𝓟𝓹𝐏🇵" },
|
||||
{ eng: "q", alts: "g9q͏Qq𝓠𝓺𝐐Q𝐪🇶" },
|
||||
{ eng: "r", alts: "ГгЯяԘԙԆԇԄԅr͏Rr𝓡𝓻𝐑𝐫Ɽ🇷" },
|
||||
{ eng: "s", alts: "5ꙄꙅЅѕs͏Ss𝓢𝓼𝐒𝐬🇸₴" },
|
||||
{ eng: "t", alts: "ТтҬҭt͏Tt𝓣𝓽𝐓𝐭₮🇹" },
|
||||
{ eng: "u", alts: "vЦцꙠꙡu͏Uuυ𝓤𝓾𝐔𝐮🇺Ʉ"},
|
||||
{ eng: "v", alts: "ѶѷѴѵv͏Vvν𝓥𝓿𝐕𝐯🇻"},
|
||||
{ eng: "w", alts: "ШшЩщꚆꚇѠѡԜԝw͏Wwω𝓦𝔀𝐖𝐰🇼₩" },
|
||||
{ eng: "x", alts: "ХхҲҳӾӿӼӽx͏Xxχ𝓧𝔁𝐗🇽𝐱" },
|
||||
{ eng: "y", alts: "УуҮүЧчЦцӮӯӰӱЎўӲӳꚎꚏy͏🇾Yy𝓨𝔂𝐘𝐲Ɏ" },
|
||||
{ eng: "z", alts: "2ЗзЖжЗ́ж́z͏Zz𝓩𝔃𝐙𝐳Ⱬ🇿" }
|
||||
]
|
||||
|
||||
similarLetters.forEach((letter) => {
|
||||
const alts = letter.alts.normalize('NFD').replace(/\p{Diacritic}/gu, "").replace(/[\u200B-\u200D\uFEFF\u034F]/g, '');
|
||||
[...alts].forEach((alt) => {
|
||||
data[alt.toLowerCase()] = letter.eng
|
||||
})
|
||||
})
|
||||
|
||||
fs.writeFileSync(savePath, JSON.stringify(data, null, 2))
|
||||
|
||||
console.log("Added alternatives")
|
||||
4
index.d.ts
vendored
Normal file
4
index.d.ts
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
declare module 'unhomoglyph' {
|
||||
const unhomoglyph: (s: string) => string;
|
||||
export default unhomoglyph;
|
||||
}
|
||||
2
index.js
2
index.js
@@ -14,7 +14,7 @@ function replace_fn(match) {
|
||||
}
|
||||
|
||||
function unhomoglyph(str) {
|
||||
return str.replace(REPLACE_RE, replace_fn);
|
||||
return str.toLowerCase().normalize('NFD').replace(/\p{Diacritic}/gu, "").replace(/[\u200B-\u200D\uFEFF\u034F]/g, '').replace(REPLACE_RE, replace_fn).toLowerCase();
|
||||
}
|
||||
|
||||
module.exports = unhomoglyph;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "unhomoglyph",
|
||||
"version": "1.0.1",
|
||||
"version": "1.0.6",
|
||||
"description": "Replace all homoglyphs with base characters.",
|
||||
"keywords": [
|
||||
"homoglyph",
|
||||
@@ -10,7 +10,8 @@
|
||||
"license": "MIT",
|
||||
"files": [
|
||||
"index.js",
|
||||
"data.json"
|
||||
"data.json",
|
||||
"index.d.ts"
|
||||
],
|
||||
"scripts": {
|
||||
"lint": "eslint .",
|
||||
@@ -18,7 +19,7 @@
|
||||
"update": "node update.js && npm test"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^3.11.1",
|
||||
"mocha": "^3.2.0"
|
||||
"eslint": "^7.0.0",
|
||||
"mocha": "^7.1.2"
|
||||
}
|
||||
}
|
||||
|
||||
4
test.js
4
test.js
@@ -26,4 +26,8 @@ describe('unhomoglyph', function () {
|
||||
assert.strictEqual(unhomoglyph('1abcаа'), 'labcaa');
|
||||
});
|
||||
|
||||
it('2028 & 2029 should be ok after replace in updater', function () {
|
||||
assert.strictEqual(data['\u2028'], ' ');
|
||||
assert.strictEqual(data['\u2029'], ' ');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -37,8 +37,14 @@ function save(str) {
|
||||
result[src] = dst;
|
||||
});
|
||||
|
||||
let output = JSON.stringify(result, null, ' ')
|
||||
// Workaround for ES9 <=> ES10 inconsistency
|
||||
// https://github.com/nodeca/unhomoglyph/issues/7
|
||||
// https://github.com/facebook/hermes/issues/235#issuecomment-623606572
|
||||
.replace(/\u2028/g, '\\u2028')
|
||||
.replace(/\u2029/g, '\\u2029');
|
||||
|
||||
fs.writeFileSync(SAVE_PATH, JSON.stringify(result, null, ' '));
|
||||
fs.writeFileSync(SAVE_PATH, output);
|
||||
console.log('Done!');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user