Numeronyms are a form of abbreviation. The middle of the word or phrase is swapped out for a number that represents the number of letters that are being replaced. The first and last letters are retained.
Some examples are:
- a16z for Andreessen Horowitz
- i18n for Internationalization
- i10n for Localization
I’m not really a fan of the word “numeronym”, primarily because I can’t ever seem to remember it. Looking through Google Trends, seems like most people don’t know the term either. I usually just refer to it as “number abbreviation”.
The steps to accomplish this are:
- Lowercase the string
- Remove the spaces from the string
- Grab the first character from the string
- Grab the last character from the string
- Count the number of characters that are left
- Concatenate the first letter, number, and last character
I’m sure there are packages out there to accomplish this, but I don’t like dependency bloat when things can be accomplished pretty easily.
Based on the steps outlined above, we can create a short function that takes a string as a parameter and spit back the numeronym:
const numeronym = (s) => {
const l = s.toLowerCase().replace(/\s/g, '');
return `${l[0]}${l.length - 2}${l[l.length - 1]}`;
};
JavaScriptNot much to it, and definitely not enough code to justify adding a dependency for it. You could probably even golf it down to a one-liner,