All Projects → yiisoft → strings

yiisoft / strings

Licence: BSD-3-Clause License
String helper methods and an inflector

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to strings

babel-plugin-proposal-pattern-matching
the minimal grammar, high performance JavaScript pattern matching implementation
Stars: ✭ 34 (+9.68%)
Mutual labels:  pattern-matching
yii-gii
Yii code generator extension
Stars: ✭ 27 (-12.9%)
Mutual labels:  yii3
injector
PSR-11 compatible injector
Stars: ✭ 33 (+6.45%)
Mutual labels:  yii3
typy
A fragmentary bidirectional type system as a Python library
Stars: ✭ 51 (+64.52%)
Mutual labels:  pattern-matching
rxjs-ninja
RxJS Operators for handling Observable strings, numbers, booleans and more
Stars: ✭ 68 (+119.35%)
Mutual labels:  string
String.prototype.matchAll
Spec-compliant polyfill for String.prototype.matchAll, in ES2020
Stars: ✭ 14 (-54.84%)
Mutual labels:  string
cache
PSR-16 compatible cache library
Stars: ✭ 30 (-3.23%)
Mutual labels:  yii3
Compute.NET
.NET bindings for native numerical computing
Stars: ✭ 30 (-3.23%)
Mutual labels:  numerical
StringPool
A performant and memory efficient storage for immutable strings with C++17. Supports all standard char types: char, wchar_t, char16_t, char32_t and C++20's char8_t.
Stars: ✭ 19 (-38.71%)
Mutual labels:  string
yii-masked-input
Yii Framework Masked input widget Extension
Stars: ✭ 38 (+22.58%)
Mutual labels:  yii3
files
Useful methods to manage files and directories
Stars: ✭ 27 (-12.9%)
Mutual labels:  yii3
BFSG
BFSG - BruteForce String Generator 😾
Stars: ✭ 16 (-48.39%)
Mutual labels:  string
conditional-expression
JavaScript functional conditional expression
Stars: ✭ 63 (+103.23%)
Mutual labels:  pattern-matching
aho-corasick-node
A Node implementation of the Aho-Corasick string matching algorithm based on DoubleArray Trie.
Stars: ✭ 16 (-48.39%)
Mutual labels:  string
demo
Yii 3 demo application
Stars: ✭ 259 (+735.48%)
Mutual labels:  yii3
db-oracle
Oracle Database support for Yii
Stars: ✭ 21 (-32.26%)
Mutual labels:  yii3
static string
A fixed capacity dynamically sized string
Stars: ✭ 46 (+48.39%)
Mutual labels:  string
siringa
Minimalist dependency injection library for Python that embraces type annotations syntax
Stars: ✭ 51 (+64.52%)
Mutual labels:  pattern-matching
mux-stream
(De)multiplex asynchronous streams
Stars: ✭ 34 (+9.68%)
Mutual labels:  pattern-matching
safe-string-interpolation
A type driven approach to string interpolation, aiming at consistent, secure, and only-human-readable logs and console outputs !
Stars: ✭ 14 (-54.84%)
Mutual labels:  string

Yii Strings


Latest Stable Version Total Downloads Build Status Scrutinizer Code Quality Code Coverage Mutation testing badge static analysis type-coverage

The package provides:

  • StringHelper that has static methods to work with strings;
  • NumericHelper that has static methods to work with numeric strings;
  • Inflector provides methods such as toPlural() or toSlug() that derive a new string based on the string given;
  • WildcardPattern is a shell wildcard pattern to match strings against.

Requirements

  • PHP 7.4 or higher.

Installation

composer require yiisoft/strings --prefer-dist

StringHelper usage

String helper methods are static so usage is like the following:

echo \Yiisoft\Strings\StringHelper::countWords('Strings are cool!'); // 3

Overall the helper has the following method groups.

Bytes

  • byteLength
  • byteSubstring

File paths

  • baseName
  • directoryName

Substrings

  • substring
  • replaceSubstring
  • startsWith
  • startsWithIgnoringCase
  • endsWith
  • endsWithIgnoringCase

Truncation

  • truncateBegin
  • truncateMiddle
  • truncateEnd
  • truncateWords

Counting

  • length
  • countWords

Lowercase and uppercase

  • lowercase
  • uppercase
  • uppercaseFirstCharacter
  • uppercaseFirstCharacterInEachWord

URL friendly base64

  • base64UrlEncode
  • base64UrlDecode

Other

  • split

NumericHelper usage

Numeric helper methods are static so usage is like the following:

echo \Yiisoft\Strings\NumericHelper::toOrdinal(3); // 3rd

The following methods are available:

  • toOrdinal
  • normalize
  • isInteger

Inflector usage

echo (new \Yiisoft\Strings\Inflector())->withoutIntl()->toSlug('Strings are cool!'); // strings-are-cool

Overall the inflector has the following method groups.

Plurals and singulars

  • toPlural
  • toSingular

Transliteration

  • toTransliterated

Case conversion

  • pascalCaseToId
  • toPascalCase
  • toCamelCase

Words and sentences

  • toSentence
  • toWords
  • toHumanReadable

Classes and database tables

  • classToTable
  • tableToClass

URLs

  • toSlug

WildcardPattern usage

WildcardPattern allows a simple POSIX-style string matching.

use \Yiisoft\Strings\WildcardPattern;

$startsWithTest = new WildcardPattern('test*');
if ($startsWithTest->match('testIfThisIsTrue')) {
    echo 'It starts with "test"!';
}

The following characters are special in the pattern:

  • \ escapes other special characters if usage of escape character is not turned off.
  • * matches any string, including the empty string, except delimiters (/ and \ by default).
  • ** matches any string, including the empty string and delimiters.
  • ? matches any single character.
  • [seq] matches any character in seq.
  • [a-z] matches any character from a to z.
  • [!seq] matches any character not in seq.
  • [[:alnum:]] matches POSIX style character classes.

ignoreCase() could be called before doing a match() to get a case-insensitive match:

use \Yiisoft\Strings\WildcardPattern;

$startsWithTest = new WildcardPattern('test*');
if ($startsWithTest->ignoreCase()->match('tEStIfThisIsTrue')) {
    echo 'It starts with "test"!';
}

Testing

Unit testing

The package is tested with PHPUnit. To run tests:

./vendor/bin/phpunit

Mutation testing

The package tests are checked with Infection mutation framework. To run it:

./vendor/bin/infection

Static analysis

The code is statically analyzed with Psalm. To run static analysis:

./vendor/bin/psalm

License

The Yii Strings is free software. It is released under the terms of the BSD License. Please see LICENSE for more information.

Maintained by Yii Software.

Support the project

Open Collective

Follow updates

Official website Twitter Telegram Facebook Slack

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