'Utility First' Thinking in JavaScript

min read

At 175 words per minute.

2025-07-13 Back to posts

Stylized JS logo with 'Utility First' text

Designing a minimalist, fast, and testable JavaScript library for string and numeric utilities.

Utility First Thinking in JavaScript

There are certain tasks you complete with JavaScript repeatedly when working on enterprise systems. A lot of times, building your own library can be beneficial—it gives you improved control over your code.

In this blog post, I’ll breakdown some code of my new string library (under development) and how it contributes to a utility-first approach in JavaScript that seems to have been lost in the age of frameworks.


Why Build Your Own?

Why write yet another utility library?

I’m curious about about the internal workings of JavaScript—primarily to improve at my day job.

I’ve always been interested in library development, so I figured a good place to start would be a JavaScript string library.

I think this library is performant, offers a lot of educational value through its creation, and is unit tested.


Small, Explicit, Fast

Here is an overview of my library:

  • Minimal footprint – no unnecessary abstractions.
  • Tested behavior – predictable across edge cases.
  • Understandable code – clear even for beginners, well-documented in-code.
  • Reusable patterns – suited for larger apps and libraries.

If you’ve ever written typeof x === 'string' || x instanceof String, you’ve already felt the pain Luniv Strings aims to solve.


Design and Implementation

Let’s go over two different use cases of my library. I decide to tackle the easy methods first.

isString(value)

The purpose of isString is simple:

Check if any value is a string. This is a nice piece of code that can be added to forms as an extra layer of validation around user input, for example.

Below is the implentation:

export default function isString(value) {
  return typeof value === 'string' || value instanceof String;
}

We use instanceof to return a boolean.

Check out the unit tests.

isNumeric(value)

isNumeric has a human approach to solving if a value is a number or not.

The function was the most fun to write so far, as it has a variety of checks.

Below is the implementation:

export default function isNumeric(value) {
  
  if (value === null || value === undefined) {
    return false;
  }

  if (typeof value === 'number') {
    return isFinite(value);
  }

  if (typeof value === 'string' && value.trim() !== '') {
    const num = Number(value);
    return !isNaN(num) && isFinite(num);
  }

  return false;
}

We include a check for strings in the last if block.

This is a human way of evaluating a value: just because it is a string does not mean the value has to be non-numeric.

Check out the unit tests.

Conclusion

Overall, my first attempt to develop a library has been fun. I even started a document website to help beginners. It has been a blast!

Thanks for reading.

Nick Stambaugh

Nick Stambaugh

Full Stack Engineer

Entrepreneur & Enterprise Software Engineer

Recent Posts

I Don't Follow, I Subscribe

For over 7 years, I have almost never engaged with social media. I'm sharing my story to help those who are addicted to social media or need direction in their careers.

2026-04-09

Read more →

#SelfHelp #SocialMedia

Why I Let GitHub Actions Maintain My GitHub Profile README

How manually updating your GitHub profile README quietly fails at scale, and how I use GitHub Actions to keep it accurate, current, and maintenance-free.

2026-01-06

Read more →

#Automation #DevOps #Engineering

Why Your Astro JavaScript Works in Chrome but Breaks in Firefox

How browser inconsistencies in JavaScript APIs can silently tank your Astro site, and why engineers often miss them.

2025-12-25

Read more →

#WebDev #Astro #Frontend #JavaScript

Software Can Stop Losing You Money

How engineers can apply software thinking to maximize sales, reduce errors, and improve business outcomes.

2025-12-25

Read more →

#Business #Tech #Opinion

LunivCore: BI As Code

A lightweight, expressive, efficient, extensible BI language with a Markdown-inspired syntax, powered by a compact C/Lua execution core.

2025-12-5

Read more →

#LunivCore #BIAsCode #C #Lua #BusinessIntelligence

Astro/JS Randomized Banner Icons

A guide to creating dynamic, randomized banner icons.

2025-11-18

Read more →

#Astro #TailwindCSS #WebDev