Convert strings between 13 naming conventions: Snake case, Camel case, Kebab case, Pascal case, Ada case, Train case, Cobol case, Macro case, Upper case, Lower case, Title case, Sentence case and Dot notation.

Overview

Case converter

Use this library to convert string between:

Name Method Output example
🐪 Camel case toCamel() myNameIsBond
👨‍🏫 Pascal case toPascal() MyNameIsBond
🐍 Snake case toSnake() my_name_is_bond
👩‍🏫 Ada case toAda() My_Name_Is_Bond
Ⓜ️ Macro case toMacro() MY_NAME_IS_BOND
🥙 Kebab case toKebab() my-name-is-bond
🚂 Train case toTrain() My-Name-Is-Bond
🏦 Cobol case toCobol() MY-NAME-IS-BOND
🔡 Lower case toLower() my name is bond
🔠 Upper case toUpper() MY NAME IS BOND
📰 Title case toTitle() My Name Is Bond
✍️ Sentence case toSentence() My name is bond
⚙️ Dot notation toDot() my.name.is.bond

Features:

Latest Stable Version PHP from Packagist Build Status Build Status Build Status Maintainability Test Coverage Total Downloads Monthly Downloads Daily Downloads PHPPackages Rank PHPPackages Referenced By Average time to resolve an issue Percentage of issues still open License composer.lock PDS Skeleton Issues HitCount

Usage

Input string (i.e. john-connor) format is going to be detected automatically. Here's an example:

use Jawira\CaseConverter\Convert;

$hero = new Convert('john-connor');

echo $hero->toCamel();   // output: johnConnor

Of course you can explicitly set the format of input string:

echo $hero->fromKebab()->toSnake();   // output: john_connor

You can also use the provided factory to instantiate Convert class. A list of all public methods is also available.

i18n

Fully compatible with non-english alphabets:

// Spanish
$esp = new Convert('DON_RAMÓN_Y_ÑOÑO');
echo $esp->toCamel();   // output: donRamónYÑoño

// Greek
$grc = new Convert('πολύ-Καλό');
echo $grc->toCamel();   // output: πολύΚαλό

// Russian
$rus = new Convert('ОЧЕНЬ_ПРИЯТНО');
echo $rus->toCamel();   // output: оченьПриятно

case-converter is compatible with Simple Case-Mapping and Full Case-Mapping. Learn more about Case-Mapping.

Installation

$ composer require jawira/case-converter

Documentation

https://jawira.github.io/case-converter/

Contributing

  • If you liked this project, star it on GitHub.
  • Pull requests and issues are welcomed.

Contributors

Contributors

License

This library is licensed under the MIT LICENSE.


Packages from jawira

jawira/emoji-catalog (library)
Get access to +3000 emojis as class constants.
jawira/phing-visualizer (library)
Graphical representation of Phing's buildfile.
jawira/phing-open-task (library)
Phing task to open files, directories, and URLs with your favorite software.
more...
Comments
  • SOLID

    SOLID

    I can't easily inject the functionality this package provides as a dependency to one of my classes because I have to create a new instance every time I want to perform a conversion. This breaks the inversion of control principle of SOLID.

    To use this properly I'd have to make a factory and inject it everywhere which is definitely sub-optimal.

    4 - Done 
    opened by chrisharrison 5
  • ext-mbstring replaced with polyfill

    ext-mbstring replaced with polyfill

    Just idea. But I think it's useful

    as you can see, I have some problems with pipelines. It looks like problem with gh rate limit, so it's not a problem with source code

    opened by vanodevium 3
  • Upgrade travis configuration

    Upgrade travis configuration

    Please be aware travis-ci.org will be shutting down in several weeks, with all accounts migrating to travis-ci.com. Please stay tuned here for more information.

    opened by szepeviktor 2
  • pascal case

    pascal case "error404" is converted to sentence case "Error404" instead of "Error 404"

    This one is a ltitle bit tricky because it seems on the internet all case converters are producing the same output, which bugs me.

    How is a sentence case algorithm not considering words ending with numbers 2 seperate entities, and "__toString" will trim the underscores, but still produce a single word (https://github.com/jawira/case-converter/issues/84)? Seems like there is something I do not get with the logic.

    opened by khalyomede 0
  • pascal case

    pascal case "__toString" is converted to sentence case "Tostring" instead of "To string"

    The following reproduction code will show the issue:

    use Jawira\CaseConverter\Convert;
    
    require __DIR__ . "/vendor/autoload.php";
    
    $original = "__toString";
    $text = new Convert($original);
    $expected = "To string";
    $sentence = $text->toSentence();
    
    echo $expected === $sentence
        ? "$expected === $sentence" . PHP_EOL
        : "Expected $sentence to be $expected";
    
    echo PHP_EOL;
    
    Expected Tostring to be To string
    

    Is it expected?

    FYI here is how one NPM package handles it (as expected in my opinion)

    Capture d’écran du 2022-09-03 18-07-13

    opened by khalyomede 0
Releases(v3.5.1)
  • v3.5.1(Aug 14, 2022)

    What's Changed

    • refactor: Use arrow function in Gluer::changeWordsCase by @jawira in https://github.com/jawira/case-converter/pull/83

    Full Changelog: https://github.com/jawira/case-converter/compare/v3.5.0...v3.5.1

    Source code(tar.gz)
    Source code(zip)
  • v3.5.0(Jun 26, 2022)

    What's Changed

    • feat: Bump minimum PHP version to 7.4 by @jawira in https://github.com/jawira/case-converter/pull/82
    • docs: Update Full case-mapping documentation

    Full Changelog: https://github.com/jawira/case-converter/compare/v3.4.6...v3.5.0

    Source code(tar.gz)
    Source code(zip)
  • v3.4.6(Nov 21, 2021)

    What's Changed

    • Update documentation by @jawira in https://github.com/jawira/case-converter/pull/80
    • Reformat documentation by @jawira in https://github.com/jawira/case-converter/pull/81

    Full Changelog: https://github.com/jawira/case-converter/compare/v3.4.5...v3.4.6

    Source code(tar.gz)
    Source code(zip)
  • v3.4.5(Nov 17, 2021)

    What's Changed

    • Remove travis by @jawira in https://github.com/jawira/case-converter/pull/74
    • Config gitlab ci by @jawira in https://github.com/jawira/case-converter/pull/75
    • Fix psalm by @jawira in https://github.com/jawira/case-converter/pull/77
    • Deploy docs to github pages by @jawira in https://github.com/jawira/case-converter/pull/78
    • Update gitattributes by @jawira in https://github.com/jawira/case-converter/pull/79

    Full Changelog: https://github.com/jawira/case-converter/compare/v3.4.4...v3.4.5

    Source code(tar.gz)
    Source code(zip)
  • v3.4.4(Nov 12, 2021)

    What's Changed

    • Move phpunit to dev dependencies by @jawira in https://github.com/jawira/case-converter/pull/73

    Full Changelog: https://github.com/jawira/case-converter/compare/v3.4.3...v3.4.4

    Source code(tar.gz)
    Source code(zip)
  • v3.4.3(Nov 4, 2021)

    What's Changed

    • Upgrade travis configuration by @szepeviktor in https://github.com/jawira/case-converter/pull/68
    • Add rector.php to .gitattributes by @jawira in https://github.com/jawira/case-converter/pull/70
    • Removing Phive by @jawira in https://github.com/jawira/case-converter/pull/71
    • Update README.md by @jawira in https://github.com/jawira/case-converter/pull/72

    Full Changelog: https://github.com/jawira/case-converter/compare/v3.4.2...v3.4.3

    Source code(tar.gz)
    Source code(zip)
  • v3.4.2(Jan 5, 2021)

    What's Changed

    • Railroad by @jawira in https://github.com/jawira/case-converter/pull/56
    • Refactoring buildfile #55 by @jawira in https://github.com/jawira/case-converter/pull/57
    • Add /.idea to .gitattributes #58 by @jawira in https://github.com/jawira/case-converter/pull/59
    • Add rector by @jawira in https://github.com/jawira/case-converter/pull/62
    • Update readme #60 by @jawira in https://github.com/jawira/case-converter/pull/63
    • Add php8 in composer.json #66 by @jawira in https://github.com/jawira/case-converter/pull/67

    Full Changelog: https://github.com/jawira/case-converter/compare/v3.4.1...v3.4.2

    Source code(tar.gz)
    Source code(zip)
Owner
Jawira Portugal
I prefer GitLab, but most open source project are here 🤷‍♂️.
Jawira Portugal
Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a unified way.

String Component The String component provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a un

Symfony 1.3k Dec 29, 2022
PHP library to detect and manipulate indentation of strings and files

indentation PHP library to detect and manipulate the indentation of files and strings Installation composer require --dev colinodell/indentation Usage

Colin O'Dell 34 Nov 28, 2022
Multibyte strings as objects

Opis String Multibyte strings Opis String is a tiny library that allows you to work with multibyte encoded strings in an object-oriented manner. The l

Opis 58 Oct 6, 2022
The Universal Device Detection library will parse any User Agent and detect the browser, operating system, device used (desktop, tablet, mobile, tv, cars, console, etc.), brand and model.

DeviceDetector Code Status Description The Universal Device Detection library that parses User Agents and detects devices (desktop, tablet, mobile, tv

Matomo Analytics 2.4k Jan 5, 2023
Extensive, portable and performant handling of UTF-8 and grapheme clusters for PHP

Patchwork UTF-8 for PHP Patchwork UTF-8 gives PHP developpers extensive, portable and performant handling of UTF-8 and grapheme clusters. It provides

Nicolas Grekas 80 Sep 28, 2022
php-crossplane - Reliable and fast NGINX configuration file parser and builder

php-crossplane Reliable and fast NGINX configuration file parser and builder ℹ️ This is a PHP port of the Nginx Python crossplane package which can be

null 19 Jun 30, 2022
A tiny PHP class-based program to analyze an input file and extract all of that words and detect how many times every word is repeated

A tiny PHP class-based program to analyze an input file and extract all of that words and detect how many times every word is repeated

Max Base 4 Feb 22, 2022
A PHP class which allows the decoding and encoding of a wider variety of characters compared to the standard htmlentities and html_entity_decode functions.

The ability to encode and decode a certain set of characters called 'Html Entities' has existed since PHP4. Amongst the vast number of functions built into PHP, there are 4 nearly identical functions that are used to encode and decode html entities; despite their similarities, however, 2 of them do provide additional capabilities not available to the others.

Gavin G Gordon (Markowski) 2 Nov 12, 2022
A lightweight php class for formatting sql statements. Handles automatic indentation and syntax highlighting.

SqlFormatter A lightweight php class for formatting sql statements. It can automatically indent and add line breaks in addition to syntax highlighting

Jeremy Dorn 3.9k Jan 1, 2023
Converts a string to a slug. Includes integrations for Symfony, Silex, Laravel, Zend Framework 2, Twig, Nette and Latte.

cocur/slugify Converts a string into a slug. Developed by Florian Eckerstorfer in Vienna, Europe with the help of many great contributors. Features Re

Cocur 2.8k Dec 22, 2022
A fast PHP slug generator and transliteration library that converts non-ascii characters for use in URLs.

URLify for PHP A fast PHP slug generator and transliteration library, started as a PHP port of URLify.js from the Django project. Handles symbols from

Aband*nthecar 667 Dec 20, 2022
ColorJizz is a PHP library for manipulating and converting colors.

#Getting started: ColorJizz-PHP uses the PSR-0 standards for namespaces, so there should be no trouble using with frameworks like Symfony 2. ###Autolo

Mikeemoo 281 Nov 25, 2022
Library for free use Google Translator. With attempts connecting on failure and array support.

GoogleTranslateForFree Packagist: https://packagist.org/packages/dejurin/php-google-translate-for-free Library for free use Google Translator. With at

Yurii De 122 Dec 23, 2022
:clamp: HtmlMin: HTML Compressor and Minifier via PHP

??️ HtmlMin: HTML Compressor and Minifier for PHP Description HtmlMin is a fast and very easy to use PHP library that minifies given HTML5 source by r

Lars Moelleken 135 Dec 8, 2022
A lightweight php class for formatting sql statements. Handles automatic indentation and syntax highlighting.

SqlFormatter A lightweight php class for formatting sql statements. It can automatically indent and add line breaks in addition to syntax highlighting

Jeremy Dorn 3.9k Jan 3, 2023
Highlight trailing spaces and delete them in a flash.

Trailing Spaces A Sublime Text plugin that allows you to… highlight trailing spaces and delete them in a flash! Synopsis Installation Alternative inst

Sublime Text Packages 884 Jan 4, 2023
Tutorial for computer vision and machine learning in PHP 7/8 by opencv (installation + examples + documentation)

Examples detect face by cascade classifier detect face by pretrained caffe model res10_300x300_ssd by ddn module detect facemarks by LBF algorithm rec

null 409 Dec 25, 2022
A PHP string manipulation library with multibyte support. Compatible with PHP 5.4+, PHP 7+, and HHVM.

A PHP string manipulation library with multibyte support. Compatible with PHP 5.4+, PHP 7+, and HHVM. s('string')->toTitleCase()->ensureRight('y') ==

Daniel St. Jules 2.5k Dec 28, 2022
FileNamingResolver - A lightweight library which helps to resolve a file/directory naming of uploaded files using various naming strategies

FileNamingResolver - A lightweight library which helps to resolve a file/directory naming of uploaded files using various naming strategies

Victor Bocharsky 111 May 19, 2022
Methods to allow the mapping of cases to snake / camel for input / output

Methods to allow the mapping of cases to snake / camel for input / output This is where your description should go. Limit it to a paragraph or two. Co

Craig Smith 4 Aug 31, 2022