Download the PHP package dakujem/shorts without Composer
On this page you can find all versions of the php package dakujem/shorts. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package shorts
🩳 shorts
Use this tool to shorten or limit personal names to desired length, or to use initials instead of a full name.\ Supports Unicode / UTF-8 names.
-
limit / cap name length (with the aim to keep the name as legible as possible):
-
shorten a name using initials for part of the name (no length constraint):
- create initials (configurable separator):
well i could not google out anything reasonable in well over 60 minutes so i decided to code it in less than that. how silly i was...
TODO / in progress
The features and the public interface are in place. The code is still ugly, don't fret. 🙊
I'm also deciding how to make it possible for a custom name parser to be provided on the fly/by configuration, so that special cases (like compound names) can easily be supported. Bear with me. 🐻
Supported:
- unicode names
- arbitrary length
What is not (yet) supported:
- compound surnames (sorry folks, this may come later)
- non-word characters will be lost
Bull, John
- academic and other titles
Bc. Foo Bar, Dr.Sc.
John Bull, Sr.
- other writing systems than latin (may the will work, i'm just not testing them)
You will need to handle these yourself before/after passing them through the shortener.
Usage
Limit (cap) names to desired lengths:
The above will try to keep the last name legible, unless the limit is too strict.\ Inverse version that will try to keep the first name legible is also available:
Shrink names using initials except for the last name:
Shrink names using initials except for the first name:
Create "short" initials:
... or "longer" version:
Each of the static methods has a non-static counterpart:
Shorts also provides the ability co create a preconfigured formatter callable for each of the methods:
These can be used as follows:
Note the formatters can come handy when defining filters for templating languages, like Twig or Latte.
Testing
$
composer test
Contributions
... are always welcome. Many times it is useful to just point out a use case the author have not thought about or come across.
Possible future stuff
- include a name parser to split the names
- https://github.com/joshfraser/PHP-Name-Parser
- https://github.com/theiconic/name-parser
- in fact i intend to provide a possibility to use your own explode/implode functions so that the tool is as flexible as possible