String helpers with Laravel's Str semantics (BLUEPRINT_V2 §7.12).
Str.slug('Hello World!'); // hello-world
Str.snake('emailVerifiedAt'); // email_verified_at
Str.studly('user_profile'); // UserProfile
Str.plural('category'); // categories
Str.limit('The quick brown fox', 9); // The quick...
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
after(
String subject, String search) → String -
What follows the first
searchinsubject, or all of it without one. -
afterLast(
String subject, String search) → String -
What follows the last
searchinsubject, or all of it without one. -
ascii(
String value) → String -
Replaces common Latin accented letters with ASCII (
Str::ascii, for Latin scripts; other characters are kept). -
before(
String subject, String search) → String -
What precedes the first
searchinsubject, or all of it without one. -
beforeLast(
String subject, String search) → String -
What precedes the last
searchinsubject, or all of it without one. -
between(
String subject, String from, String to) → String -
The part between the first
fromand the lastto. -
camel(
String value) → String -
foo_bar→fooBar. -
contains(
String haystack, Object needles, {bool ignoreCase = false}) → bool -
Whether
haystackcontains any ofneedles(aStringor anIterable<String>). -
containsAll(
String haystack, Iterable< String> needles, {bool ignoreCase = false}) → bool -
Whether
haystackcontains every needle. -
endsWith(
String haystack, Object needles) → bool -
Whether
haystackends with a string, or with one of a list. -
finish(
String value, String cap) → String -
Suffixes
capunless already there (Str::finish). -
headline(
String value) → String -
emailNotificationSent/email_notification_sent→Email Notification Sent. -
isAscii(
String value) → bool -
Whether
valueis 7-bit ASCII only. -
isJson(
String value) → bool -
Whether
valueis valid JSON. -
isUlid(
String value) → bool -
Whether
valueis a ULID. -
isUuid(
String value) → bool -
Whether
valueis a UUID. -
kebab(
String value) → String -
fooBar→foo-bar. -
lcfirst(
String value) → String -
valuewith its first character lower case. -
limit(
String value, [int limit = 100, String end = '...']) → String -
Truncates to
limitcharacters plusend(Str::limit). -
mask(
String value, String character, int index, [int? length]) → String -
Replaces
lengthcharacters fromindexwithcharacter(Str::mask('taylor@example.com', '*', 3)). Negativeindexcounts from the end. -
padBoth(
String value, int length, [String pad = ' ']) → String -
valuepadded on both sides tolengthwithpad. -
padLeft(
String value, int length, [String pad = ' ']) → String -
valuepadded on the left tolengthwithpad. -
padRight(
String value, int length, [String pad = ' ']) → String -
valuepadded on the right tolengthwithpad. -
plural(
String value, [num count = 2]) → String -
English plural of
value(singular whencountis 1), keeping its case (Str::plural). -
pluralStudly(
String value, [num count = 2]) → String -
UserProfile→UserProfiles: pluralizes the last studly word. -
random(
[int length = 16]) → String -
Cryptographically secure alphanumeric string (
Str::random). -
replaceFirst(
String search, String replace, String subject) → String -
subjectwith its firstsearchreplaced. -
replaceLast(
String search, String replace, String subject) → String -
subjectwith its lastsearchreplaced. -
singular(
String value) → String -
English singular of
value(Str::singular). -
slug(
String value, {String separator = '-'}) → String -
URL slug: lower case ASCII, separators collapsed,
@→at. -
snake(
String value, [String delimiter = '_']) → String -
fooBar/Foo Bar→foo_bar(LaravelStr::snake). -
squish(
String value) → String -
Trims and collapses inner whitespace (
Str::squish). -
start(
String value, String prefix) → String -
Prefixes
prefixunless already there (Str::start). -
startsWith(
String haystack, Object needles) → bool -
Whether
haystackstarts with a string, or with one of a list. -
studly(
String value) → String -
foo_bar/foo-bar/foo bar→FooBar. -
title(
String value) → String -
hello world→Hello World. -
trimChars(
String value, String chars) → String -
valuewithout the characters ofcharsat either end. -
ucfirst(
String value) → String -
valuewith its first character upper case. -
ucwords(
String value) → String - Upper-cases the first letter of every whitespace separated word.
-
ulid(
[DateTime? time]) → String - Sortable ULID (26 Crockford base32 characters).
-
uuid(
) → String - Random UUID v4.
-
wordCount(
String value) → int -
The number of words in
value. -
words(
String value, [int count = 100, String end = '...']) → String -
Keeps the first
countwords plusend(Str::words).