mirror of
https://github.com/litruv/unhomoglyph.git
synced 2026-07-24 10:46:14 +10:00
first commit
This commit is contained in:
20
index.js
Normal file
20
index.js
Normal file
@@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
|
||||
var data = require('./data.json');
|
||||
|
||||
function escapeRegexp(str) {
|
||||
return str.replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1');
|
||||
}
|
||||
|
||||
var REPLACE_RE = RegExp(Object.keys(data).map(escapeRegexp).join('|'), 'g');
|
||||
|
||||
function replace_fn(match) {
|
||||
return data[match];
|
||||
}
|
||||
|
||||
function unhomoglyph(str) {
|
||||
return str.replace(REPLACE_RE, replace_fn);
|
||||
}
|
||||
|
||||
module.exports = unhomoglyph;
|
||||
Reference in New Issue
Block a user