Giter Club home page Giter Club logo

tocase's Introduction

tocase

Convert a string from one case (camel, pascal, snake, kebab) to another case (camel, pascal, snake, kebab, capital, space, dot) with ease.

Installation

With npm

npm install @fougassum/tocase

With yarn

yarn add @fougassum/tocase

With bun

bun install @fougassum/tocase

Basic example

import toCase from '@fougassum/tocase'

const snakeStr = 'to_case_test_string';

const camelStr = toCase(snakeStr, 'camel');
console.log(camelStr) // "toCaseTestString"

const uppercaseKebabStr = toCase(snakeStr, 'uppercaseKebab');
console.log(uppercaseKebabStr) // "TO-CASE-TEST-STRING"

Supported cases

You can currently convert strings from those cases :

  • Camel case (camelCase)
  • Pascal case (PascalCase)
  • Snake case (snake_case)
  • Kebab case (kebab-cace)

To those cases :

  • 'camel' : Camel case (camelCase)
  • 'pascal' : Pascal case (PascalCase)
  • 'snake' : Snake case (snake_case)
  • 'uppercaseSnake' : Uppercase snake case (UPPERCASE_SNAKE_CASE)
  • 'kebab' : Kebab case (kebab_cace)
  • 'uppercaseKebab' : Uppercase kebab case (UPPERCASE_KEBAB_CASE)
  • 'capital' : Capital case (Capital Case)
  • 'spaceCase' : Space case (space case)
  • 'uppercaseSpace' : Uppercase space case (UPPERCASE SPACE CASE)
  • 'dot' : Dot case (dot.case)
  • 'uppercaseDog : Uppercase dot case (UPPERCASE.DOT.CASE)

Importing utils functions

You can also import all utils functions to convert a string to a splitted array of strings, and the ones to convert back to a string.

import { fromCamel, toSnake } from '@fougassum/tocase';

const str = 'welcomeToFrance';
const splitted = fromCamel(str);
const snakeStr = toSnake(splitted);

console.log(snakeStr); // 'welcome_to_france'

tocase's People

Contributors

gabinbernard avatar

Watchers

 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.