strrr
Functional string utilities, inspired by Laravel's Str
helpers.
Installation
yarn add strrr
Usage
chainability built in. e.g.
title ; // = 'Lorem Ipsu…'
Available Methods
limit
Limit a string to a given length with a suffix (ellipsis).
Method signature
limit(limit = 100, end = '…');
; ;// = 'Lorem ipsum dolor si…'
words
Limit the number of words in a string with a suffix (ellipsis).
Method signature
words(words = 100, end = '…');
; ;// = 'Lorem ipsum dolor…'
random
Generate a "random" alpha-numeric string.
Method signature
random(length = 32)
; ; // = 'nKusDo5JIFrI1tJswwzpEyGLpvML1Mxp'; // = 'Ky6zJuGnGyrnvw1y'
title
Convert the string to Title case.
Method signature
title()
; title;// = 'Lorem Ipsum Dolor Sit Amet'
studly
Convert the string to Studly case. Also known as pascal case
Method signature
studly()
; ;// = 'LoremIpsumDolorSitAmet'
camel
Convert the string to camel case
Method signature
camel()
; ;// = 'loremIpsumDolorSitAmet'
snake
Convert the string to snake case
Method signature
snake(delimeter = '_')
; ;// = 'lorem_ipsum_dolor_sit_amet'
kebab
Convert the string to kebab case - Which is similar to snake case but with dashes.
Method signature
kebab()
; ;// = 'lorem-ipsum-dolor-sit-amet'
ucfirst
Capitalize the first character in a string.
Method signature
ucfirst()
; ; // = 'Foo bar'
lcfirst
lower case the first character in a string.
Method signature
lcfirst()
; ; // = 'lorem ipsum'
contains
Determine if a given string contains a given string.
Method signature
contains(val, position = 0)
; ; // = true; // = false
startsWith
Determine if a given string starts with a given string.
Method signature
startsWith(val, position = 0)
; // = true // = false
endsWith
Determine if a given string ends with a given string.
Method signature
endsWith(val, position = 0)
; ; // = true; // = false
isLowerCase
Determine if the string is lowercase.
Method signature
isLowerCase()
; ; // = true; // = false
isUpperCase
Determine if the string is uppercase.
Method signature
isUpperCase()
; ; // = true; // = false
strip
Strip all whitespace from a string.
Method signature
strip()
; // = 'Loremipsumdolorsitamet'
ascii
Transliterate a UTF-8 value to ASCII.
Method signature
ascii()
; // = 'I love javascript' // = 'atde-0ff'
slug
Generate a URL friendly "slug" from the string.
Method signature
slug(separator = '-')
; // = 'foo-bar-baz' // = 'i_love_javascript'