Skip to content

Instantly share code, notes, and snippets.

@omranjamal
Created April 2, 2024 12:29
Show Gist options
  • Save omranjamal/0973ae59380a6ee135fceb77772c8f15 to your computer and use it in GitHub Desktop.
Save omranjamal/0973ae59380a6ee135fceb77772c8f15 to your computer and use it in GitHub Desktop.
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('');
}
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