Skip to main content

String Helpers

This section contains information about functions usable on strings.

truncate#

truncate(text, limit)

truncate :: String -> Int -> String

Outputs an arbitrary number of characters in a string and appends an ellipsis to the resultant string.

Since

  • bingo-functional - v1.12.0
  • bingo-functional-js - v0.1.0

Argument(s)

  • text (string) - The text to truncate
  • limit (integer) - Arbitrary number of characters to include
use function Chemem\Bingo\Functional\truncate;
$result = truncate(  <<<'TXT'  Culpa exercitation nostrud dolor est voluptate  velit amet qui eiusmod amet et est velit.  TXT,  18);

toWords#

toWords(text, regex)

toWords :: String -> String -> [String]

Splits a string into an array of words.

Since

  • bingo-functional - v1.12.0
  • bingo-functional-js - v0.1.0

Argument(s)

  • text (string) - The text to split into words
  • regex (string) - The regex which serves as a rubric for splitting a string
use function Chemem\Bingo\Functional\toWords;
$words = toWords('Culpa irure eu occaecat dolor', '/[\s]+/');

slugify#

slugify(text)

slugify :: String -> String

Converts a string to a slug.

Since

  • bingo-functional - v1.12.0
  • bingo-functional-js - v0.1.0

Argument(s)

  • text (string) - The text to slugify
use function Chemem\Bingo\Functional\slugify;
$result = slugify('lorem ipsum');

concat#

concat(wildcard, ...strings)

concat :: String -> String -> String

The concat function concatenates strings.

Since

  • bingo-functional - v1.12.0
  • bingo-functional-js - v0.1.0

Argument(s)

  • wildcard (string) - The wildcard to use
  • text (string) - The text to truncate
use function Chemem\Bingo\Functional\concat;
$result = concat(' ', 'Kampala', 'is', 'hot');

filePath#

filePath(level, ...components)

filePath :: Int -> String -> String

Outputs an absolute path to a file/directory.

Since

  • bingo-functional - v1.12.0

Argument(s)

  • level (integer) - Directory level relative to a project's root directory
  • component (string) - File path fragment
use function Chemem\Bingo\Functional\filePath;
$path = filePath(0, 'path', 'to', 'file');

startsWith#

startsWith(haystack, needle)

startsWith :: String -> String -> Bool

Checks if a specified string exists at the beginning of another string.

Since:

  • bingo-functional - v1.13.0

Arguments:

  • haystack (string) - The string to search
  • needle (string) - The string sequence to find
use function Chemem\Bingo\Functional\startsWith;
$check = startsWith('functional', 'func');

endsWith#

endsWith(haystack, needle)

endsWith :: String -> String -> Bool

Checks if a specified string exists at the end of another string.

Since:

  • bingo-functional - v1.13.0

Arguments:

  • haystack (string) - The string to search
  • needle (string) - The string sequence to find
use function Chemem\Bingo\Functional\endsWith;
$check = endsWith('function', 'on');

contains#

contains(haystack, needle)

endsWith :: String -> String -> Bool

Checks if a specified string exists in another string.

Since:

  • bingo-functional - v1.13.0

Arguments:

  • haystack (string) - The string to search
  • needle (string) - The string sequence to find
use function Chemem\Bingo\Functional\contains;
$check = contains('function', 'unc');