From 2bc58ce00590bc627e270f15f15c0ce9494e9e86 Mon Sep 17 00:00:00 2001 From: benjGam Date: Thu, 26 Sep 2024 14:07:59 +0200 Subject: [PATCH 01/19] docs(CHANGELOG): fix typo --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bde6c03..c9dddeb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,7 +49,7 @@ - Added: - Unit testing is now part of this project. - TSDoc has been adopted and is now part of this project. - - Code quality components is now part of this project (ESLint & Prettier) + - Code quality components are now part of this project (ESLint & Prettier) - Performance: - Code has been reworked to improve performance (**A performance measurer should be implemented in next realases**) @@ -75,4 +75,4 @@ - `isPlural();` - [FIX] Bring a fix to case where provided words ended with `ss`, there's no confusion, method now manage those cases. - `isSingular();`, `pluralize();`, `singularize();` - moved from `StringUtils` to `StringUtilsWord` class. - `formatWord();` - has been reworked and now use `StringUtils.replaceAt();` method to optimize process. - - `normalizeSpacesBetweenWords();` - to be be rework in next release. + - `normalizeSpacesBetweenWords();` - to be rework in next release. From cbe40e7a9f3b7ddbff8c3d90e62e4c171e5e8801 Mon Sep 17 00:00:00 2001 From: benjGam Date: Thu, 26 Sep 2024 14:08:23 +0200 Subject: [PATCH 02/19] docs(CHANGELOG): fix typo --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c9dddeb..c993967 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # Version 2.3.1 - `Fixes`: - - Export for cases component are now availables. + - Exports for cases component are now availables. # Version 2.3.0 From ff1329d22b64df52c5591f0cdd0cc3d06b04e75f Mon Sep 17 00:00:00 2001 From: benjGam Date: Thu, 26 Sep 2024 16:41:44 +0200 Subject: [PATCH 03/19] chore: move 'src/word.ts' -> 'src/word/utils.ts' --- src/{word.ts => word/utils.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/{word.ts => word/utils.ts} (100%) diff --git a/src/word.ts b/src/word/utils.ts similarity index 100% rename from src/word.ts rename to src/word/utils.ts From a6dedbb0be5f0447f207fd71b950d3e1fd364224 Mon Sep 17 00:00:00 2001 From: benjGam Date: Thu, 26 Sep 2024 16:43:54 +0200 Subject: [PATCH 04/19] fix: update import to fit with new 'StringUtilsWord' file path --- src/case/camel-case.ts | 2 +- src/case/pascal-case.ts | 2 +- src/case/snake-case.ts | 2 +- src/main.ts | 2 +- src/word/utils.ts | 2 +- test/words.spec.ts | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/case/camel-case.ts b/src/case/camel-case.ts index 7120aaf..a84c329 100644 --- a/src/case/camel-case.ts +++ b/src/case/camel-case.ts @@ -1,6 +1,6 @@ import Case from './Case'; import StringUtilsCase from './utils'; -import StringUtilsWord from '../word'; +import StringUtilsWord from '../word/utils'; import { StringUtils } from '../main'; export default class CamelCase extends Case { diff --git a/src/case/pascal-case.ts b/src/case/pascal-case.ts index 505b830..dd241ac 100644 --- a/src/case/pascal-case.ts +++ b/src/case/pascal-case.ts @@ -1,5 +1,5 @@ import Case from './Case'; -import StringUtilsWord from '../word'; +import StringUtilsWord from '../word/utils'; import { StringUtils } from '../main'; export default class PascalCase extends Case { diff --git a/src/case/snake-case.ts b/src/case/snake-case.ts index e4b5985..7b0711a 100644 --- a/src/case/snake-case.ts +++ b/src/case/snake-case.ts @@ -1,6 +1,6 @@ import Case from './Case'; import StringUtilsCase from './utils'; -import StringUtilsWord from '../word'; +import StringUtilsWord from '../word/utils'; export default class SnakeCase extends Case { protected _matcher = /(\w+)_(\w+)/; diff --git a/src/main.ts b/src/main.ts index a82ea74..06a5cd0 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,4 +1,4 @@ -import StringUtilsWord from './word'; +import StringUtilsWord from './word/utils'; export class StringUtils { /** diff --git a/src/word/utils.ts b/src/word/utils.ts index a3629c7..0fe8ee1 100644 --- a/src/word/utils.ts +++ b/src/word/utils.ts @@ -1,4 +1,4 @@ -import { StringUtils } from './main'; +import { StringUtils } from '../main'; /** * This interface provide a structure to register word endings forms diff --git a/test/words.spec.ts b/test/words.spec.ts index 2f1fbaa..2a36b8d 100644 --- a/test/words.spec.ts +++ b/test/words.spec.ts @@ -1,4 +1,4 @@ -import StringUtilsWord, { IWordEnding } from '../src/word'; +import StringUtilsWord, { IWordEnding } from '../src/word/utils'; import JestRunner from './test.utils'; const runner = new JestRunner(StringUtilsWord); From 673b7323cedb6bb1d6f34a40a3ef1dfae4dce8b7 Mon Sep 17 00:00:00 2001 From: benjGam Date: Thu, 26 Sep 2024 17:10:44 +0200 Subject: [PATCH 05/19] chore: move 'IWordEnding' interface to dedicated file 'src/word/IWordEnding.ts' --- src/word/IWordEnding.ts | 15 +++++++++++++++ src/word/utils.ts | 17 +---------------- test/words.spec.ts | 3 ++- 3 files changed, 18 insertions(+), 17 deletions(-) create mode 100644 src/word/IWordEnding.ts diff --git a/src/word/IWordEnding.ts b/src/word/IWordEnding.ts new file mode 100644 index 0000000..e8a9364 --- /dev/null +++ b/src/word/IWordEnding.ts @@ -0,0 +1,15 @@ +/** + * This interface provide a structure to register word endings forms + * + * @interface IWordEnding + * @field {string} pluralForm is used to store a plural form of ending + * @field {string} singularForm is used to store the singular form of the plural form ending + * + * @example + * pluralForm: 'ies' + * singularForm: 'y' + */ +export interface IWordEnding { + pluralForm: string; + singularForm: string; +} diff --git a/src/word/utils.ts b/src/word/utils.ts index 0fe8ee1..c9f290a 100644 --- a/src/word/utils.ts +++ b/src/word/utils.ts @@ -1,20 +1,5 @@ import { StringUtils } from '../main'; - -/** - * This interface provide a structure to register word endings forms - * - * @interface IWordEnding - * @field {string} pluralForm is used to store a plural form of ending - * @field {string} singularForm is used to store the singular form of the plural form ending - * - * @example - * pluralForm: 'ies' - * singularForm: 'y' - */ -export interface IWordEnding { - pluralForm: string; - singularForm: string; -} +import { IWordEnding } from './IWordEnding'; /** * This object is used to list plural and singular forms diff --git a/test/words.spec.ts b/test/words.spec.ts index 2a36b8d..746c08d 100644 --- a/test/words.spec.ts +++ b/test/words.spec.ts @@ -1,4 +1,5 @@ -import StringUtilsWord, { IWordEnding } from '../src/word/utils'; +import StringUtilsWord from '../src/word/utils'; +import { IWordEnding } from '../src/word/IWordEnding'; import JestRunner from './test.utils'; const runner = new JestRunner(StringUtilsWord); From c0e0c6a97afeb4b14dc81c50489b489f7d6d6c55 Mon Sep 17 00:00:00 2001 From: benjGam Date: Thu, 26 Sep 2024 17:30:18 +0200 Subject: [PATCH 06/19] feat: implement 'WordEnding' class --- src/word/word-ending.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/word/word-ending.ts diff --git a/src/word/word-ending.ts b/src/word/word-ending.ts new file mode 100644 index 0000000..20ac0d6 --- /dev/null +++ b/src/word/word-ending.ts @@ -0,0 +1,23 @@ +export class WordEnding { + private _pluralForm: string; + private _singularForm: string; + + constructor(pluralForm: string, singularForm: string) { + this._pluralForm = pluralForm; + this._singularForm = singularForm; + } + + /** + * Returns the plural of stored singular form + */ + public get pluralOf(): string { + return this._pluralForm; + } + + /** + * Returns the singular of stored plural form + */ + public get singularOf(): string { + return this._singularForm; + } +} From 41a72a32307a78e0c9bcf75701112ab415749da7 Mon Sep 17 00:00:00 2001 From: benjGam Date: Thu, 26 Sep 2024 17:34:42 +0200 Subject: [PATCH 07/19] fix: rename getters --- src/word/utils.ts | 26 +++++++------------------- src/word/word-ending.ts | 4 ++-- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/src/word/utils.ts b/src/word/utils.ts index c9f290a..154f69a 100644 --- a/src/word/utils.ts +++ b/src/word/utils.ts @@ -1,27 +1,15 @@ import { StringUtils } from '../main'; -import { IWordEnding } from './IWordEnding'; +import { WordEnding } from './word-ending'; /** * This object is used to list plural and singular forms * of words. */ -const wordEndings: IWordEnding[] = [ - { - pluralForm: 'sses', - singularForm: 'ss', - }, - { - pluralForm: 'ies', - singularForm: 'y', - }, - { - pluralForm: 'es', - singularForm: 'e', - }, - { - pluralForm: 's', - singularForm: '', - }, +const wordEndings: WordEnding[] = [ + new WordEnding('sses', 'ss'), + new WordEnding('ies', 'y'), + new WordEnding('es', 'e'), + new WordEnding('s', ''), ]; /** @@ -64,7 +52,7 @@ export default class StringUtilsWord { * If you just want to do some word operation, prefer * @method getWordEnding */ - public static getCorrespondingEnding(word: string): IWordEnding { + public static getCorrespondingEnding(word: string): WordEnding { return wordEndings.find( (ending) => word.endsWith(ending.pluralForm) || word.endsWith(ending.singularForm), diff --git a/src/word/word-ending.ts b/src/word/word-ending.ts index 20ac0d6..2af5e1f 100644 --- a/src/word/word-ending.ts +++ b/src/word/word-ending.ts @@ -10,14 +10,14 @@ export class WordEnding { /** * Returns the plural of stored singular form */ - public get pluralOf(): string { + public get pluralForm(): string { return this._pluralForm; } /** * Returns the singular of stored plural form */ - public get singularOf(): string { + public get singularForm(): string { return this._singularForm; } } From c74c8aed912cb17d0651e74ded1ae287d070c0ce Mon Sep 17 00:00:00 2001 From: benjGam Date: Thu, 26 Sep 2024 17:38:02 +0200 Subject: [PATCH 08/19] fix(test): fix 'getCorrespondingEnding' to fit with new implementation --- test/words.spec.ts | 68 +++++++--------------------------------------- 1 file changed, 10 insertions(+), 58 deletions(-) diff --git a/test/words.spec.ts b/test/words.spec.ts index 746c08d..8b7d142 100644 --- a/test/words.spec.ts +++ b/test/words.spec.ts @@ -1,5 +1,5 @@ import StringUtilsWord from '../src/word/utils'; -import { IWordEnding } from '../src/word/IWordEnding'; +import { WordEnding } from '../src/word/word-ending'; import JestRunner from './test.utils'; const runner = new JestRunner(StringUtilsWord); @@ -21,63 +21,15 @@ describe('Get word ending', () => { runner.runBasicTests( StringUtilsWord.getCorrespondingEnding, - new Map([ - [ - 'Passes', - { - pluralForm: 'sses', - singularForm: 'ss', - }, - ], - [ - 'Pass', - { - pluralForm: 'sses', - singularForm: 'ss', - }, - ], - [ - 'Categories', - { - pluralForm: 'ies', - singularForm: 'y', - }, - ], - [ - 'Category', - { - pluralForm: 'ies', - singularForm: 'y', - }, - ], - [ - 'Bees', - { - pluralForm: 'es', - singularForm: 'e', - }, - ], - [ - 'Bee', - { - pluralForm: 'es', - singularForm: 'e', - }, - ], - [ - 'Cars', - { - pluralForm: 's', - singularForm: '', - }, - ], - [ - 'Car', - { - pluralForm: 's', - singularForm: '', - }, - ], + new Map([ + ['Passes', new WordEnding('sses', 'ss')], + ['Pass', new WordEnding('sses', 'ss')], + ['Categories', new WordEnding('ies', 'y')], + ['Category', new WordEnding('ies', 'y')], + ['Bees', new WordEnding('es', 'e')], + ['Bee', new WordEnding('es', 'e')], + ['Cars', new WordEnding('s', '')], + ['Car', new WordEnding('s', '')], ]), ); }); From cd996869d849bdbd7371cb671524a9030059db05 Mon Sep 17 00:00:00 2001 From: benjGam Date: Thu, 26 Sep 2024 17:38:41 +0200 Subject: [PATCH 09/19] chore: remove 'IWordEnding' interface --- src/word/IWordEnding.ts | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 src/word/IWordEnding.ts diff --git a/src/word/IWordEnding.ts b/src/word/IWordEnding.ts deleted file mode 100644 index e8a9364..0000000 --- a/src/word/IWordEnding.ts +++ /dev/null @@ -1,15 +0,0 @@ -/** - * This interface provide a structure to register word endings forms - * - * @interface IWordEnding - * @field {string} pluralForm is used to store a plural form of ending - * @field {string} singularForm is used to store the singular form of the plural form ending - * - * @example - * pluralForm: 'ies' - * singularForm: 'y' - */ -export interface IWordEnding { - pluralForm: string; - singularForm: string; -} From 1a1ce883656e4c9d4ad8ee61e5f1d99af3615b22 Mon Sep 17 00:00:00 2001 From: benjGam Date: Thu, 26 Sep 2024 17:47:48 +0200 Subject: [PATCH 10/19] test: add tests for 'StringUtilsWord.getPluralOf' method --- test/words.spec.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/words.spec.ts b/test/words.spec.ts index 8b7d142..074ef1b 100644 --- a/test/words.spec.ts +++ b/test/words.spec.ts @@ -123,4 +123,14 @@ describe('Normalization of stuffs', () => { [['This ', 'is ', 'my ', 'test'], 'This Is My Test'], ]), ); + + runner.runBasicTests( + StringUtilsWord.getPluralOf, + new Map([ + ['y', 'ies'], + ['ss', 'sses'], + ['es', 'e'], + ['', 's'], + ]), + ); }); From ff581634b9e1b8033f3e2c064351ec8f93c4e19b Mon Sep 17 00:00:00 2001 From: benjGam Date: Thu, 26 Sep 2024 17:49:09 +0200 Subject: [PATCH 11/19] fix: fix test --- test/words.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/words.spec.ts b/test/words.spec.ts index 074ef1b..e4253ad 100644 --- a/test/words.spec.ts +++ b/test/words.spec.ts @@ -129,7 +129,7 @@ describe('Normalization of stuffs', () => { new Map([ ['y', 'ies'], ['ss', 'sses'], - ['es', 'e'], + ['e', 'es'], ['', 's'], ]), ); From 5a1ed8596455e798bc6c2a47dacc90e4afef62f3 Mon Sep 17 00:00:00 2001 From: benjGam Date: Thu, 26 Sep 2024 17:49:21 +0200 Subject: [PATCH 12/19] feat: implement 'getPluralOf' method logic --- src/word/utils.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/word/utils.ts b/src/word/utils.ts index 154f69a..840c007 100644 --- a/src/word/utils.ts +++ b/src/word/utils.ts @@ -59,6 +59,23 @@ export default class StringUtilsWord { ); } + /** + * Returns the plural form of a singular one. + * + * @param {string} str - Should be a singular form + * + * @example + * str: 'y' + * returns: 'ies' + * + * @example + * str: 'ss' + * returns: 'sses' + */ + public static getPluralOf(str: string): string { + return this.getCorrespondingEnding(str).pluralForm; + } + /** * Check the ending form of a word and return a boolean * From b85c8015b0c7eb4dece65468008776fae91c21ed Mon Sep 17 00:00:00 2001 From: benjGam Date: Thu, 26 Sep 2024 17:51:41 +0200 Subject: [PATCH 13/19] test: add tests for 'StringUtilsWord.getSingularOf' method --- test/words.spec.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/words.spec.ts b/test/words.spec.ts index e4253ad..e5b63e7 100644 --- a/test/words.spec.ts +++ b/test/words.spec.ts @@ -133,4 +133,14 @@ describe('Normalization of stuffs', () => { ['', 's'], ]), ); + + runner.runBasicTests( + StringUtilsWord.getSingularOf, + new Map([ + ['ies', 'y'], + ['sses', 'ss'], + ['es', 'e'], + ['s', ''], + ]), + ); }); From 0a9f077b15889f8acec08d09818a8d386f909ca0 Mon Sep 17 00:00:00 2001 From: benjGam Date: Thu, 26 Sep 2024 17:51:52 +0200 Subject: [PATCH 14/19] feat: implement 'getSingularOf' method logic --- src/word/utils.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/word/utils.ts b/src/word/utils.ts index 840c007..a259088 100644 --- a/src/word/utils.ts +++ b/src/word/utils.ts @@ -76,6 +76,23 @@ export default class StringUtilsWord { return this.getCorrespondingEnding(str).pluralForm; } + /** + * Returns the plural form of a singular one. + * + * @param {string} str - Should be a singular form + * + * @example + * str: 'ies' + * returns: 'y' + * + * @example + * str: 'sses' + * returns: 'ss' + */ + public static getSingularOf(str: string): string { + return this.getCorrespondingEnding(str).singularForm; + } + /** * Check the ending form of a word and return a boolean * From 5c063a8e0f8267bf35ca151941a84b3580a091a4 Mon Sep 17 00:00:00 2001 From: benjGam Date: Thu, 26 Sep 2024 17:53:52 +0200 Subject: [PATCH 15/19] docs: fix TSDoc for 'StringUtilsWord.getSingularOf' method --- src/word/utils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/word/utils.ts b/src/word/utils.ts index a259088..1d4a533 100644 --- a/src/word/utils.ts +++ b/src/word/utils.ts @@ -77,9 +77,9 @@ export default class StringUtilsWord { } /** - * Returns the plural form of a singular one. + * Returns the singular form of a plural one. * - * @param {string} str - Should be a singular form + * @param {string} str - Should be a plural form * * @example * str: 'ies' From 1d37cb42853ef0da8b433cd76fbb457a87a88222 Mon Sep 17 00:00:00 2001 From: benjGam Date: Thu, 26 Sep 2024 20:20:51 +0200 Subject: [PATCH 16/19] feat: export word components --- src/word/index.ts | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 src/word/index.ts diff --git a/src/word/index.ts b/src/word/index.ts new file mode 100644 index 0000000..9968618 --- /dev/null +++ b/src/word/index.ts @@ -0,0 +1,2 @@ +export * from './word-ending'; +export * from './utils'; From 35347df84992dcaebd266b8d28c4a66ee577b7a4 Mon Sep 17 00:00:00 2001 From: benjGam Date: Fri, 27 Sep 2024 10:27:17 +0200 Subject: [PATCH 17/19] fix: fix imports in 'src/index.ts' --- src/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 884bd41..b3ecf58 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,2 +1,3 @@ export * from './main'; -export * from './word'; +export * from './word/'; +export * from './case'; From e0258f8e4d1a47f0f3216cee323f337b1407f3ab Mon Sep 17 00:00:00 2001 From: benjGam Date: Fri, 27 Sep 2024 10:34:48 +0200 Subject: [PATCH 18/19] docs(CHANGELOG): add 'Version 2.4.0' logs --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c993967..ef07a89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +# Version 2.4.0 + +- `Added`: + - `WordEnding` class has been implemented to replace `IWordEnding` interface. + - `getPluralOf(str: string): string`, `getSingularOf(str: string): string` methods has been implemented to get respectively `plural` & `singular` form of a given one. +- `Removed` [BREAKING CHANGES]: + - `IWordEnding` interface has been removed. + # Version 2.3.1 - `Fixes`: From 95516534e870aa0362f28b5d50c87517455377b7 Mon Sep 17 00:00:00 2001 From: benjGam Date: Fri, 27 Sep 2024 10:35:15 +0200 Subject: [PATCH 19/19] chore(version): 2.3.1 -> 2.4.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 774d33d..68593fc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "string-utils-ts", - "version": "2.3.1", + "version": "2.4.0", "description": "Provide some useful functions for strings", "main": "./lib", "scripts": {