String Helpers
This section contains information about functions usable on strings.
#
truncatetruncate(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.0bingo-functional-js
- v0.1.0
Argument(s)
- text (string) - The text to truncate
- limit (integer) - Arbitrary number of characters to include
- JavaScript
- PHP
import { truncate } from 'bingo-functional-js'
const res = truncate( 'Culpa exercitation nostrud dolor est voluptate velit amet qui eiusmod amet et est velit.', 18,)
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);
#
toWordstoWords(text, regex)
toWords :: String -> String -> [String]
Splits a string into an array of words.
Since
bingo-functional
- v1.12.0bingo-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
- JavaScript
- PHP
import { toWords } from 'bingo-functional-js'
const words = toWords('Culpa irure eu occaecat dolor', /[\s]/g)
use function Chemem\Bingo\Functional\toWords;
$words = toWords('Culpa irure eu occaecat dolor', '/[\s]+/');
#
slugifyslugify(text)
slugify :: String -> String
Converts a string to a slug.
Since
bingo-functional
- v1.12.0bingo-functional-js
- v0.1.0
Argument(s)
- text (string) - The text to slugify
- JavaScript
- PHP
import { slugify } from 'bingo-functional-js'
const res = slugify('lorem ipsum')
use function Chemem\Bingo\Functional\slugify;
$result = slugify('lorem ipsum');
#
concatconcat(wildcard, ...strings)
concat :: String -> String -> String
The concat function concatenates strings.
Since
bingo-functional
- v1.12.0bingo-functional-js
- v0.1.0
Argument(s)
- wildcard (string) - The wildcard to use
- text (string) - The text to truncate
- JavaScript
- PHP
import { concat } from 'bingo-functional-js'
const res = concat(' ', 'Kampala', 'is', 'hot')
use function Chemem\Bingo\Functional\concat;
$result = concat(' ', 'Kampala', 'is', 'hot');
#
filePathfilePath(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');
#
startsWithstartsWith(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');
#
endsWithendsWith(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');
#
containscontains(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');