Skip to content

Commit

Permalink
fix: comment fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewmayer committed Dec 1, 2022
1 parent 8657c47 commit c9caafc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/modules/internet/char-mappings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// selectively sourced from https://github.com/sindresorhus/transliterate/blob/main/replacements.js (under MIT license)
// Selectively sourced from https://github.com/sindresorhus/transliterate/blob/08bbfd3a13ac393d945a430ed5ec62f044a08d70/replacements.js (under MIT license)
const cyrillicMapping: { [key: string]: string } = Object.fromEntries([
['А', 'A'],
['а', 'a'],
Expand Down
14 changes: 6 additions & 8 deletions src/modules/internet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,29 +160,27 @@ export class InternetModule {
break;
}

//There may still be non-ascii characters in the result.
//First remove simple accents etc
// There may still be non-ascii characters in the result.
// First remove simple accents etc
result = result
.normalize('NFKD') //for example è decomposes to as e + ̀
.replace(/[\u0300-\u036f]/g, ''); // removes combining marks

result = result
.split('')
.map(function (char) {
//if we have a mapping for this character, (for Cyrillic, Greek etc) use it
.map((char) => {
// If we have a mapping for this character, (for Cyrillic, Greek etc) use it
if (charMapping[char]) {
return charMapping[char];
}
if (char.charCodeAt(0) < 0x80) {
//keep ascii characters
// Keep ASCII characters
return char;
}
//final fallback return the Unicode char code value for Chinese, Japanese, Korean etc, base-36 encoded
// Final fallback return the Unicode char code value for Chinese, Japanese, Korean etc, base-36 encoded
return char.charCodeAt(0).toString(36);
})
.join('');

//remove spaces and '
result = result.toString().replace(/'/g, '');
result = result.replace(/ /g, '');

Expand Down

0 comments on commit c9caafc

Please sign in to comment.