Skip to content

Commit

Permalink
add valueOrEmpty method.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jojo-craft committed Sep 8, 2023
1 parent cdf15c6 commit a2dfdec
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 64 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 📦 [2.4.0] - 2023-09-08

### 💎 Added
- Methods:
- `valueOrEmpty`: Returns an empty string if the value is null, undefined, or blank; otherwise, returns the input value.


## 📦 [2.3.0] - 2023-08-23
Expand Down
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ String.EMPTY;
| [`containsSpecialCharacter`](#containsSpecialCharacter) | Indicates whether a given string contains at least one special character (reverse with `notContainsSpecialCharacter` method). | value: `string` | `null` | `undefined` | `boolean` |
| [`containsUpperCase`](#containsUpperCase) | Indicates whether the specified string contains at least one uppercase letter. | value: `string` | `null` | `undefined` | `boolean` |
| [`containsLowerCase`](#containsLowerCase) | Indicates whether the specified string contains at least one lowercase letter. | value: `string` | `null` | `undefined` | `boolean` |
| [`valueOrEmpty`](#valueOrEmpty) | Returns an empty string if the value is null, undefined, or blank; otherwise, returns the input value. | value: `string` | `null` | `undefined` | `string` |
| [`removeAccents`](#removeAccents) | Removes accents from a given string. | value: `string` | `string` |
| [`join`](#join) | Concatenates an array of strings using the specified separator between each member. | separator: `string`, values: (`string` | `null` | `undefined`)[] | `string` |
| [`countWords`](#countWords) | Counts the number of words in a sentence. | sentence: `string` | `null` | `undefined` | `number` |
Expand Down Expand Up @@ -345,6 +346,27 @@ String.toBoolean('true');
// true
```

#### <a id="valueOrEmpty"/> valueOrEmpty

```typescript
String.valueOrEmpty(undefined);
// ''
```

```typescript
String.valueOrEmpty(null);
// ''
```

```typescript
String.valueOrEmpty(' ');
// ''
```

```typescript
String.valueOrEmpty('pomme de terre');
// 'pomme de terre'
```


## License
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "string-craft",
"version": "2.3.0",
"version": "2.4.0",
"description": "Simple string manipulation library for TypeScript",
"main": "dist/string.js",
"types": "dist/string.d.ts",
Expand Down Expand Up @@ -34,7 +34,10 @@
"package.json",
"tsconfig.json",
"stryker.conf.json",
".eslintrc"
".eslintrc",
".eslintignore",
".gitignore",
".npmignore"
],
"author": "Joann JOUSSELIN",
"license": "MIT",
Expand Down
Loading

0 comments on commit a2dfdec

Please sign in to comment.