latest
This commit is contained in:
1 parent
eb0d79d503
commit
b03c1d4619
12446 files changed
+1647557
-24
No files matched your search
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Laravel\Prompts\Concerns;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
trait Truncation
|
||||
{
|
||||
/**
|
||||
* Truncate a value with an ellipsis if it exceeds the given width.
|
||||
*/
|
||||
protected function truncate(string $string, int $width): string
|
||||
{
|
||||
if ($width <= 0) {
|
||||
throw new InvalidArgumentException("Width [{$width}] must be greater than zero.");
|
||||
}
|
||||
|
||||
return mb_strwidth($string) <= $width ? $string : (mb_strimwidth($string, 0, $width - 1).'…');
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user