'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.

Writtten by Nick

Nick Stambaugh

Nick Stambaugh

Full Stack Engineer

Enterprise Software Engineer

Recent Posts

'Utility First' Thinking in JavaScript

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

2025-07-13

Read more →

#JavaScript #Coding #Utilities #LunivStrings

LINQ and Learning To Be Declarative

LINQ is familiar to those who know SQL, but can be jarring to C# newcomers.

2025-04-20

Read more →

C# #Coding #Tech #LINQ

Thoughts on Pop!_OS

My thoughts on the Pop!_OS, as an engineer and gamer.

2025-03-31

Read more →

#Linux #OS #Tech

Why Micromanagement Kills Innovation

Micromanagement of workers, especially software engineers, is detrimental to innovation.

2025-03-19

Read more →

#Workplace #Leadership #Business

Adding Music To My Raylib App

Adding audio to a C application is easy with raylib!

2025-03-13

Read more →

#C #raylib #Coding #Low-Level Development #Tech #Music

Why I Love Houston As A Michigander

Houston is an amazing city to explore with a wide variety of interesting activities, culture, and food.

2025-02-22

Read more →

#Houston #Travel