Last active
November 9, 2023 16:23
-
-
Save alex-cory/b807a07dee2c4c410435783a94213ec6 to your computer and use it in GitHub Desktop.
This file contains 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
const toEmoji = (num) => { | |
if (num === null || num === undefined || Number.isNaN(num)) return '⛔'; | |
if (num === 10) return '🔟'; | |
if (!isFinite(num)) return '🔁'; | |
return String(num) | |
.replace('-', '−') | |
.replace('.', '⏺️') | |
.replace(/\d/g, digit => `${digit}️⃣`) | |
.replace(/⏺️(\d{0,2})\d*/, (match, p1) => `⏺️${p1}`); | |
}; | |
// Examples | |
// console.log(toEmoji(-1)); // '−1️⃣' | |
// console.log(toEmoji(Infinity)); // '🔁' | |
// console.log(toEmoji(10)); // '🔟' | |
// console.log(toEmoji(0)); // '0️⃣' | |
// console.log(toEmoji(3.14159)); // '3️⃣⏺️14' | |
// console.log(toEmoji(NaN)); // '⛔' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment