Code Monkey home page Code Monkey logo

56_npm_change-case's Introduction

Change Case

Build status

Transform a string between camelCase, PascalCase, Capital Case, snake_case, param-case, CONSTANT_CASE and others.

Installation

npm install change-case --save

Usage

import * as changeCase from "change-case";

Core

These functions come bundled with change-case:

All core methods accept options as the second argument.

Transform into a string with the separator denoted by the next word capitalized.

camelCase("test string");
//=> "testString"

Transform into a space separated string with each word capitalized.

capitalCase("test string");
//=> "Test String"

Transform into upper case string with an underscore between words.

constantCase("test string");
//=> "TEST_STRING"

Transform into a lower case string with a period between words.

dotCase("test string");
//=> "test.string"

Transform into a dash separated string of capitalized words.

headerCase("test string");
//=> "Test-String"

Transform into a lower cased string with spaces between words.

noCase("testString");
//=> "test string"

Transform into a lower cased string with dashes between words.

paramCase("test string");
//=> "test-string"

Transform into a string of capitalized words without separators.

pascalCase("test string");
//=> "TestString"

Transform into a lower case string with slashes between words.

pathCase("test string");
//=> "test/string"

Transform into a lower case with spaces between words, then capitalize the string.

sentenceCase("testString");
//=> "Test string"

Transform into a lower case string with underscores between words.

snakeCase("test string");
//=> "test_string"

Other Case Utilities

These functions are not "case" libraries but independent functions, you must install these separately.

Transform a string into title case following English rules.

titleCase("a simple test");
//=> "A Simple Test"

Transform a string by swapping every character from upper to lower case, or lower to upper case.

swapCase("Test String");
//=> "tEST sTRING"

Returns true if the string is lower case only.

isLowerCase("test string");
//=> true

Returns true if the string is upper case only.

isUpperCase("test string");
//=> false

Transforms the string to lower case.

lowerCase("TEST STRING");
//=> "test string"

Transforms the string with the first character in lower cased.

lowerCaseFirst("TEST");
//=> "tEST"

Transforms the string to upper case.

upperCase("test string");
//=> "TEST STRING"

Transforms the string with the first character in upper cased.

upperCaseFirst("test");
//=> "Test"

Transform into a string with random capitalization applied.

spongeCase("Test String");
//=> "tEst stRINg"

Options

  • splitRegexp RegExp used to split into word segments (see example).
  • stripRegexp RegExp used to remove extraneous characters (default: /[^A-Z0-9]/gi).
  • delimiter Value used between words (e.g. " ").
  • transform Used to transform each word segment (e.g. lowerCase).

Split Example

If you find the default split hard to use, you can provide a different one. The example below will change the behavior to word2019 -> word 2019 and minifyURLs -> minify urls:

const options = {
  splitRegexp: /([a-z])([A-Z0-9])/g,
};

Related

License

MIT

56_npm_change-case's People

Contributors

ep-infosec avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.