diff --git a/docs/methods.md b/docs/methods.md
index 7236723..8f6bc23 100644
--- a/docs/methods.md
+++ b/docs/methods.md
@@ -87,6 +87,7 @@
- [whenNotExactly ](#whennotexactly)
- [whenIs](#whenis)
- [whenIsAscii](#whenisascii)
+- [whenIsUlid](#whenisulid)
- [whenIsUuid](#whenisuuid)
- [whenTest](#whentest)
- [wordCount](#wordcount)
@@ -95,7 +96,7 @@
- [value](#value)
## Fluent Strings
-### after()
+### after
The `after` method returns everything after the given value in a string.
The entire string will be returned if the value does not exist within the string:
```js
@@ -103,7 +104,7 @@ Stringable.of('This is my name').after('This is');
// ' my name'
```
-### afterLast()
+### afterLast
The `afterLast` method returns everything after the last occurrence of the given value in a string.
The entire string will be returned if the value does not exist within the string:
```js
@@ -111,21 +112,21 @@ Stringable.of('App\\Http\\Controllers\\Controller').afterLast('\\');
// 'Controller'
```
-### append()
+### append
The `append` method appends the given values to the string:
```js
Stringable.of('Taylor').append(' Otwell');
// 'Taylor Otwell'
```
-### ascii()
+### ascii
The `ascii` method will attempt to transliterate the string into an ASCII value:
```js
Stringable.of('ü').ascii();
// 'u'
```
-### basename()
+### basename
The `basename` method will return the trailing name component of the given string:
```js
Stringable.of('/foo/bar/baz').basename();
@@ -138,42 +139,42 @@ Stringable.of('/foo/bar/baz.jpg').basename('.jpg');
// 'baz'
```
-### before()
+### before
The `before` method returns everything before the given value in a string:
```js
Stringable.of('This is my name').before('my name');
// 'This is '
```
-### beforeLast()
+### beforeLast
The `beforeLast` method returns everything before the last occurrence of the given value in a string:
```js
Stringable.of('This is my name').beforeLast('is');
// 'This '
```
-### between()
+### between
The `between` method returns the portion of a string between two values:
```js
Stringable.of('This is my name').between('This', 'name');
// ' is my '
```
-### betweenFirst()
+### betweenFirst
The `betweenFirst` method returns the smallest possible portion of a string between two values:
```js
Stringable.of('[a] bc [d]').betweenFirst('[', ']');
// 'a'
```
-### camel()
+### camel
The `camel` method converts the given string to `camelCase`:
```js
Stringable.of('foo_bar').camel();
// 'fooBar'
```
-### contains()
+### contains
The `contains` method determines if the given string contains the given value. This method is case-sensitive:
```js
Stringable.of('This is my name').contains('my');
@@ -186,14 +187,14 @@ Stringable.of('This is my name').contains(['my', 'foo']);
// true
```
-### containsAll()
+### containsAll
The `containsAll` method determines if the given string contains all the values in the given array:
```js
Stringable.of('This is my name').containsAll(['my', 'name']);
// true
```
-### dirname()
+### dirname
The `dirname` method returns the parent directory portion of the given string:
```js
Stringable.of('/foo/bar/baz').dirname();
@@ -206,7 +207,7 @@ Stringable.of('/foo/bar/baz').dirname(2);
// '/foo'
```
-### dd()
+### dd
The `dd` method dumps the string and ends execution of the script:
```js
Stringable.of('This is my name').dd();
@@ -214,7 +215,7 @@ Stringable.of('This is my name').dd();
// Error: 'This is my name'
```
If you do not want to halt the execution of your script, use the [dump](#dump) method instead.
-### dump()
+### dump
The `dump` method dumps the string:
```js
Stringable.of('This is my name').dump();
@@ -222,7 +223,7 @@ Stringable.of('This is my name').dump();
// 'This is my name'
```
If you want to stop executing the script after dumping the variables, use the [dd](#dd) method instead.
-### excerpt()
+### excerpt
The `excerpt` method extracts an excerpt from the string that matches the first instance of a phrase within that string:
```js
Stringable.of('This is my name').excerpt('my', {
@@ -242,7 +243,7 @@ Stringable.of('This is my name').excerpt('name', {
// '(...) my name'
```
-### endsWith()
+### endsWith
The `endsWith` method determines if the given string ends with the given value:
```js
Stringable.of('This is my name').endsWith('name');
@@ -259,21 +260,21 @@ Stringable.of('This is my name').endsWith(['this', 'foo']);
// false
```
-### exactly()
+### exactly
The `exactly` method determines if the given string is an exact match with another string:
```js
Stringable.of('Laravel').exactly('Laravel');
// true
```
-### explode()
+### explode
The `explode` method splits the string by the given delimiter and returns an array containing each section of the split string:
```js
Stringable.of('foo bar baz').explode(' ');
// ['foo', 'bar', 'baz']
```
-### finish()
+### finish
The `finish` method adds a single instance of the given value to a string if it does not already end with that value:
```js
Stringable.of('this/string').finish('/');
@@ -284,12 +285,12 @@ Stringable.of('this/string/').finish('/');
// 'this/string/'
```
-### flushCache()
+### flushCache
The `flushCache` method removes all strings from the casing caches.
```js
Stringable.flushCache();
```
-### headline()
+### headline
The `headline` method will convert strings delimited by casing, hyphens, or underscores into a space delimited string with each word's first letter capitalized:
```js
Stringable.of('steve_jobs').headline();
@@ -299,7 +300,7 @@ Stringable.of('EmailNotificationSent').headline();
// 'Email Notification Sent'
```
-### is()
+### is
The `is` method determines if a given string matches a given pattern. Asterisks may be used as wildcard values
```js
Stringable.of('foobar').is('foo*');
@@ -310,7 +311,7 @@ Stringable.of('foobar').is(/baz*/);
// false
```
-### isAscii()
+### isAscii
The `isAscii` method determines if a given string is an ASCII string:
```js
Stringable.of('Taylor').isAscii();
@@ -321,7 +322,7 @@ Stringable.of('ü').isAscii();
// false
```
-### isEmpty()
+### isEmpty
The `isEmpty` method determines if the given string is empty:
```js
Stringable.of(' ').trim().isEmpty();
@@ -332,7 +333,7 @@ Stringable.of('Laravel').trim().isEmpty();
// false
```
-### isNotEmpty()
+### isNotEmpty
The `isNotEmpty` method determines if the given string is not empty:
```js
Stringable.of(' ').trim().isNotEmpty();
@@ -343,7 +344,7 @@ Stringable.of('Laravel').trim().isNotEmpty();
// true
```
-### isJson()
+### isJson
The `isJson` method determines if a given string is valid JSON:
```js
Stringable.of('[1,2,3]').isJson();
@@ -358,7 +359,7 @@ Stringable.of('{first: "John", last: "Doe"}').isJson();
// false
```
-### isUlid()
+### isUlid
The `isUlid` method determines if a given string is a valid ULID:
```js
Stringable.of('01ARZ3NDEKTSV4RRFFQ69G5FAV').isUlid();
@@ -369,7 +370,7 @@ Stringable.of('Taylor').isUlid();
// false
```
-### isUuid()
+### isUuid
The `isUuid` method determines if a given string is a UUID:
```js
Stringable.of('5ace9ab9-e9cf-4ec6-a19d-5881212a452c').isUuid();
@@ -380,28 +381,28 @@ Stringable.of('Taylor').isUuid();
// false
```
-### kebab()
+### kebab
The `kebab` method converts the given string to `kebab-case`:
```js
Stringable.of('fooBar').kebab();
// 'foo-bar'
```
-### lcfirst()
+### lcfirst
The `lcfirst` method returns the given string with the first character lowercased:
```js
Stringable.of('Foo Bar').lcfirst();
// 'foo Bar'
```
-### length()
+### length
The `length` method returns the length of the given string:
```js
Stringable.of('Laravel').length();
// 7
```
-### limit()
+### limit
The `limit` method truncates the given string to the specified length:
```js
@@ -415,14 +416,14 @@ Stringable.of('The quick brown fox jumps over the lazy dog').limit(20, ' (...)')
// 'The quick brown fox (...)'
```
-### lower()
+### lower
The `lower` method converts the given string to lowercase:
```js
Stringable.of('LARAVEL').lower();
// 'laravel'
```
-### ltrim()
+### ltrim
The `ltrim` method trims the left side of the string:
```js
Stringable.of(' Laravel ').ltrim();
@@ -433,7 +434,7 @@ Stringable.of('/Laravel/').ltrim('/');
// 'Laravel/'
```
-### markdown()
+### markdown
The `markdown` method converts GitHub flavored Markdown into HTML:
```js
Stringable.of('# Laravel').markdown();
@@ -444,7 +445,7 @@ Stringable.of('# Taylor Otwell').markdown({'html_input': 'strip'});
//
Taylor Otwell
```
-### inlineMarkdown()
+### inlineMarkdown
The `inlineMarkdown` method converts GitHub flavored Markdown into inline HTML.
However, unlike the markdown method, it does not wrap all generated HTML in a block-level element:
```js
@@ -452,7 +453,7 @@ Stringable.of('**Laravel**').inlineMarkdown();
// Laravel
```
-### mask()
+### mask
The `mask` method masks a portion of a string with a repeated character, and may be used to obfuscate
segments of strings such as email addresses and phone numbers:
```js
@@ -467,7 +468,7 @@ Stringable.of('taylor@example.com').mask('*', -15, 3);
// 'tay***@example.com'
```
-### match()
+### match
The `match` method will return the portion of a string that matches a given regular expression pattern:
```js
Stringable.of('foo bar').match('bar');
@@ -478,7 +479,7 @@ Stringable.of('foo bar').match(/foo (.*)/);
// 'bar'
```
-### matchAll()
+### matchAll
The `matchAll` method will return an array containing the portions of a string that match a given regular expression pattern:
```js
Stringable.of('bar foo bar').matchAll('bar');
@@ -492,7 +493,7 @@ Stringable.of('bar fun bar fly').matchAll(/f(\w*)/);
// ['un', 'ly']
```
If no matches are found, an empty array will be returned.
-### newLine()
+### newLine
The `newLine` method appends an "end of line" character to a string:
```js
Stringable.of('Laravel').newLine().append('Framework');
@@ -500,7 +501,7 @@ Stringable.of('Laravel').newLine().append('Framework');
// 'Laravel
// Framework'
```
-### padBoth()
+### padBoth
The `padBoth` method wraps both sides of a string with another string until the final string reaches the desired length:
```js
Stringable.of('James').padBoth(10, '_');
@@ -511,7 +512,7 @@ Stringable.of('James').padBoth(10);
// ' James '
```
-### padLeft()
+### padLeft
The `padLeft` method wraps the left side of a string with another string until the final string reaches the desired length:
```js
Stringable.of('James').padLeft(10, '-=');
@@ -522,7 +523,7 @@ Stringable.of('James').padLeft(10);
// ' James'
```
-### padRight()
+### padRight
The `padRight` method wraps the right side of a string with another string until the final string reaches the desired length:
```js
Stringable.of('James').padRight(10, '-');
@@ -533,14 +534,14 @@ Stringable.of('James').padRight(10);
// 'James '
```
-### parseCallback()
+### parseCallback
The `parseCallback` method parse to an array a `Class@method` style callback into class and method:
```js
Stringable.of('Class@method').parseCallback();
// ['Class', 'method']
```
-### pipe()
+### pipe
The `pipe` method allows you to transform the string by passing its current value to the given callable:
```js
Stringable.of('Laravel').pipe('md5').prepend('Checksum: ');
@@ -551,16 +552,16 @@ Stringable.of('foo').pipe(str => 'bar');
// 'bar'
```
-### plural()
+### plural
Not implemented.
-### prepend()
+### prepend
The `prepend` method prepends the given values onto the string:
```js
Stringable.of('Framework').prepend('Laravel ');
// 'Laravel Framework'
```
-### remove()
+### remove
The `remove` method removes the given value or array of values from the string:
```js
Stringable.of('Arkansas is quite beautiful!').remove('quite');
@@ -568,42 +569,42 @@ Stringable.of('Arkansas is quite beautiful!').remove('quite');
// 'Arkansas is beautiful!'
```
You may also pass `false` as a second parameter to ignore case when removing strings.
-### repeat()
+### repeat
The `repeat` method repeats the given value N times:
```js
Stringable.of('a').repeat('5');
// 'aaaaa'
```
-### replace()
+### replace
The `replace` method replaces a given string within the string:
```js
Stringable.of('Laravel 6.x').replace('6.x', '7.x');
// 'Laravel 7.x'
```
-### replaceArray()
+### replaceArray
The `replaceArray` method replaces a given value in the string sequentially using an array:
```js
Stringable.of('The event will take place between ? and ?').replaceArray('?', ['8:30', '9:00']);
// 'The event will take place between 8:30 and 9:00'
```
-### replaceFirst()
+### replaceFirst
The `replaceFirst` method replaces the first occurrence of a given value in a string:
```js
Stringable.of('the quick brown fox jumps over the lazy dog').replaceFirst('the', 'a');
// 'a quick brown fox jumps over the lazy dog'
```
-### replaceLast()
+### replaceLast
The `replaceLast` method replaces the last occurrence of a given value in a string:
```js
Stringable.of('the quick brown fox jumps over the lazy dog').replaceLast('the', 'a');
// 'the quick brown fox jumps over a lazy dog'
```
-### replaceMatches()
+### replaceMatches
The `replaceMatches` method replaces all portions of a string matching a pattern with the given replacement string:
```js
Stringable.of('(+1) 501-555-1000').replaceMatches(/[^A-Za-z0-9]++/, '')
@@ -617,14 +618,14 @@ Stringable.of('123').replaceMatches(/\d/, match => '['+match[0]+']');
// '[1][2][3]'
```
-### reverse()
+### reverse
The `reverse` method reverses the given string:
```js
Stringable.of('Hello World').reverse();
// 'dlroW olleH'
```
-### rtrim()
+### rtrim
The `rtrim` method trims the right side of the given string:
```js
Stringable.of(' Laravel ').rtrim();
@@ -635,44 +636,44 @@ Stringable.of('/Laravel/').rtrim('/');
// '/Laravel'
```
-### scan()
+### scan
The `scan` method parses input from a string into an array similar to [scan PHP function](https://www.php.net/manual/en/function.sscanf.php):
```js
Stringable.of('filename.jpg').scan('%[^.].%s');
// ['filename', 'jpg']
```
-### singular()
+### singular
Not implemented.
-### slug()
+### slug
The `slug` method generates a URL friendly "slug" from the given string:
```js
Stringable.of('Laravel Framework').slug('-');
// 'laravel-framework'
```
-### snake()
+### snake
The `snake` method converts the given string to `snake_case`:
```js
Stringable.of('fooBar').snake();
// 'foo_bar'
```
-### split()
+### split
The `split` method splits a string into an array using a regular expression:
```js
Stringable.of('one, two, three').split(/[\s,]+/);
// ["one", "two", "three"]
```
-### squish()
+### squish
The `squish` method removes all extraneous white space from a string, including extraneous white space between words:
```js
Stringable.of(' laravel framework ').squish();
// 'laravel framework'
```
-### start()
+### start
The `start` method adds a single instance of the given value to a string if it does not already start with that value:
```js
Stringable.of('this/string').start('/');
@@ -683,28 +684,28 @@ Stringable.of('/this/string').start('/');
// '/this/string'
```
-### startsWith()
+### startsWith
The `startsWith` method determines if the given string begins with the given value:
```js
Stringable.of('This is my name').startsWith('This');
// true
```
-### stripTags()
+### stripTags
The `stripTags` method strips HTML and PHP tags from the given string:
```js
Stringable.of('before
after').stripTags();
// 'beforeafter'
```
-### studly()
+### studly
The `studly` method converts the given string to `StudlyCase`:
```js
Stringable.of('foo_bar').studly();
// 'FooBar'
```
-### substr()
+### substr
The `substr` method returns the portion of the string specified by the given start and length parameters:
```js
Stringable.of('Laravel Framework').substr(8);
@@ -715,14 +716,14 @@ Stringable.of('Laravel Framework').substr(8, 5);
// 'Frame'
```
-### substrCount()
+### substrCount
The `substrCount` method returns the number of occurrences of a given value in the given string:
```js
Stringable.of('If you like ice cream, you will like snow cones.').substrCount('like');
// 2
```
-### substrReplace()
+### substrReplace
The `substrReplace` method replaces text within a portion of a string, starting at the position specified by the second argument
and replacing the number of characters specified by the third argument. Passing `0` to the method's third argument
will insert the string at the specified position without replacing any of the existing characters in the string:
@@ -735,7 +736,7 @@ Stringable.of('The Framework').substrReplace(' Laravel', 3, 0);
// 'The Laravel Framework'
```
-### swap()
+### swap
The `swap` method replaces multiple values in the string similar to PHP `strtr` function:
```js
Stringable.of('Tacos are great!').swap({
@@ -745,7 +746,7 @@ Stringable.of('Tacos are great!').swap({
// 'Burritos are fantastic!'
```
-### tap()
+### tap
The `tap` method passes the string to the given closure, allowing you to examine and interact with the string while
not affecting the string itself. The original string is returned by the `tap` method regardless of what is returned by the closure:
```js
@@ -758,61 +759,61 @@ Stringable.of('Laravel')
// 'LARAVEL FRAMEWORK'
```
-### test()
+### test
The `test` method determines if a string matches the given regular expression pattern:
```js
Stringable.of('Laravel Framework').test(/Laravel/);
// true
```
-### title()
+### title
The `title` method converts the given string to `Title Case`:
```js
Stringable.of('a nice title uses the correct case').title();
// 'A Nice Title Uses The Correct Case'
```
-### toHtmlString()
+### toHtmlString
The `toHtmlString` method converts the string instance to an instance of `Element`, which may be displayed in HTML:
```js
Stringable.of('Nuno Maduro').toHtmlString();
```
-### toString()
+### toString
The `toString` method returns the underlying string value.
```js
Stringable.of('foo').toString();
// 'foo'
```
-### toInteger()
+### toInteger
The `toInteger` method returns string value as an integer.
```js
Stringable.of('123').toInteger();
// 123
```
-### toFloat()
+### toFloat
The `toFloat` method returns string value as a float.
```js
Stringable.of('1').toFloat();
// 1.0'
```
-### toBoolean()
+### toBoolean
The `toBoolean` method returns string value as a boolean.
```js
Stringable.of('yes').toBoolean();
// true
```
-### toDate()
+### toDate
The `toDate` method returns string value as a Date.
```js
Stringable.of('2020-01-01 16:30:25').toDate();
// Date(2020-01-01 16:30:25)
```
-### trim()
+### trim
The `trim` method trims the given string:
```js
Stringable.of(' Laravel ').trim();
@@ -823,28 +824,28 @@ Stringable.of('/Laravel/').trim('/');
// 'Laravel'
```
-### ucfirst()
+### ucfirst
The `ucfirst` method returns the given string with the first character capitalized:
```js
Stringable.of('foo bar').ucfirst();
// 'Foo bar'
```
-### ucsplit()
+### ucsplit
The `ucsplit` method splits the given string into an array by uppercase characters:
```js
Stringable.of('Foo Bar').ucsplit();
// ['Foo', 'Bar']
```
-### upper()
+### upper
The `upper` method converts the given string to uppercase:
```js
Stringable.of('laravel').upper();
// 'LARAVEL'
```
-### when()
+### when
The `when` method invokes the given function if a given condition is `true`. The function will receive the fluent string instance:
```js
Stringable.of('Taylor').when(true, (str) => str.append(' Otwell'));
@@ -852,7 +853,7 @@ Stringable.of('Taylor').when(true, (str) => str.append(' Otwell'));
// 'Taylor Otwell'
```
If necessary, you may pass another function as the third parameter to `when` method. This function will execute if the condition parameter evaluates to `false`.
-### whenContains()
+### whenContains
The `whenContains` method invokes the given function if the string contains the given value. The function will receive the fluent string instance:
```js
Stringable.of('tony stark').whenContains('tony', (str) => str.title());
@@ -867,7 +868,7 @@ Stringable.of('tony stark').whenContains(['tony', 'hulk'], (str) => str.title())
// 'Tony Stark'
```
-### whenContainsAll()
+### whenContainsAll
The `whenContainsAll` method invokes the given function if the string contains all the given sub-strings.
The function will receive the fluent string instance:
```js
@@ -877,7 +878,7 @@ Stringable.of('tony stark').whenContainsAll(['tony', 'stark'], (str) => str.titl
```
If necessary, you may pass another closure as the third parameter to `when` method.
This function will execute if the condition parameter evaluates to `false`.
-### whenEmpty()
+### whenEmpty
The `whenEmpty` method invokes the given function if the string is empty. If the function returns a value,
that value will also be returned by the `whenEmpty` method. If the function does not return a value, the fluent string instance will be returned:
```js
@@ -885,7 +886,7 @@ Stringable.of('').whenEmpty((str) => str.trim().prepend('Laravel'));
// 'Laravel'
```
-### whenNotEmpty()
+### whenNotEmpty
The `whenNotEmpty` method invokes the given function if the string is not empty. If the function returns a value,
that value will also be returned by the `whenNotEmpty` method. If the function does not return a value,
the fluent string instance will be returned:
@@ -894,7 +895,7 @@ Stringable.of('Framework').whenNotEmpty(str => str.prepend('Laravel '));
// 'Laravel Framework'
```
-### whenStartsWith()
+### whenStartsWith
The `whenStartsWith` method invokes the given function if the string starts with the given sub-string.
The function will receive the fluent string instance:
```js
@@ -902,7 +903,7 @@ Stringable.of('disney world').whenStartsWith('disney', (str) => str.title());
// 'Disney World'
```
-### whenEndsWith()
+### whenEndsWith
The `whenEndsWith` method invokes the given function if the string ends with the given sub-string.
The function will receive the fluent string instance:
```js
@@ -910,7 +911,7 @@ Stringable.of('disney world').whenEndsWith('world', (str) => str.title());
// 'Disney World'
```
-### whenExactly()
+### whenExactly
The `whenExactly` method invokes the given function if the string exactly matches the given string.
The function will receive the fluent string instance:
```js
@@ -918,7 +919,7 @@ Stringable.of('laravel').whenExactly('laravel', (str) => str.title());
// 'Laravel'
```
-### whenNotExactly()
+### whenNotExactly
The `whenNotExactly` method invokes the given closure if the string does not exactly match the given string.
The closure will receive the fluent string instance:
```js
@@ -926,7 +927,7 @@ Stringable.of('framework').whenNotExactly('laravel', (str) => str.title());
// 'Framework'
```
-### whenIs()
+### whenIs
The `whenIs` method invokes the given function if the string matches a given pattern. Asterisks may be used as wildcard values.
The function will receive the fluent string instance:
```js
@@ -934,7 +935,7 @@ Stringable.of('foo/bar').whenIs('foo/*', (str) => str.append('/baz'));
// 'foo/bar/baz'
```
-### whenIsAscii()
+### whenIsAscii
The `whenIsAscii` method invokes the given function if the string is 7 bit ASCII.
The function will receive the fluent string instance:
```js
@@ -942,7 +943,15 @@ Stringable.of('A').whenIsAscii((str) => str.prepend('Ascii:'));
// 'Ascii: A'
```
-### whenIsUuid()
+### whenIsUlid
+The `whenIsUlid` method invokes the given function if the string is a valid ULID.
+The function will receive the fluent string instance:
+```js
+Stringable.of('01gd6r360bp37zj17nxb55yv40').whenIsUlid((str) => str.substr(0, 8));
+
+// '01gd6r36'
+```
+### whenIsUuid
The `whenIsUuid` method invokes the given function if the string is a valid UUID.
The function will receive the fluent string instance:
```js
@@ -950,7 +959,7 @@ Stringable.of('2cdc7039-65a6-4ac7-8e5d-d554a98e7b15').whenIsUuid((str) => str.pr
// 'Uuid: 2cdc7039-65a6-4ac7-8e5d-d554a98e7b15'
```
-### whenTest()
+### whenTest
The `whenTest` method invokes the given function if the string matches the given regular expression.
The function will receive the fluent string instance:
```js
@@ -958,28 +967,28 @@ Stringable.of('laravel framework').whenTest(/laravel/, (str) => str.title());
// 'Laravel Framework'
```
-### wordCount()
+### wordCount
The `wordCount` method returns the number of words that a string contains:
```js
Stringable.of('Hello, world!').wordCount();
// 2
```
-### words()
+### words
The `words` method limits the number of words in a string. If necessary, you may specify an additional string that will be appended to the truncated string:
```js
Stringable.of('Perfectly balanced, as all things should be.').words(3, ' >>>');
// 'Perfectly balanced, as >>>'
```
-### wrap()
+### wrap
The `wrap` method wraps the string with the given strings:
```js
Stringable.of('is').wrap('This ', ' me!');
// 'This is me!'
```
-### value()
+### value
The `value` method returns the underlying string value.
```js
Stringable.of('foo').value();
@@ -987,21 +996,21 @@ Stringable.of('foo').value();
// 'foo'
```
## Strings
-### Str.orderedUuid()
+### Str.orderedUuid
Not implemented
-### Str.preg_quote()
+### Str.preg_quote
The `Str.preg_quote` method quote regular expression characters:
```js
Str.preg_quote('*RRRING* Hello?');
// '\*RRRING\* Hello\?'
```
-### Str.random()
+### Str.random
The `Str.random` method generates a random string of the specified length:
```js
Str.random(40);
```
-### Str.createRandomStringsUsing()
+### Str.createRandomStringsUsing
The `Str.createRandomStringsUsing` method allows to intercept and control the random string generation.
```js
Str.createRandomStringsUsing((length) => `xyz|${length}`);
@@ -1009,7 +1018,7 @@ Str.random(7);
// 'xyz:7'
```
-### Str.createRandomStringsUsingSequence()
+### Str.createRandomStringsUsingSequence
The `Str.createRandomStringsUsingSequence` method allows to set a sequence that will be used to generate random strings.
```js
Str.createRandomStringsUsingSequence({0: 'x', 2: 'y', 3: 'z'});
@@ -1021,7 +1030,7 @@ Str.random();
Str.random();
// 'y'
```
-### Str.createRandomStringsNormally()
+### Str.createRandomStringsNormally
The `Str.createRandomStringsNormally` method resets to default random string generator.
```js
Str.createRandomStringsUsing((length) => `xyz|${length}`);
@@ -1030,21 +1039,21 @@ Str.random(7);
// random 7 characters
```
-### Str.substr()
+### Str.substr
The `Str.substr` method returns the portion of string specified by the start and length parameters:
```js
Str.substr('The Laravel Framework', 4, 7);
// 'Laravel'
```
-### Str.uuid()
+### Str.uuid
The `Str.uuid` method generates a UUID (version 4):
```js
Str.uuid();
// Stringable object
```
-### Str.ulid()
+### Str.ulid
The `Str.ulid` method generates a ULID:
```js
Str.ulid();
diff --git a/src/Stringable.ts b/src/Stringable.ts
index 78dd0f0..f8d5b4d 100644
--- a/src/Stringable.ts
+++ b/src/Stringable.ts
@@ -956,6 +956,10 @@ export class Stringable {
return this.when(this.isAscii(), callback, defaultValue);
}
+ public whenIsUlid = (callback: Closure, defaultValue: Closure = null): this => {
+ return this.when(this.isUlid(), callback, defaultValue);
+ }
+
public whenIsUuid = (callback: Closure, defaultValue: Closure = null): this => {
return this.when(this.isUuid(), callback, defaultValue);
}
diff --git a/tests/whenIsUlid.test.js b/tests/whenIsUlid.test.js
new file mode 100644
index 0000000..ccb22c2
--- /dev/null
+++ b/tests/whenIsUlid.test.js
@@ -0,0 +1,28 @@
+'use strict';
+
+const {Stringable} = require('../src/Stringable');
+
+it('returns a passed closure if the string is a valid ULID', () => {
+
+ expect(Stringable.of('01GJSNW9MAF792C0XYY8RX6QFT')
+ .whenIsUlid(
+ stringable => stringable.prepend('Ulid: '),
+ stringable => stringable.prepend('Not Ulid: '),
+ )
+ .toString()
+ ).toBe('Ulid: 01GJSNW9MAF792C0XYY8RX6QFT');
+
+ expect(Stringable.of('2cdc7039-65a6-4ac7-8e5d-d554a98')
+ .whenIsUlid(stringable => stringable.prepend('Ulid: '))
+ .toString()
+ ).toBe('2cdc7039-65a6-4ac7-8e5d-d554a98');
+
+ expect(Stringable.of('ss-01GJSNW9MAF792C0XYY8RX6QFT')
+ .whenIsUlid(
+ stringable => stringable.prepend('Ulid: '),
+ stringable => stringable.prepend('Not Ulid: '),
+ )
+ .toString()
+ ).toBe('Not Ulid: ss-01GJSNW9MAF792C0XYY8RX6QFT');
+
+});
\ No newline at end of file