Giter VIP home page Giter VIP logo

change-case's Introduction

Change Case

PHPVersion Tests GitHub license

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

Installation

You can install the package via composer:

composer require realodix/change-case

Usage

use Realodix\ChangeCase\ChangeCase;

Methods Available

Options

Every method that gets 💡 flag, they can support option

  • delimiter: (string) This character separates each chunk of data within the text string. Default: singgle space.
  • splitRx: (RegExp) Used to split into word segments.
  • stripRx: (RegExp) Used to remove extraneous characters.
  • separateNum: (bool) Used to separate numbers or not. Default: false.
  • apostrophe: (bool) Used to separate apostrophe or not. Default: false.

Examples

ChangeCase::header('TestV2', ['separateNum' => true]);
// 'Test-V-2'

camelCase

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

💡 Support options

ChangeCase::camel('test string');
// 'testString'

ChangeCase::camel('1twoThree');
// '1twoThree'
ChangeCase::camel('1twoThree', ['separateNum' => true]);
// '1TwoThree'

CONSTANT_CASE

Transform into upper case string with an underscore between words.

ChangeCase::constant('test string');
// 'TEST_STRING'

dot.case

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

💡 Support options

ChangeCase::dot('test string');
// 'test.string'

Header-Case

Transform into a dash separated string of capitalized words.

💡 Support options

ChangeCase::header('test string');
// 'Test-String'

Headline Case

Transform a strings delimited by casing, hyphens, or underscores into a space delimited string with each word's first letter capitalized.

ChangeCase::headline('test string');
// 'Test String'
ChangeCase::headline('steve_jobs');
// Steve Jobs
ChangeCase::headline('EmailNotificationSent');
// Email Notification Sent

The difference with the title:

ChangeCase::headline('php_v8.3'); // 'Php V8.3'
ChangeCase::title('php_v8.3');    // 'Php_V8.3'

ChangeCase::headline('phpV8.3'); // 'Php V8.3'
ChangeCase::title('phpV8.3');    // 'Phpv8.3'

ChangeCase::headline('_foo_'); // 'Foo'
ChangeCase::title('_foo_');    // '_Foo_'

kebab-case

Transform into a lower cased string with dashes between words.

💡 Support options

ChangeCase::kebab('test string');
// 'test-string'

ChangeCase::kebab('Foo123Bar');
// 'foo123-bar'
ChangeCase::kebab('Foo123Bar', ['separateNum' => true]);
// 'foo-123-bar'

no case

Transform into a lower cased string with spaces between words, and clean up the string from non-word characters.

💡 Support options

ChangeCase::no('testString');
// 'test string'

ChangeCase::no('Foo123Bar')
// foo123 bar
ChangeCase::no('Foo123Bar', ['separateNum' => true])
// foo 123 bar

PascalCase

Transform into a string of capitalized words without separators.

💡 Support options

ChangeCase::pascal('test string');
// 'TestString'

path/case

Transform into a lower case string with slashes between words.

💡 Support options

ChangeCase::path('test string');
// 'test/string'

Sentence case

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

💡 Support options

ChangeCase::sentence('testString');
// 'Test string'

snake_case

Transform into a lower case string with underscores between words.

💡 Support options

ChangeCase::snake('test string');
// 'test_string'

ChangeCase::snake('Foo123Bar');
// 'foo123_bar'
ChangeCase::snake('Foo123Bar', ['separateNum' => true]);
// 'foo_123_bar'

swapCase

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

ChangeCase::swap('Test String');
// 'tEST sTRING'

titleCase

Transform the given string to Title Case:

ChangeCase::title('a simple test');
// 'A Simple Test'

The difference with the headline:

ChangeCase::headline('php_v8.3'); // 'Php V8.3'
ChangeCase::title('php_v8.3');    // 'Php_V8.3'

ChangeCase::headline('phpV8.3'); // 'Php V8.3'
ChangeCase::title('phpV8.3');    // 'Phpv8.3'

ChangeCase::headline('_foo_'); // 'Foo'
ChangeCase::title('_foo_');    // '_Foo_'

License

The MIT License (MIT). Please see License File for more information.

change-case's People

Contributors

realodix 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.