Skip to content

Instantly share code, notes, and snippets.

@danieldietrich
Last active September 25, 2020 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danieldietrich/8fa7fd56538ccbefdf2735f400800aad to your computer and use it in GitHub Desktop.
Save danieldietrich/8fa7fd56538ccbefdf2735f400800aad to your computer and use it in GitHub Desktop.
Emoji numbers
function numji(i, c = 0) {
let s = "";
if (!Number.isNaN(i) && Number.isFinite(i)) {
i = Math.abs(Math.trunc(i));
do {
c--;
s = String.fromCharCode(0x0030 + i % 10, 0xFE0F, 0x20E3) + s;
i = Math.trunc(i / 10);
} while (i > 0 || c > 0);
}
return s;
}
@danieldietrich
Copy link
Author

danieldietrich commented Sep 25, 2020

Note: the number of digits c will never change the sign.

  • -Number.MAX_VALUE - 1 is equal to -Number.MAX_VALUE
  • Number.MIN_SAFE_INTEGER * Number.MAX_VALUE is equal to -Infinity

@danieldietrich
Copy link
Author

Example:

// DD.MM.YYYY
function dateji(d = new Date()) {
  return `${numji(d.getDate(), 2)}.${numji(d.getMonth() + 1, 2)}.${numji(d.getFullYear())}`;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment