uodate wrap to handle empty items deletion and adding testcases for that feature

This commit is contained in:
Chesterkxng
2024-07-04 10:54:30 +00:00
parent 37c520d9ca
commit cc16fa5bb0
2 changed files with 59 additions and 1 deletions

View File

@@ -9,8 +9,10 @@ export function wrapList(
input: string,
splitSeparator: string,
joinSeparator: string,
deleteEmptyItems: boolean,
left: string = '',
right: string = ''
right: string = '',
): string {
let array: string[];
let wrappedArray: string[];
@@ -22,6 +24,9 @@ export function wrapList(
array = input.split(new RegExp(splitSeparator));
break;
}
if (deleteEmptyItems) {
array = array.filter(Boolean);
}
wrappedArray = wrap(array, left, right);
return wrappedArray.join(joinSeparator);
}