Numeronym in JavaScript

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:

  1. Lowercase the string
  2. Remove the spaces from the string
  3. Grab the first character from the string
  4. Grab the last character from the string
  5. Count the number of characters that are left
  6. 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]}`;
};
JavaScript

Not 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,

Josh Sherman - The Man, The Myth, The Avatar

About Josh

Husband. Father. Pug dad. Musician. Founder of Holiday API, Head of Engineering and Emoji Specialist at Mailshake, and author of the best damn Lorem Ipsum Library for PHP.


If you found this article helpful, please consider buying me a coffee.