Skip to content

Release 2.4.0 #30

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 21 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
2bc58ce
docs(CHANGELOG): fix typo
benjGam Sep 26, 2024
cbe40e7
docs(CHANGELOG): fix typo
benjGam Sep 26, 2024
ff1329d
chore: move 'src/word.ts' -> 'src/word/utils.ts'
benjGam Sep 26, 2024
a6dedbb
fix: update import to fit with new 'StringUtilsWord' file path
benjGam Sep 26, 2024
673b732
chore: move 'IWordEnding' interface to dedicated file 'src/word/IWord…
benjGam Sep 26, 2024
c0e0c6a
feat: implement 'WordEnding' class
benjGam Sep 26, 2024
41a72a3
fix: rename getters
benjGam Sep 26, 2024
c74c8ae
fix(test): fix 'getCorrespondingEnding' to fit with new implementation
benjGam Sep 26, 2024
cd99686
chore: remove 'IWordEnding' interface
benjGam Sep 26, 2024
1a1ce88
test: add tests for 'StringUtilsWord.getPluralOf' method
benjGam Sep 26, 2024
ff58163
fix: fix test
benjGam Sep 26, 2024
5a1ed85
feat: implement 'getPluralOf' method logic
benjGam Sep 26, 2024
22d65f9
Merge branch 'feature/implement-getPluralOf' into develop
benjGam Sep 26, 2024
b85c801
test: add tests for 'StringUtilsWord.getSingularOf' method
benjGam Sep 26, 2024
0a9f077
feat: implement 'getSingularOf' method logic
benjGam Sep 26, 2024
6ec3312
Merge branch 'feature/implement-getSingularOf' into develop
benjGam Sep 26, 2024
5c063a8
docs: fix TSDoc for 'StringUtilsWord.getSingularOf' method
benjGam Sep 26, 2024
1d37cb4
feat: export word components
benjGam Sep 26, 2024
35347df
fix: fix imports in 'src/index.ts'
benjGam Sep 27, 2024
e0258f8
docs(CHANGELOG): add 'Version 2.4.0' logs
benjGam Sep 27, 2024
9551653
chore(version): 2.3.1 -> 2.4.0
benjGam Sep 27, 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
14 changes: 11 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
# 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`:
- Export for cases component are now availables.
- Exports for cases component are now availables.

# Version 2.3.0

Expand Down Expand Up @@ -49,7 +57,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**)

Expand All @@ -75,4 +83,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.
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.3.1",
"version": "2.4.0",
"description": "Provide some useful functions for strings",
"main": "./lib",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/case/camel-case.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/case/pascal-case.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/case/snake-case.ts
Original file line number Diff line number Diff line change
@@ -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+)/;
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './main';
export * from './word';
export * from './word/';
export * from './case';
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import StringUtilsWord from './word';
import StringUtilsWord from './word/utils';

export class StringUtils {
/**
Expand Down
2 changes: 2 additions & 0 deletions src/word/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './word-ending';
export * from './utils';
77 changes: 42 additions & 35 deletions src/word.ts → src/word/utils.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,15 @@
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 { StringUtils } from '../main';
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', ''),
];

/**
Expand Down Expand Up @@ -79,13 +52,47 @@ 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),
);
}

/**
* 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;
}

/**
* Returns the singular form of a plural one.
*
* @param {string} str - Should be a plural 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
*
Expand Down
23 changes: 23 additions & 0 deletions src/word/word-ending.ts
Original file line number Diff line number Diff line change
@@ -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 pluralForm(): string {
return this._pluralForm;
}

/**
* Returns the singular of stored plural form
*/
public get singularForm(): string {
return this._singularForm;
}
}
89 changes: 31 additions & 58 deletions test/words.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import StringUtilsWord, { IWordEnding } from '../src/word';
import StringUtilsWord from '../src/word/utils';
import { WordEnding } from '../src/word/word-ending';
import JestRunner from './test.utils';

const runner = new JestRunner(StringUtilsWord);
Expand All @@ -20,63 +21,15 @@ describe('Get word ending', () => {

runner.runBasicTests(
StringUtilsWord.getCorrespondingEnding,
new Map<string, IWordEnding>([
[
'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<string, WordEnding>([
['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', '')],
]),
);
});
Expand Down Expand Up @@ -170,4 +123,24 @@ describe('Normalization of stuffs', () => {
[['This ', 'is ', 'my ', 'test'], 'This Is My Test'],
]),
);

runner.runBasicTests(
StringUtilsWord.getPluralOf,
new Map<string, string>([
['y', 'ies'],
['ss', 'sses'],
['e', 'es'],
['', 's'],
]),
);

runner.runBasicTests(
StringUtilsWord.getSingularOf,
new Map<string, string>([
['ies', 'y'],
['sses', 'ss'],
['es', 'e'],
['s', ''],
]),
);
});
Loading