camelcase vs lodash vs lower-case vs change-case vs upper-case vs change-case-all vs case
String Case Manipulation Comparison
3 Years
camelcaselodashlower-casechange-caseupper-casechange-case-allcaseSimilar Packages:
What's String Case Manipulation?

String case manipulation libraries in JavaScript provide functions to transform the case of strings, such as converting them to camelCase, snake_case, kebab-case, or uppercase/lowercase. These libraries are useful for formatting strings consistently, especially when dealing with user input, APIs, or databases that require specific casing conventions. They help improve code readability, maintainability, and ensure data is presented or stored in the desired format. Examples include camelcase for converting strings to camelCase, lower-case for converting to lowercase, and change-case for a variety of case transformations.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
camelcase109,950,997
69511.2 kB32 years agoMIT
lodash74,737,592
60,959-1215 years agoMIT
lower-case26,521,514
2,3695.08 kB132 years agoMIT
change-case11,461,454
2,36935.9 kB13a year agoMIT
upper-case11,385,963
2,3697.16 kB132 years agoMIT
change-case-all6,028,991
1929.2 kB12 years agoMIT
case994,247
283-75 years ago(MIT OR GPL-3.0-or-later)
Feature Comparison: camelcase vs lodash vs lower-case vs change-case vs upper-case vs change-case-all vs case

Case Transformation

  • camelcase:

    camelcase converts a given string to camelCase format, which is a common convention in JavaScript and programming in general. It takes a string with spaces, underscores, or hyphens and transforms it into camelCase by removing the delimiters and capitalizing the first letter of each subsequent word, except for the first one. This is particularly useful for formatting variable names, function names, or any other identifiers that need to follow the camelCase convention.

  • lodash:

    lodash is a comprehensive utility library that includes a wide range of functions for manipulating arrays, objects, and strings. It provides several case transformation functions, such as _.camelCase, _.snakeCase, and _.kebabCase, among others. While lodash is not solely focused on case manipulation, its extensive feature set and well-optimized functions make it a valuable tool for any JavaScript project. The library is highly regarded for its performance, consistency, and ease of use, making it a staple in the developer community.

  • lower-case:

    lower-case is a simple and efficient library that converts strings to lowercase. It is focused on providing a single transformation with high performance and minimal overhead. The library is lightweight and easy to use, making it a great choice for projects that require quick and reliable lowercase conversion without any additional features or complexity.

  • change-case:

    change-case is a versatile library that provides a wide range of case transformation functions, including camelCase, snake_case, kebab-case, and more. It is designed to be modular, allowing developers to import only the specific case transformation functions they need, which helps keep the bundle size small. The library is particularly useful for projects that require consistent and customizable case transformations for strings, making it a popular choice among developers.

  • upper-case:

    upper-case is a small library that converts strings to uppercase. It provides a straightforward function for transforming any input string into its uppercase equivalent. The library is lightweight and focused on this single task, making it ideal for projects that need a simple and efficient solution for uppercase conversion.

  • change-case-all:

    change-case-all is a unique library that transforms strings into multiple case formats simultaneously. It supports various cases, including camelCase, snake_case, kebab-case, and more, allowing developers to generate all case variations of a string with a single function call. This can be particularly useful for applications that need to display or process strings in multiple formats at once, making it a versatile tool for string manipulation.

  • case:

    case is a simple library that provides functions for transforming strings into different cases, including camelCase, snake_case, and kebab-case. It offers a straightforward API for case conversion, making it easy to use for various string manipulation tasks. The library is lightweight and focuses on providing clear and consistent case transformations without any unnecessary complexity.

Bundle Size

  • camelcase:

    camelcase is a very lightweight library, with a minified size of around 1 KB. Its small size makes it ideal for projects where performance and load times are critical, as it adds minimal overhead to the application.

  • lodash:

    lodash is a large utility library, with a minified size of around 4 KB for the core library. However, its size can be a concern for projects that only need a few functions. To mitigate this, developers can use tree-shaking or import only the specific lodash functions they need to reduce the overall bundle size. Despite its size, lodash is widely used for its performance and versatility across many areas of JavaScript development.

  • lower-case:

    lower-case is a small library with a minimal footprint, making it an excellent choice for projects that prioritize performance and quick load times. Its simplicity and focus on a single function keep the bundle size low, which is beneficial for web applications and environments where every kilobyte counts.

  • change-case:

    change-case is a modular library, which means you can import only the specific case transformation functions you need. This modular design helps keep the bundle size small, especially if you only use a few of its many features. However, the overall size of the library is larger than some single-purpose case transformation libraries due to its comprehensive nature.

  • upper-case:

    upper-case is a lightweight library that adds very little to the bundle size. Its focus on a single functionality (converting strings to uppercase) means that it is efficient and quick to load, making it suitable for performance-sensitive applications.

  • change-case-all:

    change-case-all is designed to be efficient while providing multiple case transformations. Its bundle size is reasonable given the functionality it offers, but it is larger than single-purpose libraries like camelcase or lower-case. The trade-off is worth it for projects that need to generate multiple case formats from a single string.

  • case:

    case is a lightweight library that provides multiple case transformation functions without significantly increasing the bundle size. It is designed to be simple and efficient, making it a good choice for projects that need quick and easy case conversions without bloating the codebase.

Ease of Use: Code Examples

  • camelcase:

    camelcase is straightforward to use, with a simple function that takes a string as input and returns the camelCase version. Its simplicity makes it easy to integrate into any project without a steep learning curve.

    Example:

    const camelcase = require('camelcase');
    
    const input = 'hello world';
    const output = camelcase(input);
    console.log(output); // helloWorld
    
  • lodash:

    lodash is known for its well-designed and consistent API, which makes it easy to use across various functions. The library is well-documented, and its case transformation functions are intuitive for developers familiar with JavaScript.

    Example:

    const _ = require('lodash');
    
    const str = 'hello world';
    const camelCase = _.camelCase(str);
    const snakeCase = _.snakeCase(str);
    const kebabCase = _.kebabCase(str);
    
    console.log(camelCase); // helloWorld
    console.log(snakeCase); // hello_world
    console.log(kebabCase); // hello-world
    
  • lower-case:

    lower-case is extremely easy to use, with a single function that converts any string to lowercase. Its simplicity makes it a go-to choice for quick and reliable lowercase transformations.

    Example:

    const lowerCase = require('lower-case');
    
    const input = 'Hello World';
    const output = lowerCase(input);
    console.log(output); // hello world
    
  • change-case:

    change-case offers a user-friendly API for its various case transformation functions. The modular design allows developers to use only what they need, which simplifies implementation and reduces confusion.

    Example:

    const { camelCase, snakeCase, kebabCase } = require('change-case');
    
    console.log(camelCase('hello world')); // helloWorld
    console.log(snakeCase('hello world')); // hello_world
    console.log(kebabCase('hello world')); // hello-world
    
  • upper-case:

    upper-case is simple to use, with a clear function for converting strings to uppercase. Its straightforward design makes it easy for developers to implement without any confusion.

    Example:

    const upperCase = require('upper-case');
    
    const input = 'Hello World';
    const output = upperCase(input);
    console.log(output); // HELLO WORLD
    
  • change-case-all:

    change-case-all provides an intuitive API for transforming strings into multiple case formats at once. Its documentation clearly explains how to use the library, making it easy for developers to implement.

    Example:

    const changeCaseAll = require('change-case-all');
    
    const input = 'hello world';
    const cases = changeCaseAll(input);
    console.log(cases);
    // { camelCase: 'helloWorld', snake_case: 'hello_world', kebab-case: 'hello-world' }
    
  • case:

    case provides a simple API for case transformations, making it easy to use for developers. Its documentation is clear, which helps users understand how to implement the library quickly.

    Example:

    const { camelCase, snakeCase, kebabCase } = require('case');
    
    console.log(camelCase('hello world')); // helloWorld
    console.log(snakeCase('hello world')); // hello_world
    console.log(kebabCase('hello world')); // hello-world
    
How to Choose: camelcase vs lodash vs lower-case vs change-case vs upper-case vs change-case-all vs case
  • camelcase:

    Choose camelcase if you only need to convert strings to camelCase format. It is lightweight and efficient for this specific task.

  • lodash:

    Choose lodash if you need a full-featured utility library that includes a wide range of functions for case manipulation, as well as many other utilities for working with arrays, objects, and functions. It is ideal for projects that require more than just string manipulation.

  • lower-case:

    Choose lower-case if you need a simple and efficient way to convert strings to lowercase. It is lightweight and focused on this specific transformation, making it easy to use.

  • change-case:

    Choose change-case if you require a comprehensive solution for transforming strings into various cases (e.g., camelCase, snake_case, kebab-case) with a modular design that allows for easy customization.

  • upper-case:

    Choose upper-case if you need to convert strings to uppercase. It is a small and efficient library focused on this single transformation, suitable for projects that require straightforward uppercase conversion.

  • change-case-all:

    Choose change-case-all if you need to transform strings into multiple cases simultaneously (e.g., camelCase, snake_case, kebab-case) and want a library that supports all case types in one package.

  • case:

    Choose case if you need a simple and versatile library that supports multiple case transformations with a straightforward API.

README for camelcase

camelcase

Convert a dash/dot/underscore/space separated string to camelCase or PascalCase: foo-barfooBar

Correctly handles Unicode strings.

If you use this on untrusted user input, don't forget to limit the length to something reasonable.

Install

npm install camelcase

Usage

import camelCase from 'camelcase';

camelCase('foo-bar');
//=> 'fooBar'

camelCase('foo_bar');
//=> 'fooBar'

camelCase('Foo-Bar');
//=> 'fooBar'

camelCase('розовый_пушистый_единорог');
//=> 'розовыйПушистыйЕдинорог'

camelCase('Foo-Bar', {pascalCase: true});
//=> 'FooBar'

camelCase('--foo.bar', {pascalCase: false});
//=> 'fooBar'

camelCase('Foo-BAR', {preserveConsecutiveUppercase: true});
//=> 'fooBAR'

camelCase('fooBAR', {pascalCase: true, preserveConsecutiveUppercase: true});
//=> 'FooBAR'

camelCase('foo bar');
//=> 'fooBar'

console.log(process.argv[3]);
//=> '--foo-bar'
camelCase(process.argv[3]);
//=> 'fooBar'

camelCase(['foo', 'bar']);
//=> 'fooBar'

camelCase(['__foo__', '--bar'], {pascalCase: true});
//=> 'FooBar'

camelCase(['foo', 'BAR'], {pascalCase: true, preserveConsecutiveUppercase: true})
//=> 'FooBAR'

camelCase('lorem-ipsum', {locale: 'en-US'});
//=> 'loremIpsum'

API

camelCase(input, options?)

input

Type: string | string[]

The string to convert to camel case.

options

Type: object

pascalCase

Type: boolean
Default: false

Uppercase the first character: foo-barFooBar

preserveConsecutiveUppercase

Type: boolean
Default: false

Preserve consecutive uppercase characters: foo-BARFooBAR.

locale

Type: false | string | string[]
Default: The host environment’s current locale.

The locale parameter indicates the locale to be used to convert to upper/lower case according to any locale-specific case mappings. If multiple locales are given in an array, the best available locale is used.

import camelCase from 'camelcase';

camelCase('lorem-ipsum', {locale: 'en-US'});
//=> 'loremIpsum'

camelCase('lorem-ipsum', {locale: 'tr-TR'});
//=> 'loremİpsum'

camelCase('lorem-ipsum', {locale: ['en-US', 'en-GB']});
//=> 'loremIpsum'

camelCase('lorem-ipsum', {locale: ['tr', 'TR', 'tr-TR']});
//=> 'loremİpsum'

Setting locale: false ignores the platform locale and uses the Unicode Default Case Conversion algorithm:

import camelCase from 'camelcase';

// On a platform with 'tr-TR'

camelCase('lorem-ipsum');
//=> 'loremİpsum'

camelCase('lorem-ipsum', {locale: false});
//=> 'loremIpsum'

Related