All Projects → tamtamchik → namecase

tamtamchik / namecase

Licence: MIT License
This package allows you to convert names into the correct case where possible.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to namecase

Laravel-Crud-Generator
A Simple Laravel Library that allows to create crud operation with a single command
Stars: ✭ 20 (-71.43%)
Mutual labels:  composer-package
repl
Framework Agnostic REPL For Node.js. Used by AdonisJS
Stars: ✭ 76 (+8.57%)
Mutual labels:  framework-agnostic
scheduler
Task Scheduler for Laravel applications. UI from scratch
Stars: ✭ 18 (-74.29%)
Mutual labels:  composer-package
php-base-project
A Composer ready package to start a new PHP 7 project
Stars: ✭ 17 (-75.71%)
Mutual labels:  composer-package
picoFeed
PHP library to parse and write RSS/Atom feeds
Stars: ✭ 30 (-57.14%)
Mutual labels:  composer-package
wp-phpunit
WordPress core PHPUnit library. [READ ONLY] Versions for new WordPress releases are built daily.
Stars: ✭ 65 (-7.14%)
Mutual labels:  composer-package
docker-symfony
🐳 Environment for a Symfony application using Docker.
Stars: ✭ 42 (-40%)
Mutual labels:  composer-package
billbee-php-sdk
🔌 The official Billbee API SDK for PHP 💻
Stars: ✭ 14 (-80%)
Mutual labels:  composer-package
graphyne
⚡ Lightning-fast JavaScript GraphQL Server ⚡
Stars: ✭ 18 (-74.29%)
Mutual labels:  framework-agnostic
fence
🔰 Framework-agnostic package who provides powerful ACL abilities to JavaScript
Stars: ✭ 64 (-8.57%)
Mutual labels:  framework-agnostic
aws-upload
🌈 A delicious CLI tool for uploading files to ec2
Stars: ✭ 39 (-44.29%)
Mutual labels:  composer-package
laravel-binlog
Add mysql binlog event listening for Laravel ( 为Laravel框架添加Mysql Binlog事件监听 )
Stars: ✭ 19 (-72.86%)
Mutual labels:  composer-package
docker-magento2
🐳 Environment for a Magento2 application using Docker.
Stars: ✭ 52 (-25.71%)
Mutual labels:  composer-package
qqmap-region
腾讯位置服务中国标准行政区划数据 SDK
Stars: ✭ 22 (-68.57%)
Mutual labels:  composer-package
permissionary
Tiny and framework-agnostic role-based permission management using composition over inheritance
Stars: ✭ 19 (-72.86%)
Mutual labels:  framework-agnostic
php-currency-api
Standardized wrapper for popular currency rate APIs. Currently supports FixerIO, CurrencyLayer, Open Exchange Rates and Exchange Rates API.
Stars: ✭ 17 (-75.71%)
Mutual labels:  composer-package
watson-personality-insights-php
Framework Agnostic Watson Personality Insights Client
Stars: ✭ 13 (-81.43%)
Mutual labels:  framework-agnostic
php-legal-licenses
A utility to help generate a file containing information about dependencies including the full license text.
Stars: ✭ 62 (-11.43%)
Mutual labels:  composer-package
parasut-v4
Parasut Php Api V4
Stars: ✭ 50 (-28.57%)
Mutual labels:  composer-package
phpcsfixer-preset
Use the same php-cs-fixer configuration across all of your projects, with presets for common project layouts (Laravel, Composer packages, etc.).
Stars: ✭ 22 (-68.57%)
Mutual labels:  composer-package

NameCase

Buy Me A Coffee Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

Forenames and surnames are often stored either entirely in UPPERCASE or lowercase. This package allows you to convert names into the correct case where possible. Although forenames and surnames are typically stored separately if they do appear in a single string, whitespace-separated, NameCase deals correctly with them.

Currently NameCase correctly name cases names which include any of the following:

Mc, Mac, al, el, ap, bat, ben, bin, binti, binte, da, de, das, dos, delle, della, di, du, del, der, den, ten, ter, la, le, lo, van and von.

It correctly deals with names which contain apostrophes and hyphens too.

Warning! This README.md is for version 2.0.x.
If you need PHP 5 compatible version, please use 1.0.x! README.md

Install

Via Composer

$ composer require tamtamchik/namecase

Usage

use \Tamtamchik\NameCase\Formatter;

// As a static call
Formatter::nameCase("KEITH");                            // => Keith
Formatter::nameCase("LEIGH-WILLIAMS");                   // => Leigh-Williams
Formatter::nameCase("MCCARTHY");                         // => McCarthy
Formatter::nameCase("O'CALLAGHAN");                      // => O'Callaghan
Formatter::nameCase("ST. JOHN");                         // => St. John
Formatter::nameCase("VON STREIT");                       // => von Streit
Formatter::nameCase("AP LLWYD DAFYDD");                  // => ap Llwyd Dafydd
Formatter::nameCase("HENRY VIII");                       // => Henry VIII
Formatter::nameCase("VAN DYKE");                         // => van Dyke
Formatter::nameCase("JJ ABRAMS");                        // => JJ Abrams
Formatter::nameCase("PRINCE PHILIP, DUKE OF EDINBURGH"); // => Prince Philip, Duke of Edinburgh

// Or as an instance
$formatter = new Formatter();
$formatter->nameCase("LOUIS XIV");          // => Louis XIV

// Passing options
Formatter::setOptions([
  'lazy'        => true,
  'irish'       => true,
  'spanish'     => false,
  'roman'       => true,
  'hebrew'      => true,
  'postnominal' => true,
]);

// Or
$formatter = new Formatter(['spanish' => true]);

// Or 
$formatter->setOptions([
    'lazy' = false, 
    'postnominal' => false
]);

// Or even
Formatter::nameCase("VAN DYKE", ['lazy' = false]);

Options

  • lazy – Default: true. Do not do anything if string is already mixed case and lazy option is true.
  • irish – Default: true. Correct "Mac" exceptions.
  • spanish – Default: false. Correct el, la and spanish conjunctions.
  • roman – Default: true. Correct roman numbers.
  • hebrew – Default: true. Correct ben, bat.
  • postnominal – Default: true. Correct post-nominal e.g. PhD.

Global function

This package used to have global function str_name_case. Now it does not have it anymore. But, if you still need to have it, use this snippet.

<?php

use Tamtamchik\NameCase\Formatter;

if ( ! function_exists('str_name_case')) {

    /**
     * Wrapper for NameCase object to be used as global function.
     *
     * @param string $string  - string to NameCase.
     * @param array  $options - options for NameCase.
     *
     * @return string
     */
    function str_name_case($string, $options = [])
    {
        return Formatter::nameCase($string, $options);
    }
}

Exclude Post-Nominals

<?php

use Tamtamchik\NameCase\Formatter;

Formatter::excludePostNominals('MOst');

Formatter::nameCase('ČERNÝ MOST');

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing & Demo

$ composer tests
$ composer demo

Contributing

Please see CONTRIBUTING and CODE_OF_CONDUCT for details.

Security

If you discover any security-related issues, please email [email protected] instead of using the issue tracker.

Acknowledgements

This library is a port of the Perl library and owes most of its functionality to the Perl version by Mark Summerfield.
I also used some solutions from Ruby version by Aaron Patterson.
Any bugs in the PHP port are my fault.

Credits

Original PERL Lingua::EN::NameCase Version:

  • Copyright © Mark Summerfield 1998-2014. All Rights Reserved.
  • Copyright © Barbie 2014-2019. All Rights Reserved.

Ruby Version:

  • Copyright © Aaron Patterson 2006. All Rights Reserved.

PHP Version:

License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].