Skip to content

Commit c85f5ca

Browse files
authored
Merge pull request #27 from benjGam/develop
Release 2.2.0
2 parents 7436552 + fd51dd4 commit c85f5ca

File tree

7 files changed

+53
-7
lines changed

7 files changed

+53
-7
lines changed

.github/workflows/cd.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
name: Node.js CD
22

33
on:
4-
release:
5-
types: [created]
4+
push:
5+
branches: ['main']
66

77
jobs:
88
publish-npm:

.github/workflows/coverage.yml

+2
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ jobs:
1515
steps:
1616
- uses: actions/checkout@v3
1717
- uses: ArtiomTr/jest-coverage-report-action@v2
18+
with:
19+
custom-title: Package coverage

CHANGELOG.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
# VERSION 2.1.0
1+
# Version 2.2.0
2+
3+
- `Added`:
4+
- `StringUtilsWord.formatWords(toFormat: string | string[])` apply `StringUtilsWord.formatWord(str)` to a complete sentence or table of words.
5+
6+
# Version 2.1.0
27

38
- `Fixes`:
49
- `StringUtilsCase.splitByCase()` method doesn't remove spaces anymore while splitting `lowercase` and `uppercase` formed strings.
510
- `Added`:
611
- `type Case` is now provided to reliably link managed cases.
712
- `StringUtilsCase.convertToCase(str: string, caseToConvert: Case)` has been implemented.
813

9-
# VERSION 2.0.0
14+
# Version 2.0.0
1015

1116
- Added:
1217
- Unit testing is now part of this project.

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ This package is a way to help third-party developers but also a way to help myse
1414

1515
(I'm pretty sure that kind of module already exists and are better than mine, but, in any case, it will be usefull to me)
1616

17-
## Features (2.0.0 version)
17+
## Features (2.1.0 version)
1818

1919
### StringUtilsWord class
2020

@@ -33,7 +33,7 @@ This class is responsible to manage some operations on case of strings, we have
3333

3434
- `determineCase()`: This method could be useful if you want to know the case of a string (i.e: camelCase, snake_case, PascalCase, UPPERCASE, lowercase)
3535
- `splitByCase()`: This method could be useful if you want to split a string cased as a certain way, but you want each terms separated in a table.
36-
- `convertToCase()`: This method could be useful if you want to convert a string from a case to another one (Not implement yet)
36+
- `convertToCase()`: This method could be useful if you want to convert a string from a case to another one.
3737

3838
### StringUtils class
3939

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "string-utils-ts",
3-
"version": "2.1.0",
3+
"version": "2.2.0",
44
"description": "Provide some useful functions for strings",
55
"main": "./lib",
66
"scripts": {

src/word-ending-utils.ts

+25
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,29 @@ export default class StringUtilsWord {
195195
.filter((subsequence) => !StringUtils.isBlank(subsequence))
196196
.join(' ');
197197
}
198+
199+
/**
200+
* Return a string with each words formated.
201+
*
202+
* @param {string | string[]} toFormat - The string or table of strings to format
203+
*
204+
* @example
205+
* toFormat: 'Hello this is my example'
206+
* returns: 'Hello This Is My Example'
207+
*
208+
* @example
209+
* toFormat: ['Hello', 'this', 'is', 'my', 'example']
210+
* returns: 'Hello This Is My Example'
211+
*/
212+
public static formatWords(toFormat: string | string[]): string {
213+
if (!Array.isArray(toFormat)) {
214+
if (StringUtils.isBlank(toFormat)) return toFormat;
215+
toFormat = toFormat.split(' ');
216+
}
217+
if (StringUtils.isBlank(toFormat.join(''))) return toFormat.join('');
218+
219+
return toFormat
220+
.map((subSequence) => this.formatWord(subSequence))
221+
.join(' ');
222+
}
198223
}

test/words.spec.ts

+14
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,18 @@ describe('Normalization of stuffs', () => {
191191
);
192192
});
193193
}
194+
195+
const formatWordsExpectedReturns = new Map<string | string[], string>([
196+
['This is my test', 'This Is My Test'],
197+
[['This', 'is', 'my', 'test'], 'This Is My Test'],
198+
[[' ', ''], ' '],
199+
[' ', ' '],
200+
[['This ', 'is ', 'my ', 'test'], 'This Is My Test'],
201+
]);
202+
203+
for (const [key, value] of formatWordsExpectedReturns.entries()) {
204+
test(`Should return '${value}' for '${key}'`, () => {
205+
expect(StringUtilsWord.formatWords(key)).toEqual(value);
206+
});
207+
}
194208
});

0 commit comments

Comments
 (0)