-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update
stripGender
function to handle null values and add null checks
* Update `stripGender` function in `src/string-utilities.ts` to handle null and undefined values by returning an empty string. * Add test cases in `src/string-utilities.test.ts` for `stripGender` function to handle null and undefined values. * Update `sportlinkRowToContact` function in `src/sportlink-to-mailchimp-converter.ts` to ensure `categorie` is not null or undefined before calling `stripGender`. * Update `sportlinkRowToContact` function to check if `categorie` is null or undefined before checking `if (tags.length === 0)`.
- Loading branch information
1 parent
1f2f8b8
commit f366022
Showing
4 changed files
with
59 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"tasks": { | ||
"test": "npm install && npm test" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,42 @@ | ||
import { stripGender, isNullOrEmpty, trimSpacesAndRemoveDoubleQuotes } from './string-utilities' | ||
|
||
describe('stripGender', () => { | ||
it('should remove gender-related words and trim the string', () => { | ||
expect(stripGender('Meisjes kleding')).toBe('kleding') | ||
expect(stripGender('Jongens schoenen')).toBe('schoenen') | ||
expect(stripGender('Vrouwen accessoires')).toBe('accessoires') | ||
expect(stripGender('Mannen horloges')).toBe('horloges') | ||
expect(stripGender('Unisex kleding')).toBe('Unisex kleding') // No gender-related word | ||
}) | ||
}) | ||
|
||
describe('isNullOrEmpty', () => { | ||
it('should return true for undefined, null, or empty strings', () => { | ||
expect(isNullOrEmpty(undefined!)).toBe(true) | ||
expect(isNullOrEmpty(null!)).toBe(true) | ||
expect(isNullOrEmpty('')).toBe(true) | ||
}) | ||
|
||
it('should return false for non-empty strings', () => { | ||
expect(isNullOrEmpty('text')).toBe(false) | ||
expect(isNullOrEmpty(' ')).toBe(false) | ||
}) | ||
}) | ||
|
||
describe('trimSpacesAndRemoveDoubleQuotes', () => { | ||
it('should trim spaces and remove double quotes', () => { | ||
expect(trimSpacesAndRemoveDoubleQuotes(' "text" ')).toBe('text') | ||
expect(trimSpacesAndRemoveDoubleQuotes(' "text')).toBe('text') | ||
expect(trimSpacesAndRemoveDoubleQuotes('text" ')).toBe('text') | ||
expect(trimSpacesAndRemoveDoubleQuotes('text')).toBe('text') | ||
}) | ||
|
||
it('should handle empty strings', () => { | ||
expect(trimSpacesAndRemoveDoubleQuotes('')).toBe('') | ||
}) | ||
}) | ||
import { stripGender, isNullOrEmpty, trimSpacesAndRemoveDoubleQuotes } from './string-utilities' | ||
|
||
describe('stripGender', () => { | ||
it('should remove gender-related words and trim the string', () => { | ||
expect(stripGender('Meisjes kleding')).toBe('kleding') | ||
expect(stripGender('Jongens schoenen')).toBe('schoenen') | ||
expect(stripGender('Vrouwen accessoires')).toBe('accessoires') | ||
expect(stripGender('Mannen horloges')).toBe('horloges') | ||
expect(stripGender('Unisex kleding')).toBe('Unisex kleding') // No gender-related word | ||
}) | ||
|
||
it('should return an empty string for null or undefined values', () => { | ||
expect(stripGender(null!)).toBe('') | ||
expect(stripGender(undefined!)).toBe('') | ||
}) | ||
}) | ||
|
||
describe('isNullOrEmpty', () => { | ||
it('should return true for undefined, null, or empty strings', () => { | ||
expect(isNullOrEmpty(undefined!)).toBe(true) | ||
expect(isNullOrEmpty(null!)).toBe(true) | ||
expect(isNullOrEmpty('')).toBe(true) | ||
}) | ||
|
||
it('should return false for non-empty strings', () => { | ||
expect(isNullOrEmpty('text')).toBe(false) | ||
expect(isNullOrEmpty(' ')).toBe(false) | ||
}) | ||
}) | ||
|
||
describe('trimSpacesAndRemoveDoubleQuotes', () => { | ||
it('should trim spaces and remove double quotes', () => { | ||
expect(trimSpacesAndRemoveDoubleQuotes(' "text" ')).toBe('text') | ||
expect(trimSpacesAndRemoveDoubleQuotes(' "text')).toBe('text') | ||
expect(trimSpacesAndRemoveDoubleQuotes('text" ')).toBe('text') | ||
expect(trimSpacesAndRemoveDoubleQuotes('text')).toBe('text') | ||
}) | ||
|
||
it('should handle empty strings', () => { | ||
expect(trimSpacesAndRemoveDoubleQuotes('')).toBe('') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
const regexGender = /Meisjes|Jongens|Vrouwen|Mannen/ | ||
export const stripGender = (categorie: string) => categorie.replace(regexGender, '').trim() | ||
|
||
export const isNullOrEmpty = (text: string) => text === undefined || text === null || text.length <= 0 | ||
export const trimSpacesAndRemoveDoubleQuotes = (text: string) => text.trim().split('"').join('') | ||
const regexGender = /Meisjes|Jongens|Vrouwen|Mannen/ | ||
export const stripGender = (categorie: string) => { | ||
if (categorie === null || categorie === undefined) { | ||
return '' | ||
} | ||
return categorie.replace(regexGender, '').trim() | ||
} | ||
|
||
export const isNullOrEmpty = (text: string) => text === undefined || text === null || text.length <= 0 | ||
export const trimSpacesAndRemoveDoubleQuotes = (text: string) => text.trim().split('"').join('') |