Skip to content

Commit

Permalink
Resolve merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
BMTmohammedtaha committed Dec 1, 2023
2 parents 683ab77 + 145a7cd commit 76707bc
Show file tree
Hide file tree
Showing 5 changed files with 249 additions and 1 deletion.
198 changes: 198 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
# to-string PHP Library

`to-string` is a PHP library that provides various utility classes for string manipulation and conversion. It offers functionality to convert text case, strip tags, generate slugs, format arrays, and handle date/time values.

## Installation

You can install the `to-string` library via Composer. Run the following command in your project directory:

```
composer require effectra/to-string
```

## Usage

### TextToString

#### `toUppercase(string $text): string`

Converts a string to uppercase.

```php
use Effectra\ToString\TextToString;

$textToString = new TextToString();
$result = $textToString->toUppercase('Hello, World!');
echo $result; // Output: HELLO, WORLD!
```

#### `toLowercase(string $text): string`

Converts a string to lowercase.

```php
use Effectra\ToString\TextToString;

$textToString = new TextToString();
$result = $textToString->toLowercase('Hello, World!');
echo $result; // Output: hello, world!
```

#### `strip(string $text): string`

Strips HTML and PHP tags from a string.

```php
use Effectra\ToString\TextToString;

$textToString = new TextToString();
$result = $textToString->strip('<p>Hello, <b>World!</b></p>');
echo $result; // Output: Hello, World!
```

#### `nameVar($variable): string`

Extracts the variable name from the caller's context.

```php
use Effectra\ToString\TextToString;

$textToString = new TextToString();
$myVariable = 'Hello, World!';
$result = $textToString->nameVar($myVariable);
echo $result; // Output: myVariable
```

#### `textToSlug($text): string`

Converts a string to a URL-friendly slug.

```php
use Effectra\ToString\TextToString;

$textToString = new TextToString();
$result = $textToString->textToSlug('Hello, World!');
echo $result; // Output: hello-world
```

#### `slugToText($slug): string`

Converts a URL-friendly slug back to readable text.

```php
use Effectra\ToString\TextToString;

$textToString = new TextToString();
$result = $textToString->slugToText('hello-world');
echo $result; // Output: Hello World
```

#### `generateRandomText($length): string`

Generates a random text of specified length.

```php
use Effectra\ToString\TextToString;

$textToString = new TextToString();
$result = $textToString->generateRandomText(8);
echo $result; // Output: C4rN1QX7
```

### ArrayToString

#### `array(array $array): string`

Converts an array to a string representation.

```php
use Effectra\ToString\ArrayToString;

$result = ArrayToString::array(['apple', 'banana', 'cherry']);
echo $result; // Output: ['apple', 'banana', 'cherry']
```

#### `arrayToText(array $data, string $separator = ','): string`

Converts an array to a string by joining its elements with a separator.

```php
use Effectra\ToString\ArrayToString;

$result = ArrayToString::arrayToText(['apple', 'banana', 'cherry']);
echo $result; // Output: apple,banana,cherry
```

#### `arrayToSlug(array $data): string`

Converts an array to a URL-friendly slug by joining its elements with a separator.
```php
use Effectra\ToString\ArrayToString;

$arrayToString = new ArrayToString();
$result = $arrayToString->arrayToSlug(['apple', 'banana', 'cherry']);
echo $result; // Output: apple-banana-cherry
```

#### `arrayToTextKeyValue($data): string`

Converts an array or JSON string to a key-value pair string representation.

```php
use Effectra\ToString\ArrayToString;

$arrayToString = new ArrayToString();
$result = $arrayToString->arrayToTextKeyValue(['name' => 'John', 'age' => 25, 'city' => 'New York']);
echo $result;
/*
Output:
name: John,
age: 25,
city: New York,
*/
```

### DateToString

#### `formatTime(int $time): string`

Formats a time value in seconds into HH:MM:SS format.

```php
use Effectra\ToString\DateToString;

$dateToString = new DateToString();
$result = $dateToString->formatTime(3600); // Assuming 3600 seconds is 1 hour
echo $result; // Output: 01:00:00
```

#### `formatDate(int $timestamp): string`

Formats a timestamp into YYYY-MM-DD format.

```php
use Effectra\ToString\DateToString;

$dateToString = new DateToString();
$result = $dateToString->formatDate(time()); // Current timestamp
echo $result; // Output: 2023-05-13
```

## License

This library is licensed under the MIT License. See the [LICENSE](LICENSE) file for more information.

## Contributing

Contributions are welcome! If you have any improvements or bug fixes, please submit a pull request.

## Credits

The `to-string` library is developed and maintained by [Effectra](https://effectra.co/).

## Support

For any questions or issues, please [open an issue](https://github.com/effectra/to-string/issues) on GitHub.


Feel free to modify the README file according to your specific library details, such as author information, additional sections, or formatting preferences.
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@

},
"minimum-stability": "stable"
}
<<<<<<< HEAD
}
=======
}
>>>>>>> 145a7cd92f06365c9f0ca190efdc6e1766c29364
4 changes: 4 additions & 0 deletions src/ArrayToString.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ public static function arrayToText(array $data, string $separator = ','): string
* @param array $data The input array.
* @return string The URL-friendly slug.
*/
<<<<<<< HEAD
public static function arrayToSlug(array $data): string
=======
public function arrayToSlug(array $data): string
>>>>>>> 145a7cd92f06365c9f0ca190efdc6e1766c29364
{
return static::arrayToText($data, '-');
}
Expand Down
8 changes: 8 additions & 0 deletions src/DateToString.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ class DateToString
* @param int $time The time value in seconds.
* @return string The formatted time string (HH:MM:SS).
*/
<<<<<<< HEAD
public static function formatTime(int $time): string
=======
public function formatTime(int $time): string
>>>>>>> 145a7cd92f06365c9f0ca190efdc6e1766c29364
{
$hours = gmdate('H', $time);
$minutes = gmdate('i', $time);
Expand All @@ -27,7 +31,11 @@ public static function formatTime(int $time): string
* @param int $timestamp The timestamp value.
* @return string The formatted date string (YYYY-MM-DD).
*/
<<<<<<< HEAD
public static function formatDate(int $timestamp): string
=======
public function formatDate(int $timestamp): string
>>>>>>> 145a7cd92f06365c9f0ca190efdc6e1766c29364
{
return date('Y-m-d', $timestamp);
}
Expand Down
34 changes: 34 additions & 0 deletions src/TextToString.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ class TextToString
* @param string $text The input string.
* @return string The string converted to uppercase.
*/
<<<<<<< HEAD
public static function toUppercase(string $text): string
=======
public function toUppercase(string $text): string
>>>>>>> 145a7cd92f06365c9f0ca190efdc6e1766c29364
{
return strtoupper($text);
}
Expand All @@ -23,7 +27,11 @@ public static function toUppercase(string $text): string
* @param string $text The input string.
* @return string The string converted to lowercase.
*/
<<<<<<< HEAD
public static function toLowercase(string $text): string
=======
public function toLowercase(string $text): string
>>>>>>> 145a7cd92f06365c9f0ca190efdc6e1766c29364
{
return strtolower($text);
}
Expand All @@ -34,7 +42,11 @@ public static function toLowercase(string $text): string
* @param string $text The input string.
* @return string The string with tags stripped.
*/
<<<<<<< HEAD
public static function strip(string $text): string
=======
public function strip(string $text): string
>>>>>>> 145a7cd92f06365c9f0ca190efdc6e1766c29364
{
return strip_tags($text);
}
Expand All @@ -45,7 +57,11 @@ public static function strip(string $text): string
* @param mixed $variable The variable to get the name from.
* @return string The name of the variable.
*/
<<<<<<< HEAD
public static function nameVar($variable): string
=======
public function nameVar($variable): string
>>>>>>> 145a7cd92f06365c9f0ca190efdc6e1766c29364
{
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
$callerLine = $backtrace[1]['line'];
Expand All @@ -65,7 +81,11 @@ public static function nameVar($variable): string
* @param string $text The input string.
* @return string The URL-friendly slug.
*/
<<<<<<< HEAD
public static function textToSlug($text): string
=======
public function textToSlug($text): string
>>>>>>> 145a7cd92f06365c9f0ca190efdc6e1766c29364
{
// Convert the text to lowercase
$text = strtolower($text);
Expand All @@ -79,6 +99,7 @@ public static function textToSlug($text): string
return $text;
}

<<<<<<< HEAD
public static function snakeToCamel(string $string): string
{
$words = explode('_', $string);
Expand All @@ -102,13 +123,19 @@ public static function camelToSnake(string $inputString): string
return $outputString;
}

=======
>>>>>>> 145a7cd92f06365c9f0ca190efdc6e1766c29364
/**
* Converts a URL-friendly slug back to a readable text.
*
* @param string $slug The input slug.
* @return string The readable text.
*/
<<<<<<< HEAD
public static function slugToText($slug): string
=======
public function slugToText($slug): string
>>>>>>> 145a7cd92f06365c9f0ca190efdc6e1766c29364
{
// Replace dashes with spaces
$text = str_replace('-', ' ', $slug);
Expand All @@ -125,7 +152,11 @@ public static function slugToText($slug): string
* @param int $length The length of the random text.
* @return string The generated random text.
*/
<<<<<<< HEAD
public static function generateRandomText($length): string
=======
public function generateRandomText($length): string
>>>>>>> 145a7cd92f06365c9f0ca190efdc6e1766c29364
{
$characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$randomText = '';
Expand All @@ -137,6 +168,7 @@ public static function generateRandomText($length): string

return $randomText;
}
<<<<<<< HEAD

/**
* Converts a hyphen-separated text to camel case.
Expand Down Expand Up @@ -166,4 +198,6 @@ function dashToCamelCase(string $text): string

return $convertedText;
}
=======
>>>>>>> 145a7cd92f06365c9f0ca190efdc6e1766c29364
}

0 comments on commit 76707bc

Please sign in to comment.