Created
April 2, 2024 12:29
-
-
Save omranjamal/0973ae59380a6ee135fceb77772c8f15 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function unicodeCodePointsToString(codePoints) { | |
return codePoints | |
.replace(/[^0-9A-F]/gi, ' ') | |
.replace(/\s+/g, ' ') | |
.trim() | |
.split(' ') | |
.map((code) => parseInt(code, 16)) | |
.filter((code) => !isNaN(code)) | |
.map((code) => { | |
try { | |
return String.fromCodePoint(code); | |
} catch { | |
return ''; | |
} | |
}) | |
.filter((char) => char !== '') | |
.join(''); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function unicodeCodePointsToString(codePoints: string): string { | |
return codePoints | |
.replace(/[^0-9A-F]/gi, ' ') | |
.replace(/\s+/g, ' ') | |
.trim() | |
.split(' ') | |
.map((code) => parseInt(code, 16)) | |
.filter((code) => !isNaN(code)) | |
.map((code) => { | |
try { | |
return String.fromCodePoint(code); | |
} catch { | |
return ''; | |
} | |
}) | |
.filter((char) => char !== '') | |
.join(''); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment