### Install change-case using npm Source: https://github.com/blakeembrey/change-case/blob/main/packages/change-case/README.md This snippet shows the command to install the 'change-case' package as a project dependency using npm. It is typically used during the project setup phase. ```bash npm install change-case --save ``` -------------------------------- ### Install title-case package Source: https://github.com/blakeembrey/change-case/blob/main/packages/title-case/README.md Installs the 'title-case' package using npm. This is a prerequisite for using the titleCase function in your project. ```bash npm install title-case --save ``` -------------------------------- ### Install swap-case via npm Source: https://github.com/blakeembrey/change-case/blob/main/packages/swap-case/README.md This command installs the 'swap-case' package as a project dependency using npm. It is a prerequisite for using the swapCase function in your JavaScript or TypeScript projects. ```bash npm install swap-case --save ``` -------------------------------- ### Use swapCase function in JavaScript Source: https://github.com/blakeembrey/change-case/blob/main/packages/swap-case/README.md Demonstrates how to import and use the swapCase function from the 'swap-case' package. The function takes a string as input and returns a new string with the case of each character inverted. Examples show its behavior with different string formats. ```javascript import { swapCase } from "swap-case"; swapCase("string"); //=> "STRING" swapCase("dot.case"); //=> "DOT.CASE" swapCase("PascalCase"); //=> "pASCALcASE" ``` -------------------------------- ### Install Sponge Case Source: https://github.com/blakeembrey/change-case/blob/main/packages/sponge-case/README.md Install the sponge-case package using npm. This command adds the package as a dependency to your project. ```bash npm install sponge-case --save ``` -------------------------------- ### Apply Sponge Case Transformation in JavaScript Source: https://context7.com/blakeembrey/change-case/llms.txt Demonstrates how to use the spongeCase function from the 'sponge-case' package to apply random capitalization to strings. It shows examples with basic strings, strings containing numbers and symbols, locale-aware randomization, and a practical use case for generating meme text. ```javascript import { spongeCase } from "sponge-case"; // Random capitalization (output varies each call) spongeCase("hello world"); // e.g., "hElLo WoRLd" or "HeLLO wOrld" spongeCase("string"); // e.g., "sTrinG" or "StRiNg" spongeCase("PascalCase"); // e.g., "pASCaLCasE" // Numbers and symbols unchanged spongeCase("version 1.2.10"); // e.g., "VErSIoN 1.2.10" // Locale-aware randomization spongeCase("hello", "tr"); // Turkish locale handling // Example use case: meme text generator const mockingText = (text) => spongeCase(text); mockingText("I don't always test my code"); // e.g., "i dOn'T AlWaYs tEsT mY CoDe" ``` -------------------------------- ### Convert string to camelCase using change-case Source: https://github.com/blakeembrey/change-case/blob/main/packages/change-case/README.md Demonstrates how to import and use the `camelCase` function from the 'change-case' library. It takes a string as input and returns its camelCased equivalent. This is a fundamental usage example. ```javascript import * as changeCase from "change-case"; changeCase.camelCase("TEST_VALUE"); //=> "testValue" ``` -------------------------------- ### Convert string to title case with JavaScript Source: https://github.com/blakeembrey/change-case/blob/main/packages/title-case/README.md Demonstrates basic usage of the titleCase function from the 'title-case' package. It takes a string as input and returns the string converted to title case. ```javascript import { titleCase } from "title-case"; titleCase("string"); //=> "String" titleCase("follow step-by-step instructions"); //=> "Follow Step-by-Step Instructions" ``` -------------------------------- ### Use Sponge Case Functionality Source: https://github.com/blakeembrey/change-case/blob/main/packages/sponge-case/README.md Demonstrates how to import and use the spongeCase function from the sponge-case package. The function takes a string as input and returns a new string with random capitalization. ```javascript import { spongeCase } from "sponge-case"; spongeCase("string"); //=> "sTrinG" spongeCase("dot.case"); //=> "dOt.caSE" spongeCase("PascalCase"); //=> "pASCaLCasE" spongeCase("version 1.2.10"); //=> "VErSIoN 1.2.10" ``` -------------------------------- ### Core Case Conversion Functions in JavaScript Source: https://context7.com/blakeembrey/change-case/llms.txt Provides 12 built-in methods for converting strings between common programming case formats. Each function accepts an optional options object for customizing delimiter, locale, prefix/suffix handling, and word splitting behavior. Supports locale-aware transformations and handling of ambiguous characters. ```javascript import { camelCase, pascalCase, snakeCase, kebabCase, constantCase, capitalCase, dotCase, pathCase, sentenceCase, noCase, trainCase, pascalSnakeCase, } from "change-case"; // Basic conversions camelCase("hello_world"); // "helloWorld" camelCase("HelloWorld"); // "helloWorld" camelCase("HELLO_WORLD"); // "helloWorld" pascalCase("hello_world"); // "HelloWorld" pascalCase("hello-world"); // "HelloWorld" snakeCase("helloWorld"); // "hello_world" snakeCase("HelloWorld"); // "hello_world" kebabCase("helloWorld"); // "hello-world" kebabCase("Hello World"); // "hello-world" constantCase("helloWorld"); // "HELLO_WORLD" constantCase("hello-world"); // "HELLO_WORLD" capitalCase("helloWorld"); // "Hello World" dotCase("helloWorld"); // "hello.world" pathCase("helloWorld"); // "hello/world" sentenceCase("helloWorld"); // "Hello world" noCase("helloWorld"); // "hello world" trainCase("helloWorld"); // "Hello-World" pascalSnakeCase("helloWorld"); // "Hello_World" // With custom options camelCase("__typename", { prefixCharacters: "_" }); // "__typename" snakeCase("type_", { suffixCharacters: "_" }); // "type_" // Locale-aware conversion camelCase("ISTANBUL", { locale: "tr" }); // Turkish locale handling // Handling version numbers with ambiguous characters pascalCase("V1.2"); // "V1_2" (default: separates numbers) pascalCase("V1.2", { mergeAmbiguousCharacters: true }); // "V12" ``` -------------------------------- ### Transform object keys to camelCase using change-case/keys Source: https://github.com/blakeembrey/change-case/blob/main/packages/change-case/README.md Shows how to use the 'change-case/keys' module to transform the keys of a JavaScript object to camelCase. This is useful for standardizing object structures, especially when dealing with data from different sources. ```javascript import * as changeKeys from "change-case/keys"; changeKeys.camelCase({ TEST_KEY: true }); //=> { testKey: true } ``` -------------------------------- ### Split string into words using change-case utility Source: https://github.com/blakeembrey/change-case/blob/main/packages/change-case/README.md Illustrates the use of the `split` utility function exported by 'change-case'. This function breaks down a string into an array of words, which can then be manipulated further, such as converting to lowercase and joining with a delimiter. ```javascript import { split } from "change-case"; split("fooBar") .map((x) => x.toLowerCase()) .join("_"); //=> "foo_bar" ``` -------------------------------- ### Invert Character Case with swap-case Source: https://context7.com/blakeembrey/change-case/llms.txt The swap-case package inverts the case of each character in a string, converting uppercase to lowercase and vice versa. It supports locale-aware transformations for proper handling of special characters. Dependencies include the 'swap-case' package. ```javascript import { swapCase } from "swap-case"; // Basic swap case swapCase("Hello World"); // "hELLO wORLD" swapCase("helloWorld"); // "HELLOwORLD" swapCase("UPPERCASE"); // "uppercase" swapCase("lowercase"); // "LOWERCASE" // Mixed case swapCase("PascalCase"); // "pASCALcASE" swapCase("camelCase"); // "CAMELcASE" swapCase("dot.case"); // "DOT.CASE" // With numbers and symbols (unchanged) swapCase("Test123"); // "tEST123" swapCase("Hello-World!"); // "hELLO-wORLD!" // Locale-aware swap swapCase("ISTANBUL", "tr"); // Turkish locale handling ``` -------------------------------- ### Convert Strings to Title Case with title-case Source: https://context7.com/blakeembrey/change-case/llms.txt The title-case package converts strings to proper English title case, correctly handling small words, acronyms, URLs, and hyphenated words according to grammatical rules. It supports custom small words, word separators, and sentence case mode. Dependencies include the 'title-case' package. ```javascript import { titleCase, SMALL_WORDS, WORD_SEPARATORS } from "title-case"; // Basic title case titleCase("the quick brown fox"); // "The Quick Brown Fox" titleCase("a tale of two cities"); // "A Tale of Two Cities" titleCase("war and peace"); // "War and Peace" // Handles small words correctly titleCase("the lord of the rings"); // "The Lord of the Rings" titleCase("to kill a mockingbird"); // "To Kill a Mockingbird" titleCase("of mice and men"); // "Of Mice and Men" // Hyphenated words titleCase("step-by-step instructions"); // "Step-by-Step Instructions" titleCase("state-of-the-art technology"); // "State-of-the-Art Technology" // Preserves special cases titleCase("iPhone and iOS devices"); // "iPhone and iOS Devices" titleCase("visit example.com today"); // "Visit example.com Today" titleCase("i.e., for example"); // "I.e., for Example" // Sentence case mode (capitalize only first word of sentences) titleCase("hello world. goodbye world.", { sentenceCase: true }); // "Hello world. Goodbye world." titleCase("first sentence! second one? third here.", { sentenceCase: true }); // "First sentence! Second one? Third here." // Locale-aware transformation titleCase("istanbul", { locale: "tr" }); // Turkish locale // Custom small words const customSmallWords = new Set(["a", "the", "of"]); titleCase("lord of the rings", { smallWords: customSmallWords }); // Custom word separators const customSeparators = new Set(["-", "/"]); titleCase("client/server architecture", { wordSeparators: customSeparators }); // "Client/Server Architecture" ``` -------------------------------- ### String Splitting Utility Functions in JavaScript Source: https://context7.com/blakeembrey/change-case/llms.txt The `split` and `splitSeparateNumbers` functions break any cased string into an array of words, enabling the creation of custom case conversion functions. They intelligently handle various case formats and can separate numbers from words. These utilities can also be integrated with core conversion functions via options. ```javascript import { split, splitSeparateNumbers } from "change-case"; // Basic splitting split("fooBar"); // ["foo", "Bar"] split("FOO_BAR"); // ["FOO", "BAR"] split("foo-bar"); // ["foo", "bar"] split("XMLParser"); // ["XML", "Parser"] split("getHTTPResponse"); // ["get", "HTTP", "Response"] // Separate numbers from words splitSeparateNumbers("test123value"); // ["test", "123", "value"] splitSeparateNumbers("V1Release"); // ["V", "1", "Release"] // Build custom case functions const upperSnake = (str) => split(str).map(x => x.toUpperCase()).join("_"); upperSnake("helloWorld"); // "HELLO_WORLD" const dotLower = (str) => split(str).map(x => x.toLowerCase()).join("."); dotLower("HelloWorld"); // "hello.world" // Custom split with options import { camelCase } from "change-case"; camelCase("test123", { split: splitSeparateNumbers }); // "test_123" ``` -------------------------------- ### Transform Object Keys Recursively with change-case/keys Source: https://context7.com/blakeembrey/change-case/llms.txt The change-case/keys module recursively transforms object keys to a specified case format. It supports depth control for nested objects and arrays, useful for normalizing API responses or converting naming conventions. Dependencies include the 'change-case' package. ```javascript import { camelCase, snakeCase, constantCase, pascalCase, } from "change-case/keys"; // Transform object keys to camelCase const snakeCaseObj = { user_name: "john", user_email: "john@example.com", created_at: "2024-01-01", }; camelCase(snakeCaseObj); // { userName: "john", userEmail: "john@example.com", createdAt: "2024-01-01" } // Transform to snake_case const camelCaseObj = { userName: "john", userEmail: "john@example.com", }; snakeCase(camelCaseObj); // { user_name: "john", user_email: "john@example.com" } // Nested object transformation with depth control const nestedObj = { user_data: { first_name: "John", contact_info: { email_address: "john@example.com", }, }, }; camelCase(nestedObj, 1); // Only transform top-level keys // { userData: { first_name: "John", contact_info: { email_address: "..." } } } camelCase(nestedObj, 2); // Transform 2 levels deep // { userData: { firstName: "John", contactInfo: { email_address: "..." } } } camelCase(nestedObj, Infinity); // Transform all levels // { userData: { firstName: "John", contactInfo: { emailAddress: "..." } } } // Array handling const arrayData = [ { user_id: 1, user_name: "Alice" }, { user_id: 2, user_name: "Bob" }, ]; camelCase(arrayData, 2); // [{ userId: 1, userName: "Alice" }, { userId: 2, userName: "Bob" }] // Transform to CONSTANT_CASE constantCase({ apiKey: "secret", baseUrl: "https://api.com" }); // { API_KEY: "secret", BASE_URL: "https://api.com" } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.