Underpin’s String Helper Can Now Convert strings to camelCase and PascalCase

Posted on:

For my personal site, I realized that I needed a way to convert tags into hashtags, so that when I am showing a social feed I can make my tags look and feel as much like a micro post as possible. In-order to do that, I needed a way to transform a tag like this into ATagLikeThis. This is called PascalCase, which is very similar to camelCase, only the first letter is capitalized in the former, and it's lowercase int he latter.

I decided that the perfect place to put this was inside Underpin's String Helper class, which has loads of little helpers for string manipulation. It's largely inspired by Laravel's helper classes, and works in much the same way. I quite like this update, particularly how it's implemented, because it makes really good use of Underpin's Array Processor class to make the conversion.

This has been added to Underpin 4.1.

If you're not aware of what Underpin is, it's a set of utilities that make developing in non-Laravel applications a little easier. It tries to apply more-modern PHP approaches and helps make it easier to write test-able code. My use case is generally to use it within WordPress, but it is not coupled to WordPress at all, and I have also used it a bit for simple PHP projects as a standalone library.