Skip to content

Release 2.5.0 #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 30 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
3fc3dd8
chore(npm-ignore): remove unused files from NPM publish
benjGam Sep 27, 2024
cabd553
chore(version): 2.4.0 -> 2.4.1
benjGam Sep 27, 2024
8142286
docs(CHANGELOG): add 'Version 2.4.1' section
benjGam Sep 27, 2024
9040b3d
test: add test for getting first char in string
benjGam Oct 30, 2024
c0045a4
fix: add test case
benjGam Oct 30, 2024
8e1e640
feat: implement 'getFirstCharIndex' logic
benjGam Oct 30, 2024
269d3b3
docs: fix doc example
benjGam Oct 30, 2024
074c67e
test: implement test for 'normalizeSentence' method
benjGam Oct 30, 2024
d55183f
feat: implement 'normalizeSentence' logic
benjGam Oct 30, 2024
4115ebe
Merge branch 'feature/implement-normalize-sentence' into develop
benjGam Oct 30, 2024
0b90bd6
docs: update changelog
benjGam Oct 30, 2024
215e4bf
fix: add test case
benjGam Oct 30, 2024
273ef52
test: add test cases which break actual logic
benjGam Oct 30, 2024
2659880
test: add test for 'getFirstEndingPunctionChar' method
benjGam Oct 30, 2024
47253a4
feat: implement 'getFirstEndingPunctuationChar' logic
benjGam Oct 30, 2024
07cce09
fix: rework 'normalizeSentence' behavior to work correctly
benjGam Oct 30, 2024
742712b
Merge branch 'bugfix/normalizeSentence' into develop
benjGam Oct 30, 2024
02cc2ba
refactor: use 'findIndex' instead of a messy loop
benjGam Oct 30, 2024
833fa4d
style: fix typo in TSDoc
benjGam Oct 30, 2024
d5319c6
test: add test for 'getFirstIndexOfUnfullyDeterminated'
benjGam Oct 30, 2024
16ecbd6
fix: fix test
benjGam Oct 30, 2024
ea2a12e
feat: implement 'getFirstIndexOfUnfullyDeterminated' logic
benjGam Oct 30, 2024
2d2bf87
Merge branch 'feature/implement-get-first-index-of-unfully-determinat…
benjGam Oct 30, 2024
81bdb65
refactor: use 'getFirstIndexOfUnfullyDeterminated' logic instead of r…
benjGam Oct 30, 2024
abbc44f
fix typo for runner utils
benjGam Oct 30, 2024
d0ea921
docs: add methods implementation
benjGam Oct 30, 2024
71184da
docs: fix typo
benjGam Oct 30, 2024
0e1f68d
style: change method name 'getFirstEndingPunctuationChar' -> 'getFirs…
benjGam Oct 30, 2024
e43df81
docs: update changelog
benjGam Oct 30, 2024
7c6d1b7
chore(version): '2.4.1' -> '2.5.0'
benjGam Oct 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
node_modules/
package-lock.json
src/
.github/
coverage/
test/
tsconfig.json
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Version 2.5.0 [ON-GOING]

- `Added`:
- `getFirstCharIndex(string: string): number` method has been implemented.
- `normalizeSentence(sentence: string): string` method has been implemented, this method is used to upper the first word char & lower the rest of them & append a dot at the end of it.
- `getFirstCharIndex(string: string)` method has been implemented.
- `getFirstEndingPunctuationIndex(string: string): number` method has been implemented.
- `getIndexOfUnfullyDeterminated(string: string, toSearch: string | string[]): number` method has been implemented to get the first index of a given set of (only one) char in a given string.

# Version 2.4.1

- `Patch`:
- Remove useless files from package (When `npm publish` is performed)

# Version 2.4.0

- `Added`:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "string-utils-ts",
"version": "2.4.0",
"version": "2.5.0",
"description": "Provide some useful functions for strings",
"main": "./lib",
"scripts": {
Expand Down
36 changes: 35 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class StringUtils {
* str: 'Test'
* index: '2'
* toReplaceWith: 'hello'
* returns: 'Tehellost'
* returns: 'Tehellot'
*/
public static replaceAt(
str: string,
Expand Down Expand Up @@ -162,4 +162,38 @@ export class StringUtils {

return revelantSubSequences;
}

/**
* Returns the index of the first char
*
*
* @param string - The string to search in
*/
public static getFirstCharIndex(string: string) {
return this.getFirstIndexOfUnfullyDeterminated(
string.toLowerCase(),
'abcdefghijklmnopqrstuvwxyz',
);
}

/**
* Returns the index of the ending punctuation char index
*
* @param string - The string to search in
*
*/
public static getFirstEndingPunctuationIndex(string: string) {
return this.getFirstIndexOfUnfullyDeterminated(string, '?!;.');
}

/**
* Returns first index of a given set of char in a given string
*
*/
public static getFirstIndexOfUnfullyDeterminated(
string: string,
toSearch: string | string[],
): number {
return string.split('').findIndex((char) => toSearch.includes(char));
}
}
24 changes: 24 additions & 0 deletions src/word/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,28 @@ export default class StringUtilsWord {
.map((subSequence) => this.formatWord(subSequence))
.join(' ');
}

/**
*
* Returns a dot at end of sentence & first word char uppered.
*
* @param sentence - A sentence in a string
*
* @example
* sentence: ' this is a sentence'
* returns: 'This is a sentence.'
*/
public static normalizeSentence(sentence: string): string {
const firstCharIndex = StringUtils.getFirstCharIndex(sentence);
if (firstCharIndex == -1)
// There's no char in given string
return sentence;
sentence = this.normalizeSpacesBetweenWords(
sentence.substring(firstCharIndex, sentence.length),
);
const arrayOfSentence = sentence.split('');
sentence = sentence.toLowerCase();
arrayOfSentence[0] = arrayOfSentence[0].toUpperCase();
return `${arrayOfSentence.join('')}${StringUtils.getFirstEndingPunctuationIndex(sentence) == sentence.length - 1 ? '' : '.'}`;
}
}
35 changes: 35 additions & 0 deletions test/main.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,38 @@ runner.runBasicTests(
[' '.split(' '), false],
]),
);

runner.runBasicTests(
StringUtils.getFirstCharIndex,
new Map<string, number>([
[' this is a sentence', 3],
['this is a sentence', 0],
['!!this', 2],
['!!!', -1],
]),
);

runner.runBasicTests(
StringUtils.getFirstEndingPunctuationIndex,
new Map<string, number>([
['!', 0],
['This', -1],
['This ?', 5],
['This !', 5],
['This.', 4],
['!This', 0],
['This;', 4],
['', -1],
]),
);

runner.runBasicTests(
StringUtils.getFirstIndexOfUnfullyDeterminated,
new Map<any, number>([
[() => ['test', 'te'], 0],
[() => ['', ''], -1],
[() => ['hello', 'o'], 4],
[() => ['hey ', ' '], 3],
[() => ['bouh', 'hello'], 1],
]),
);
2 changes: 1 addition & 1 deletion test/test.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class JestRunner {
this.checkInvokation(fn);

for (const [input, output] of expectedReturns.entries()) {
test(`[${fn.name}] Should return '${output} for '${input}''`, () => {
test(`[${fn.name}] Should return '${output}' for '${input}''`, () => {
(inputPropertiesToTestName && output
? expect(
this._classToInvoke[fn.name](
Expand Down
14 changes: 14 additions & 0 deletions test/words.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,18 @@ describe('Normalization of stuffs', () => {
['s', ''],
]),
);

runner.runBasicTests(
StringUtilsWord.normalizeSentence,
new Map<string, string>([
[' this is a sentence', 'This is a sentence.'],
[' ', ' '],
[' !!!!!! hello you', 'Hello you.'],
[' a !!!! story', 'A !!!! story.'],
[' This is a story.', 'This is a story.'],
['This is a story !', 'This is a story !'],
['Is this a story ?', 'Is this a story ?'],
['Is this a story ? No', 'Is this a story ? No.'],
]),
);
});
Loading