What is snake-case?
The snake-case npm package is designed to convert strings into snake case format, where each word is lowercased and separated by underscores. This is particularly useful for formatting identifiers in programming languages that favor snake case conventions, such as Python and Ruby, or for generating keys for data formats like JSON that may require consistent naming conventions.
What are snake-case's main functionalities?
Convert string to snake case
This feature allows you to convert any string into snake case, making it lowercased and separating words with underscores. It's useful for formatting strings to meet certain coding standards or data formats.
"Hello World".toSnakeCase(); // 'hello_world'
Custom locale support
The package supports custom locales, enabling the conversion of strings with locale-specific characters into snake case while preserving those characters appropriately.
"Äpfel und Birnen".toSnakeCase({ locale: 'de' }); // 'äpfel_und_birnen'
Other packages similar to snake-case
lodash
Lodash is a comprehensive utility library that includes a `_.snakeCase` function among its string manipulation methods. Compared to snake-case, lodash offers a broader range of functionalities beyond string conversion, making it a more versatile choice for projects requiring multiple utility functions.
change-case
Change-case is a collection of utilities to convert strings between various cases. It includes a `snakeCase` function similar to what snake-case offers. The main difference is that change-case provides a wider array of case conversion options, such as camel case, pascal case, and more, making it suitable for projects that need to handle multiple string case formats.
Snake Case
Transform into a lower case string with underscores between words.
Installation
npm install snake-case --save
Usage
import { snakeCase } from "snake-case";
snakeCase("string");
snakeCase("dot.case");
snakeCase("PascalCase");
snakeCase("version 1.2.10");
The function also accepts options
.
License
MIT