Detect if a String is in camelCase Format in Javascript or Node.js

Detecting if a JavaScript string value is in camelCase is likely an edge case. Yet, it can be a valid check in your codebase. This tutorial shows you how to determine whether a given string is in camelCase format.

Node.js Series Overview

  1. Check if a Value is a Symbol in JavaScript or Node.js (Coming soon)
  1. Detect if Running on Linux (Coming soon)
  2. Detect if Running on macOS (Coming soon)
  3. Detect if Running on Windows (Coming soon)
  4. Check if Running on 64bit or 32bit Platform (Coming soon)
  1. How to Download a File (Coming soon)

Detect if a String Value is in camelCase

You should use the @supercharge/strings package to determine whether a given string is in camelCase format.

I’m the maintainer @supercharge/strings package which provides convenient string utilities. It comes a useful Str#isCamel() method detecting whether a given string value is in camelCase format:

const Str = require('@supercharge/strings')

// true

// false

The implementation follows a basic idea: compare the given value against its camelCase’d version. The comparison returns true if both strings are identical and false otherwise.

Creating the camelCase version of a string value follows this idea:

  • replace symbols (like dashes and underscores) with a space
  • uppercase the first letter of each word
  • remove all spaces from the string
  • lowercase the first character

That’s it!

Mentioned Resources

Explore the Library

Find interesting tutorials and solutions for your problems.