diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 9d2dab7..322cfcc 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,13 +4,8 @@
-
+
-
-
-
-
-
@@ -206,15 +201,7 @@
-
-
-
-
- 1719185893875
-
-
-
- 1719185893875
+
@@ -600,7 +587,15 @@
1720546921899
-
+
+
+ 1720558690146
+
+
+
+ 1720558690147
+
+
@@ -658,7 +653,6 @@
-
@@ -669,7 +663,8 @@
-
+
+
diff --git a/src/components/index.css b/src/components/index.css
index 7d8e343..8844a3f 100644
--- a/src/components/index.css
+++ b/src/components/index.css
@@ -3,5 +3,5 @@ a {
}
a:hover {
- color: #030362
+ color: #030362;
}
diff --git a/src/pages/list/find-most-popular/meta.ts b/src/pages/list/find-most-popular/meta.ts
index 309b33c..f973acb 100644
--- a/src/pages/list/find-most-popular/meta.ts
+++ b/src/pages/list/find-most-popular/meta.ts
@@ -10,4 +10,4 @@ export const tool = defineTool('list', {
shortDescription: '',
keywords: ['find', 'most', 'popular'],
component: lazy(() => import('./index'))
-});
\ No newline at end of file
+});
diff --git a/src/pages/list/find-most-popular/service.ts b/src/pages/list/find-most-popular/service.ts
index fd6e6fa..03bd144 100644
--- a/src/pages/list/find-most-popular/service.ts
+++ b/src/pages/list/find-most-popular/service.ts
@@ -44,7 +44,7 @@ function displayFormater(
dict: { [key: string]: number },
displayFormat: DisplayFormat
): string[] {
- let formattedOutput: string[] = [];
+ const formattedOutput: string[] = [];
const total = Object.values(dict).reduce((acc, val) => acc + val, 0);
switch (displayFormat) {
diff --git a/src/pages/list/find-unique/find-unique.service.test.ts b/src/pages/list/find-unique/find-unique.service.test.ts
index af1c2f5..192387e 100644
--- a/src/pages/list/find-unique/find-unique.service.test.ts
+++ b/src/pages/list/find-unique/find-unique.service.test.ts
@@ -5,43 +5,106 @@ import { TopItemsList } from './service';
describe('TopItemsList Function', () => {
test('should return unique items ignoring case sensitivity', () => {
const input = 'apple,banana,Apple,orange,Banana,apple';
- const result = TopItemsList('symbol', ',', '\n', input, true, true, false, true);
+ const result = TopItemsList(
+ 'symbol',
+ ',',
+ '\n',
+ input,
+ true,
+ true,
+ false,
+ true
+ );
expect(result).toBe('orange');
});
test('should return unique items considering case sensitivity', () => {
const input = 'apple,banana,Apple,orange,Banana,apple';
- const result = TopItemsList('symbol', ',', '\n', input, true, true, true, true);
+ const result = TopItemsList(
+ 'symbol',
+ ',',
+ '\n',
+ input,
+ true,
+ true,
+ true,
+ true
+ );
expect(result).toBe('banana\nApple\norange\nBanana');
});
test('should return all unique items ignoring case sensitivity', () => {
const input = 'apple,banana,Apple,orange,Banana,apple';
- const result = TopItemsList('symbol', ',', '\n', input, true, true, false, false);
+ const result = TopItemsList(
+ 'symbol',
+ ',',
+ '\n',
+ input,
+ true,
+ true,
+ false,
+ false
+ );
expect(result).toBe('apple\nbanana\norange');
});
test('should return all unique items considering case sensitivity', () => {
const input = 'apple,banana,Apple,orange,Banana,apple';
- const result = TopItemsList('symbol', ',', '\n', input, true, true, true, false);
+ const result = TopItemsList(
+ 'symbol',
+ ',',
+ '\n',
+ input,
+ true,
+ true,
+ true,
+ false
+ );
expect(result).toBe('apple\nbanana\nApple\norange\nBanana');
});
test('should handle empty items deletion', () => {
const input = 'apple,,banana, ,orange';
- const result = TopItemsList('symbol', ',', '\n', input, true, true, false, false);
+ const result = TopItemsList(
+ 'symbol',
+ ',',
+ '\n',
+ input,
+ true,
+ true,
+ false,
+ false
+ );
expect(result).toBe('apple\nbanana\norange');
});
test('should handle trimming items', () => {
const input = ' apple , banana , orange ';
- const result = TopItemsList('symbol', ',', '\n', input, false, false, false, false);
+ const result = TopItemsList(
+ 'symbol',
+ ',',
+ '\n',
+ input,
+ false,
+ false,
+ false,
+ false
+ );
expect(result).toBe(' apple \n banana \n orange ');
});
test('should handle regex split', () => {
const input = 'apple banana orange';
- const result = TopItemsList('regex', '\\s+', '\n', input, false, false, false, false);
+ const result = TopItemsList(
+ 'regex',
+ '\\s+',
+ '\n',
+ input,
+ false,
+ false,
+ false,
+ false
+ );
expect(result).toBe('apple\nbanana\norange');
});
});
diff --git a/src/pages/list/find-unique/index.tsx b/src/pages/list/find-unique/index.tsx
index 63b7b2f..12c1977 100644
--- a/src/pages/list/find-unique/index.tsx
+++ b/src/pages/list/find-unique/index.tsx
@@ -8,4 +8,4 @@ const validationSchema = Yup.object({
});
export default function FindUnique() {
return Lorem ipsum;
-}
\ No newline at end of file
+}
diff --git a/src/pages/list/find-unique/meta.ts b/src/pages/list/find-unique/meta.ts
index 149ec0b..aba8456 100644
--- a/src/pages/list/find-unique/meta.ts
+++ b/src/pages/list/find-unique/meta.ts
@@ -10,4 +10,4 @@ export const tool = defineTool('list', {
shortDescription: '',
keywords: ['find', 'unique'],
component: lazy(() => import('./index'))
-});
\ No newline at end of file
+});
diff --git a/src/pages/list/find-unique/service.ts b/src/pages/list/find-unique/service.ts
index bf35509..af62371 100644
--- a/src/pages/list/find-unique/service.ts
+++ b/src/pages/list/find-unique/service.ts
@@ -2,57 +2,63 @@ export type SplitOperatorType = 'symbol' | 'regex';
// Function that builds the unique items array handling caseSensitive and absolutelyUnique options
function uniqueListBuilder(
- array: string[],
- caseSensitive: boolean,
- absolutelyUnique: boolean
+ array: string[],
+ caseSensitive: boolean,
+ absolutelyUnique: boolean
): string[] {
- const dict: { [key: string]: number } = {};
- for (const item of array) {
- const key = caseSensitive ? item : item.toLowerCase();
- dict[key] = (dict[key] || 0) + 1;
+ const dict: { [key: string]: number } = {};
+ for (const item of array) {
+ const key = caseSensitive ? item : item.toLowerCase();
+ dict[key] = (dict[key] || 0) + 1;
+ }
+ if (absolutelyUnique) {
+ for (const [key, value] of Object.entries(dict)) {
+ if (value > 1) {
+ delete dict[key];
+ }
}
- if (absolutelyUnique) {
- for (const [key, value] of Object.entries(dict)) {
- if (value > 1) {
- delete dict[key];
- }
- }
- }
- return Object.keys(dict);
+ }
+ return Object.keys(dict);
}
export function TopItemsList(
- splitOperatorType: SplitOperatorType,
- splitSeparator: string,
- joinSeparator: string = '\n',
- input: string,
- deleteEmptyItems: boolean,
- trimItems: boolean,
- caseSensitive: boolean,
- absolutelyUnique: boolean
+ splitOperatorType: SplitOperatorType,
+ splitSeparator: string,
+ joinSeparator: string = '\n',
+ input: string,
+ deleteEmptyItems: boolean,
+ trimItems: boolean,
+ caseSensitive: boolean,
+ absolutelyUnique: boolean
): string {
- let array: string[];
- switch (splitOperatorType) {
- case 'symbol':
- array = input.split(splitSeparator);
- break;
- case 'regex':
- array = input.split(new RegExp(splitSeparator)).filter(item => item !== '');
- break;
- }
+ let array: string[];
+ switch (splitOperatorType) {
+ case 'symbol':
+ array = input.split(splitSeparator);
+ break;
+ case 'regex':
+ array = input
+ .split(new RegExp(splitSeparator))
+ .filter((item) => item !== '');
+ break;
+ }
- // Trim items if required
- if (trimItems) {
- array = array.map(item => item.trim());
- }
+ // Trim items if required
+ if (trimItems) {
+ array = array.map((item) => item.trim());
+ }
- // Delete empty items after initial split
- if (deleteEmptyItems) {
- array = array.filter(item => item !== '');
- }
+ // Delete empty items after initial split
+ if (deleteEmptyItems) {
+ array = array.filter((item) => item !== '');
+ }
- // Format the output with desired format
- const uniqueListItems = uniqueListBuilder(array, caseSensitive, absolutelyUnique);
+ // Format the output with desired format
+ const uniqueListItems = uniqueListBuilder(
+ array,
+ caseSensitive,
+ absolutelyUnique
+ );
- return uniqueListItems.join(joinSeparator);
+ return uniqueListItems.join(joinSeparator);
}
diff --git a/src/pages/list/group/group.service.test.ts b/src/pages/list/group/group.service.test.ts
index 18b0604..ae8cd5c 100644
--- a/src/pages/list/group/group.service.test.ts
+++ b/src/pages/list/group/group.service.test.ts
@@ -3,97 +3,97 @@ import { expect, describe, it } from 'vitest';
import { groupList, SplitOperatorType } from './service';
describe('groupList', () => {
- it('splits by symbol, groups, pads, and formats correctly', () => {
- const input = "a,b,c,d,e,f,g,h,i,j";
- const splitOperatorType: SplitOperatorType = 'symbol';
- const splitSeparator = ',';
- const groupNumber = 3;
- const itemSeparator = '-';
- const leftWrap = '[';
- const rightWrap = ']';
- const groupSeparator = ' | ';
- const deleteEmptyItems = false;
- const padNonFullGroup = true;
- const paddingChar = 'x';
+ it('splits by symbol, groups, pads, and formats correctly', () => {
+ const input = 'a,b,c,d,e,f,g,h,i,j';
+ const splitOperatorType: SplitOperatorType = 'symbol';
+ const splitSeparator = ',';
+ const groupNumber = 3;
+ const itemSeparator = '-';
+ const leftWrap = '[';
+ const rightWrap = ']';
+ const groupSeparator = ' | ';
+ const deleteEmptyItems = false;
+ const padNonFullGroup = true;
+ const paddingChar = 'x';
- const expectedOutput = "[a-b-c] | [d-e-f] | [g-h-i] | [j-x-x]";
+ const expectedOutput = '[a-b-c] | [d-e-f] | [g-h-i] | [j-x-x]';
- const result = groupList(
- splitOperatorType,
- splitSeparator,
- input,
- groupNumber,
- itemSeparator,
- leftWrap,
- rightWrap,
- groupSeparator,
- deleteEmptyItems,
- padNonFullGroup,
- paddingChar
- );
+ const result = groupList(
+ splitOperatorType,
+ splitSeparator,
+ input,
+ groupNumber,
+ itemSeparator,
+ leftWrap,
+ rightWrap,
+ groupSeparator,
+ deleteEmptyItems,
+ padNonFullGroup,
+ paddingChar
+ );
- expect(result).toBe(expectedOutput);
- });
+ expect(result).toBe(expectedOutput);
+ });
- it('handles regex split, no padding, and formats correctly', () => {
- const input = "a1b2c3d4e5f6g7h8i9j";
- const splitOperatorType: SplitOperatorType = 'regex';
- const splitSeparator = '\\d';
- const groupNumber = 4;
- const itemSeparator = ',';
- const leftWrap = '(';
- const rightWrap = ')';
- const groupSeparator = ' / ';
- const deleteEmptyItems = true;
- const padNonFullGroup = false;
+ it('handles regex split, no padding, and formats correctly', () => {
+ const input = 'a1b2c3d4e5f6g7h8i9j';
+ const splitOperatorType: SplitOperatorType = 'regex';
+ const splitSeparator = '\\d';
+ const groupNumber = 4;
+ const itemSeparator = ',';
+ const leftWrap = '(';
+ const rightWrap = ')';
+ const groupSeparator = ' / ';
+ const deleteEmptyItems = true;
+ const padNonFullGroup = false;
- const expectedOutput = "(a,b,c,d) / (e,f,g,h) / (i,j)";
+ const expectedOutput = '(a,b,c,d) / (e,f,g,h) / (i,j)';
- const result = groupList(
- splitOperatorType,
- splitSeparator,
- input,
- groupNumber,
- itemSeparator,
- leftWrap,
- rightWrap,
- groupSeparator,
- deleteEmptyItems,
- padNonFullGroup
- );
+ const result = groupList(
+ splitOperatorType,
+ splitSeparator,
+ input,
+ groupNumber,
+ itemSeparator,
+ leftWrap,
+ rightWrap,
+ groupSeparator,
+ deleteEmptyItems,
+ padNonFullGroup
+ );
- expect(result).toBe(expectedOutput);
- });
+ expect(result).toBe(expectedOutput);
+ });
- it('handles empty items removal and padd the last group with a z', () => {
- const input = "a,,b,,c,,d,,e,,";
- const splitOperatorType: SplitOperatorType = 'symbol';
- const splitSeparator = ',';
- const groupNumber = 2;
- const itemSeparator = ':';
- const leftWrap = '<';
- const rightWrap = '>';
- const groupSeparator = ' & ';
- const deleteEmptyItems = true;
- const padNonFullGroup = true;
- const paddingChar = 'z';
+ it('handles empty items removal and padd the last group with a z', () => {
+ const input = 'a,,b,,c,,d,,e,,';
+ const splitOperatorType: SplitOperatorType = 'symbol';
+ const splitSeparator = ',';
+ const groupNumber = 2;
+ const itemSeparator = ':';
+ const leftWrap = '<';
+ const rightWrap = '>';
+ const groupSeparator = ' & ';
+ const deleteEmptyItems = true;
+ const padNonFullGroup = true;
+ const paddingChar = 'z';
- const expectedOutput = " & & ";
+ const expectedOutput = ' & & ';
- const result = groupList(
- splitOperatorType,
- splitSeparator,
- input,
- groupNumber,
- itemSeparator,
- leftWrap,
- rightWrap,
- groupSeparator,
- deleteEmptyItems,
- padNonFullGroup,
- paddingChar
- );
+ const result = groupList(
+ splitOperatorType,
+ splitSeparator,
+ input,
+ groupNumber,
+ itemSeparator,
+ leftWrap,
+ rightWrap,
+ groupSeparator,
+ deleteEmptyItems,
+ padNonFullGroup,
+ paddingChar
+ );
- expect(result).toBe(expectedOutput);
- });
-});
\ No newline at end of file
+ expect(result).toBe(expectedOutput);
+ });
+});
diff --git a/src/pages/list/group/index.tsx b/src/pages/list/group/index.tsx
index 3134478..1bc9560 100644
--- a/src/pages/list/group/index.tsx
+++ b/src/pages/list/group/index.tsx
@@ -8,4 +8,4 @@ const validationSchema = Yup.object({
});
export default function Group() {
return Lorem ipsum;
-}
\ No newline at end of file
+}
diff --git a/src/pages/list/group/meta.ts b/src/pages/list/group/meta.ts
index 70d482e..84bda84 100644
--- a/src/pages/list/group/meta.ts
+++ b/src/pages/list/group/meta.ts
@@ -10,4 +10,4 @@ export const tool = defineTool('list', {
shortDescription: '',
keywords: ['group'],
component: lazy(() => import('./index'))
-});
\ No newline at end of file
+});
diff --git a/src/pages/list/group/service.ts b/src/pages/list/group/service.ts
index 245a564..dff7d7d 100644
--- a/src/pages/list/group/service.ts
+++ b/src/pages/list/group/service.ts
@@ -1,92 +1,94 @@
export type SplitOperatorType = 'symbol' | 'regex';
-
// function that split the array into an array of subarray of desired length
-function groupMaker(
- array: string[],
- groupNumber: number,
-): string[][] {
- const result: string[][] = [];
- for (let i = 0; i < array.length; i += groupNumber) {
- result.push(array.slice(i, i + groupNumber));
- }
- return result;
+function groupMaker(array: string[], groupNumber: number): string[][] {
+ const result: string[][] = [];
+ for (let i = 0; i < array.length; i += groupNumber) {
+ result.push(array.slice(i, i + groupNumber));
+ }
+ return result;
}
// function use to handle the case paddingNonFullGroup is enable
function groupFiller(
- array: string[][],
- groupNumber: number,
- padNonFullGroup: boolean,
- paddingChar: string = '',
+ array: string[][],
+ groupNumber: number,
+ padNonFullGroup: boolean,
+ paddingChar: string = ''
): string[][] {
- if (padNonFullGroup) {
- const lastSubArray: string[] = array[array.length - 1];
- if (lastSubArray.length < groupNumber) {
- for (let i = lastSubArray.length; i < groupNumber; i++) {
- lastSubArray.push(paddingChar);
- }
- }
- array[array.length - 1] = lastSubArray;
+ if (padNonFullGroup) {
+ const lastSubArray: string[] = array[array.length - 1];
+ if (lastSubArray.length < groupNumber) {
+ for (let i = lastSubArray.length; i < groupNumber; i++) {
+ lastSubArray.push(paddingChar);
+ }
}
- return array;
-
+ array[array.length - 1] = lastSubArray;
+ }
+ return array;
}
// function that join with the item separator and wrap with left and right each subArray of the Array
function groupJoinerAndWrapper(
- array: string[][],
- itemSeparator: string = '',
- leftWrap: string = '',
- rightWrap: string = '',
+ array: string[][],
+ itemSeparator: string = '',
+ leftWrap: string = '',
+ rightWrap: string = ''
): string[] {
- return array.map(subArray => {
- return leftWrap + subArray.join(itemSeparator) + rightWrap;
- });
+ return array.map((subArray) => {
+ return leftWrap + subArray.join(itemSeparator) + rightWrap;
+ });
}
-
export function groupList(
- splitOperatorType: SplitOperatorType,
- splitSeparator: string,
- input: string,
- groupNumber: number,
- itemSeparator: string = '',
- leftWrap: string = '',
- rightWrap: string = '',
- groupSeparator: string,
- deleteEmptyItems: boolean,
- padNonFullGroup: boolean,
- paddingChar: string = '',
-
+ splitOperatorType: SplitOperatorType,
+ splitSeparator: string,
+ input: string,
+ groupNumber: number,
+ itemSeparator: string = '',
+ leftWrap: string = '',
+ rightWrap: string = '',
+ groupSeparator: string,
+ deleteEmptyItems: boolean,
+ padNonFullGroup: boolean,
+ paddingChar: string = ''
): string {
- let array: string[];
- let splitedArray: string[][];
- let fullSplitedArray: string[][];
- let result: string[];
- switch (splitOperatorType) {
- case 'symbol':
- array = input.split(splitSeparator);
- break;
- case 'regex':
- array = input.split(new RegExp(splitSeparator));
- break;
- }
- // delete empty items after intial split
- if (deleteEmptyItems) {
- array = array.filter(item => item !== '');
- }
+ let array: string[];
+ let splitedArray: string[][];
+ let fullSplitedArray: string[][];
+ let result: string[];
+ switch (splitOperatorType) {
+ case 'symbol':
+ array = input.split(splitSeparator);
+ break;
+ case 'regex':
+ array = input.split(new RegExp(splitSeparator));
+ break;
+ }
+ // delete empty items after intial split
+ if (deleteEmptyItems) {
+ array = array.filter((item) => item !== '');
+ }
- // split the input into an array of subArray with the desired length
- splitedArray = groupMaker(array, groupNumber);
+ // split the input into an array of subArray with the desired length
+ splitedArray = groupMaker(array, groupNumber);
- // fill the last subArray is PadNonFullGroup is enabled
- fullSplitedArray = groupFiller(splitedArray, groupNumber, padNonFullGroup, paddingChar);
+ // fill the last subArray is PadNonFullGroup is enabled
+ fullSplitedArray = groupFiller(
+ splitedArray,
+ groupNumber,
+ padNonFullGroup,
+ paddingChar
+ );
- // get the list of formated subArray with the item separator and left and right wrapper
- result = groupJoinerAndWrapper(fullSplitedArray, itemSeparator, leftWrap, rightWrap);
+ // get the list of formated subArray with the item separator and left and right wrapper
+ result = groupJoinerAndWrapper(
+ fullSplitedArray,
+ itemSeparator,
+ leftWrap,
+ rightWrap
+ );
- // finnaly join the group separator before returning
- return result.join(groupSeparator);
+ // finnaly join the group separator before returning
+ return result.join(groupSeparator);
}
-
diff --git a/src/pages/list/reverse/index.tsx b/src/pages/list/reverse/index.tsx
index e017afe..1e40781 100644
--- a/src/pages/list/reverse/index.tsx
+++ b/src/pages/list/reverse/index.tsx
@@ -8,4 +8,4 @@ const validationSchema = Yup.object({
});
export default function Reverse() {
return Lorem ipsum;
-}
\ No newline at end of file
+}
diff --git a/src/pages/list/reverse/meta.ts b/src/pages/list/reverse/meta.ts
index 1ce2ba6..3500928 100644
--- a/src/pages/list/reverse/meta.ts
+++ b/src/pages/list/reverse/meta.ts
@@ -10,4 +10,4 @@ export const tool = defineTool('list', {
shortDescription: '',
keywords: ['reverse'],
component: lazy(() => import('./index'))
-});
\ No newline at end of file
+});
diff --git a/src/pages/list/reverse/reverse.service.test.ts b/src/pages/list/reverse/reverse.service.test.ts
index b2a468d..3f7bc2b 100644
--- a/src/pages/list/reverse/reverse.service.test.ts
+++ b/src/pages/list/reverse/reverse.service.test.ts
@@ -2,27 +2,27 @@ import { expect, describe, it } from 'vitest';
import { reverseList } from './service';
describe('reverseList Function', () => {
- test('should reverse items split by symbol', () => {
- const input = 'apple,banana,orange';
- const result = reverseList('symbol', ',', '\n', input);
- expect(result).toBe('orange\nbanana\napple');
- });
-
- test('should reverse items split by regex', () => {
- const input = 'apple banana orange';
- const result = reverseList('regex', '\\s+', '\n', input);
- expect(result).toBe('orange\nbanana\napple');
- });
-
- test('should handle empty input', () => {
- const input = '';
- const result = reverseList('symbol', ',', '\n', input);
- expect(result).toBe('');
- });
-
- test('should handle join separator', () => {
- const input = 'apple,banana,orange';
- const result = reverseList('symbol', ',', ', ', input);
- expect(result).toBe('orange, banana, apple');
- });
- });
\ No newline at end of file
+ test('should reverse items split by symbol', () => {
+ const input = 'apple,banana,orange';
+ const result = reverseList('symbol', ',', '\n', input);
+ expect(result).toBe('orange\nbanana\napple');
+ });
+
+ test('should reverse items split by regex', () => {
+ const input = 'apple banana orange';
+ const result = reverseList('regex', '\\s+', '\n', input);
+ expect(result).toBe('orange\nbanana\napple');
+ });
+
+ test('should handle empty input', () => {
+ const input = '';
+ const result = reverseList('symbol', ',', '\n', input);
+ expect(result).toBe('');
+ });
+
+ test('should handle join separator', () => {
+ const input = 'apple,banana,orange';
+ const result = reverseList('symbol', ',', ', ', input);
+ expect(result).toBe('orange, banana, apple');
+ });
+});
diff --git a/src/pages/list/reverse/service.ts b/src/pages/list/reverse/service.ts
index a172f53..cae6cb4 100644
--- a/src/pages/list/reverse/service.ts
+++ b/src/pages/list/reverse/service.ts
@@ -1,21 +1,23 @@
type SplitOperatorType = 'symbol' | 'regex';
export function reverseList(
- splitOperatorType: SplitOperatorType,
- splitSeparator: string,
- joinSeparator: string = '\n',
- input: string,
+ splitOperatorType: SplitOperatorType,
+ splitSeparator: string,
+ joinSeparator: string = '\n',
+ input: string
): string {
- let array: string[] = [];
- switch (splitOperatorType) {
- case 'symbol':
- array = input.split(splitSeparator);
- break;
- case 'regex':
- array = input.split(new RegExp(splitSeparator)).filter(item => item !== '');
- break;
- }
+ let array: string[] = [];
+ switch (splitOperatorType) {
+ case 'symbol':
+ array = input.split(splitSeparator);
+ break;
+ case 'regex':
+ array = input
+ .split(new RegExp(splitSeparator))
+ .filter((item) => item !== '');
+ break;
+ }
- const reversedList = array.reverse();
- return reversedList.join(joinSeparator);
+ const reversedList = array.reverse();
+ return reversedList.join(joinSeparator);
}
diff --git a/src/pages/list/rotate/index.tsx b/src/pages/list/rotate/index.tsx
index ea7d7d5..4f8cbb8 100644
--- a/src/pages/list/rotate/index.tsx
+++ b/src/pages/list/rotate/index.tsx
@@ -8,4 +8,4 @@ const validationSchema = Yup.object({
});
export default function Rotate() {
return Lorem ipsum;
-}
\ No newline at end of file
+}
diff --git a/src/pages/list/rotate/meta.ts b/src/pages/list/rotate/meta.ts
index 506b51e..07ddfd6 100644
--- a/src/pages/list/rotate/meta.ts
+++ b/src/pages/list/rotate/meta.ts
@@ -10,4 +10,4 @@ export const tool = defineTool('list', {
shortDescription: '',
keywords: ['rotate'],
component: lazy(() => import('./index'))
-});
\ No newline at end of file
+});
diff --git a/src/pages/list/rotate/rotate.service.test.ts b/src/pages/list/rotate/rotate.service.test.ts
index 9b68933..ba5e543 100644
--- a/src/pages/list/rotate/rotate.service.test.ts
+++ b/src/pages/list/rotate/rotate.service.test.ts
@@ -1,110 +1,105 @@
import { expect, describe, it } from 'vitest';
-import {
- SplitOperatorType,
- rotateList
-} from './service';
+import { SplitOperatorType, rotateList } from './service';
describe('rotate function', () => {
- it('should rotate right side if right is set to true', () => {
- const input: string = 'apple, pineaple, lemon, orange, mango';
- const splitOperatorType: SplitOperatorType = 'symbol';
- const splitSeparator = ', ';
- const joinSeparator = ' ';
- const step = 1;
- const right = true;
+ it('should rotate right side if right is set to true', () => {
+ const input: string = 'apple, pineaple, lemon, orange, mango';
+ const splitOperatorType: SplitOperatorType = 'symbol';
+ const splitSeparator = ', ';
+ const joinSeparator = ' ';
+ const step = 1;
+ const right = true;
- const result = rotateList(
- splitOperatorType,
- input,
- splitSeparator,
- joinSeparator,
- right,
+ const result = rotateList(
+ splitOperatorType,
+ input,
+ splitSeparator,
+ joinSeparator,
+ right,
- step);
+ step
+ );
- expect(result).toBe('mango apple pineaple lemon orange');
+ expect(result).toBe('mango apple pineaple lemon orange');
+ });
- });
+ it('should rotate left side if right is set to true', () => {
+ const input: string = 'apple, pineaple, lemon, orange, mango';
+ const splitOperatorType: SplitOperatorType = 'symbol';
+ const splitSeparator = ', ';
+ const joinSeparator = ' ';
+ const step = 1;
+ const right = false;
- it('should rotate left side if right is set to true', () => {
- const input: string = 'apple, pineaple, lemon, orange, mango';
- const splitOperatorType: SplitOperatorType = 'symbol';
- const splitSeparator = ', ';
- const joinSeparator = ' ';
- const step = 1;
- const right = false;
+ const result = rotateList(
+ splitOperatorType,
+ input,
+ splitSeparator,
+ joinSeparator,
+ right,
- const result = rotateList(
- splitOperatorType,
- input,
- splitSeparator,
- joinSeparator,
- right,
+ step
+ );
- step);
+ expect(result).toBe('pineaple lemon orange mango apple');
+ });
- expect(result).toBe('pineaple lemon orange mango apple');
+ it('should rotate left side with 2 step if right is set to true', () => {
+ const input: string = 'apple, pineaple, lemon, orange, mango';
+ const splitOperatorType: SplitOperatorType = 'symbol';
+ const splitSeparator = ', ';
+ const joinSeparator = ' ';
+ const step = 2;
+ const right = false;
- });
+ const result = rotateList(
+ splitOperatorType,
+ input,
+ splitSeparator,
+ joinSeparator,
+ right,
- it('should rotate left side with 2 step if right is set to true', () => {
- const input: string = 'apple, pineaple, lemon, orange, mango';
- const splitOperatorType: SplitOperatorType = 'symbol';
- const splitSeparator = ', ';
- const joinSeparator = ' ';
- const step = 2;
- const right = false;
+ step
+ );
- const result = rotateList(
- splitOperatorType,
- input,
- splitSeparator,
- joinSeparator,
- right,
+ expect(result).toBe('lemon orange mango apple pineaple');
+ });
- step);
+ it('should raise an error if step is negative', () => {
+ const input: string = 'apple, pineaple, lemon, orange, mango';
+ const splitOperatorType: SplitOperatorType = 'symbol';
+ const splitSeparator = ', ';
+ const joinSeparator = ' ';
+ const step = -2;
+ const right = false;
- expect(result).toBe('lemon orange mango apple pineaple');
+ expect(() => {
+ rotateList(
+ splitOperatorType,
+ input,
+ splitSeparator,
+ joinSeparator,
+ right,
+ step
+ );
+ }).toThrowError('Rotation step must be greater than zero.');
+ });
- });
+ it('should raise an error if step is undefined', () => {
+ const input: string = 'apple, pineaple, lemon, orange, mango';
+ const splitOperatorType: SplitOperatorType = 'symbol';
+ const splitSeparator = ', ';
+ const joinSeparator = ' ';
+ const right = false;
- it('should raise an error if step is negative', () => {
- const input: string = 'apple, pineaple, lemon, orange, mango';
- const splitOperatorType: SplitOperatorType = 'symbol';
- const splitSeparator = ', ';
- const joinSeparator = ' ';
- const step = -2;
- const right = false;
-
- expect(() => {
- rotateList(
- splitOperatorType,
- input,
- splitSeparator,
- joinSeparator,
- right,
- step);
- }).toThrowError('Rotation step must be greater than zero.');
-
- });
-
- it('should raise an error if step is undefined', () => {
- const input: string = 'apple, pineaple, lemon, orange, mango';
- const splitOperatorType: SplitOperatorType = 'symbol';
- const splitSeparator = ', ';
- const joinSeparator = ' ';
- const right = false;
-
- expect(() => {
- rotateList(
- splitOperatorType,
- input,
- splitSeparator,
- joinSeparator,
- right);
- }).toThrowError('Rotation step contains non-digits.');
-
- });
-
-
-})
\ No newline at end of file
+ expect(() => {
+ rotateList(
+ splitOperatorType,
+ input,
+ splitSeparator,
+ joinSeparator,
+ right
+ );
+ }).toThrowError('Rotation step contains non-digits.');
+ });
+});
diff --git a/src/pages/list/rotate/service.ts b/src/pages/list/rotate/service.ts
index 9a27957..65d183b 100644
--- a/src/pages/list/rotate/service.ts
+++ b/src/pages/list/rotate/service.ts
@@ -1,48 +1,49 @@
import { isNumber } from 'utils/string';
export type SplitOperatorType = 'symbol' | 'regex';
-function rotateArray(
- array: string[],
- step: number,
- right: boolean): string[] {
- const length = array.length;
+function rotateArray(array: string[], step: number, right: boolean): string[] {
+ const length = array.length;
- // Normalize the step to be within the bounds of the array length
- const normalizedPositions = ((step % length) + length) % length;
+ // Normalize the step to be within the bounds of the array length
+ const normalizedPositions = ((step % length) + length) % length;
- if (right) {
- // Rotate right
- return array.slice(-normalizedPositions).concat(array.slice(0, -normalizedPositions));
- } else {
- // Rotate left
- return array.slice(normalizedPositions).concat(array.slice(0, normalizedPositions));
- }
+ if (right) {
+ // Rotate right
+ return array
+ .slice(-normalizedPositions)
+ .concat(array.slice(0, -normalizedPositions));
+ } else {
+ // Rotate left
+ return array
+ .slice(normalizedPositions)
+ .concat(array.slice(0, normalizedPositions));
+ }
}
export function rotateList(
- splitOperatorType: SplitOperatorType,
- input: string,
- splitSeparator: string,
- joinSeparator: string,
- right: boolean,
- step?: number,
+ splitOperatorType: SplitOperatorType,
+ input: string,
+ splitSeparator: string,
+ joinSeparator: string,
+ right: boolean,
+ step?: number
): string {
- let array: string[];
- let rotatedArray: string[];
- switch (splitOperatorType) {
- case 'symbol':
- array = input.split(splitSeparator);
- break;
- case 'regex':
- array = input.split(new RegExp(splitSeparator));
- break;
+ let array: string[];
+ let rotatedArray: string[];
+ switch (splitOperatorType) {
+ case 'symbol':
+ array = input.split(splitSeparator);
+ break;
+ case 'regex':
+ array = input.split(new RegExp(splitSeparator));
+ break;
+ }
+ if (step !== undefined) {
+ if (step <= 0) {
+ throw new Error('Rotation step must be greater than zero.');
}
- if (step !== undefined) {
- if (step <= 0) {
- throw new Error("Rotation step must be greater than zero.");
- }
- rotatedArray = rotateArray(array, step, right);
- return rotatedArray.join(joinSeparator);
- }
- throw new Error("Rotation step contains non-digits.")
-}
\ No newline at end of file
+ rotatedArray = rotateArray(array, step, right);
+ return rotatedArray.join(joinSeparator);
+ }
+ throw new Error('Rotation step contains non-digits.');
+}
diff --git a/src/pages/list/shuffle/index.tsx b/src/pages/list/shuffle/index.tsx
index c4ba61b..3e4f97a 100644
--- a/src/pages/list/shuffle/index.tsx
+++ b/src/pages/list/shuffle/index.tsx
@@ -8,4 +8,4 @@ const validationSchema = Yup.object({
});
export default function Shuffle() {
return Lorem ipsum;
-}
\ No newline at end of file
+}
diff --git a/src/pages/list/shuffle/meta.ts b/src/pages/list/shuffle/meta.ts
index 441b9a2..e193363 100644
--- a/src/pages/list/shuffle/meta.ts
+++ b/src/pages/list/shuffle/meta.ts
@@ -10,4 +10,4 @@ export const tool = defineTool('list', {
shortDescription: '',
keywords: ['shuffle'],
component: lazy(() => import('./index'))
-});
\ No newline at end of file
+});
diff --git a/src/pages/list/shuffle/service.ts b/src/pages/list/shuffle/service.ts
index f75bb90..e6bc9e1 100644
--- a/src/pages/list/shuffle/service.ts
+++ b/src/pages/list/shuffle/service.ts
@@ -2,37 +2,37 @@ export type SplitOperatorType = 'symbol' | 'regex';
// function that randomize the array
function shuffleArray(array: string[]): string[] {
- let shuffledArray = array.slice(); // Create a copy of the array
- for (let i = shuffledArray.length - 1; i > 0; i--) {
- const j = Math.floor(Math.random() * (i + 1));
- [shuffledArray[i], shuffledArray[j]] = [shuffledArray[j], shuffledArray[i]];
- }
- return shuffledArray;
+ const shuffledArray = array.slice(); // Create a copy of the array
+ for (let i = shuffledArray.length - 1; i > 0; i--) {
+ const j = Math.floor(Math.random() * (i + 1));
+ [shuffledArray[i], shuffledArray[j]] = [shuffledArray[j], shuffledArray[i]];
+ }
+ return shuffledArray;
}
export function shuffleList(
- splitOperatorType: SplitOperatorType,
- input: string,
- splitSeparator: string,
- joinSeparator: string,
- length?: number, // "?" is to handle the case the user let the input blank
-) : string {
- let array: string[];
- let shuffledArray: string[];
- switch (splitOperatorType) {
- case 'symbol':
- array = input.split(splitSeparator);
- break;
- case 'regex':
- array = input.split(new RegExp(splitSeparator));
- break;
+ splitOperatorType: SplitOperatorType,
+ input: string,
+ splitSeparator: string,
+ joinSeparator: string,
+ length?: number // "?" is to handle the case the user let the input blank
+): string {
+ let array: string[];
+ let shuffledArray: string[];
+ switch (splitOperatorType) {
+ case 'symbol':
+ array = input.split(splitSeparator);
+ break;
+ case 'regex':
+ array = input.split(new RegExp(splitSeparator));
+ break;
+ }
+ shuffledArray = shuffleArray(array);
+ if (length !== undefined) {
+ if (length <= 0) {
+ throw new Error('Length value must be a positive number.');
}
- shuffledArray = shuffleArray(array);
- if (length !== undefined) {
- if (length <= 0) {
- throw new Error("Length value must be a positive number.");
- }
- return shuffledArray.slice(0, length).join(joinSeparator);
- }
- return shuffledArray.join(joinSeparator);
-}
\ No newline at end of file
+ return shuffledArray.slice(0, length).join(joinSeparator);
+ }
+ return shuffledArray.join(joinSeparator);
+}
diff --git a/src/pages/list/shuffle/shuffle.service.test.ts b/src/pages/list/shuffle/shuffle.service.test.ts
index feb911a..58808c9 100644
--- a/src/pages/list/shuffle/shuffle.service.test.ts
+++ b/src/pages/list/shuffle/shuffle.service.test.ts
@@ -1,94 +1,89 @@
import { expect, describe, it } from 'vitest';
-import {
- shuffleList,
- SplitOperatorType
- } from './service';
+import { shuffleList, SplitOperatorType } from './service';
describe('shuffle function', () => {
+ it('should be a 4 length list if no length value defined ', () => {
+ const input: string = 'apple, pineaple, lemon, orange';
+ const splitOperatorType: SplitOperatorType = 'symbol';
+ const splitSeparator = ', ';
+ const joinSeparator = ' ';
- it('should be a 4 length list if no length value defined ', () => {
- const input: string = 'apple, pineaple, lemon, orange';
- const splitOperatorType: SplitOperatorType = 'symbol';
- const splitSeparator = ', ';
- const joinSeparator = ' ';
-
- const result = shuffleList(
- splitOperatorType,
- input,
- splitSeparator,
- joinSeparator
- );
- expect(result.split(joinSeparator).length).toBe(4);
- });
+ const result = shuffleList(
+ splitOperatorType,
+ input,
+ splitSeparator,
+ joinSeparator
+ );
+ expect(result.split(joinSeparator).length).toBe(4);
+ });
- it('should be a 2 length list if length value is set to 2', () => {
- const input: string = 'apple, pineaple, lemon, orange';
- const splitOperatorType: SplitOperatorType = 'symbol';
- const splitSeparator = ', ';
- const joinSeparator = ' ';
- const length = 2;
-
- const result = shuffleList(
- splitOperatorType,
- input,
- splitSeparator,
- joinSeparator,
- length
- );
- console.log(result);
- expect(result.split(joinSeparator).length).toBe(2);
- });
+ it('should be a 2 length list if length value is set to 2', () => {
+ const input: string = 'apple, pineaple, lemon, orange';
+ const splitOperatorType: SplitOperatorType = 'symbol';
+ const splitSeparator = ', ';
+ const joinSeparator = ' ';
+ const length = 2;
- it('should be a 4 length list if length value is set to 99', () => {
- const input: string = 'apple, pineaple, lemon, orange';
- const splitOperatorType: SplitOperatorType = 'symbol';
- const splitSeparator = ', ';
- const joinSeparator = ' ';
- const length = 99;
-
- const result = shuffleList(
- splitOperatorType,
- input,
- splitSeparator,
- joinSeparator,
- length
- );
- console.log(result);
- expect(result.split(joinSeparator).length).toBe(4);
- });
+ const result = shuffleList(
+ splitOperatorType,
+ input,
+ splitSeparator,
+ joinSeparator,
+ length
+ );
+ console.log(result);
+ expect(result.split(joinSeparator).length).toBe(2);
+ });
- it('should include a random element if length value is undefined', () => {
- const input: string = 'apple, pineaple, lemon, orange';
- const splitOperatorType: SplitOperatorType = 'symbol';
- const splitSeparator = ', ';
- const joinSeparator = ' ';
-
- const result = shuffleList(
- splitOperatorType,
- input,
- splitSeparator,
- joinSeparator,
- length
- );
- console.log(result);
- expect(result.split(joinSeparator)).toContain('apple');
- });
+ it('should be a 4 length list if length value is set to 99', () => {
+ const input: string = 'apple, pineaple, lemon, orange';
+ const splitOperatorType: SplitOperatorType = 'symbol';
+ const splitSeparator = ', ';
+ const joinSeparator = ' ';
+ const length = 99;
- it('should return empty string if input is empty', () => {
- const input: string = '';
- const splitOperatorType: SplitOperatorType = 'symbol';
- const splitSeparator = ', ';
- const joinSeparator = ' ';
-
- const result = shuffleList(
- splitOperatorType,
- input,
- splitSeparator,
- joinSeparator,
- length
- );
- console.log(result);
- expect(result).toBe('');
- });
+ const result = shuffleList(
+ splitOperatorType,
+ input,
+ splitSeparator,
+ joinSeparator,
+ length
+ );
+ console.log(result);
+ expect(result.split(joinSeparator).length).toBe(4);
+ });
- })
\ No newline at end of file
+ it('should include a random element if length value is undefined', () => {
+ const input: string = 'apple, pineaple, lemon, orange';
+ const splitOperatorType: SplitOperatorType = 'symbol';
+ const splitSeparator = ', ';
+ const joinSeparator = ' ';
+
+ const result = shuffleList(
+ splitOperatorType,
+ input,
+ splitSeparator,
+ joinSeparator,
+ length
+ );
+ console.log(result);
+ expect(result.split(joinSeparator)).toContain('apple');
+ });
+
+ it('should return empty string if input is empty', () => {
+ const input: string = '';
+ const splitOperatorType: SplitOperatorType = 'symbol';
+ const splitSeparator = ', ';
+ const joinSeparator = ' ';
+
+ const result = shuffleList(
+ splitOperatorType,
+ input,
+ splitSeparator,
+ joinSeparator,
+ length
+ );
+ console.log(result);
+ expect(result).toBe('');
+ });
+});
diff --git a/src/pages/list/truncate/index.tsx b/src/pages/list/truncate/index.tsx
index e7a5097..f46ad17 100644
--- a/src/pages/list/truncate/index.tsx
+++ b/src/pages/list/truncate/index.tsx
@@ -8,4 +8,4 @@ const validationSchema = Yup.object({
});
export default function Truncate() {
return Lorem ipsum;
-}
\ No newline at end of file
+}
diff --git a/src/pages/list/truncate/meta.ts b/src/pages/list/truncate/meta.ts
index efd7ac3..95cc0ec 100644
--- a/src/pages/list/truncate/meta.ts
+++ b/src/pages/list/truncate/meta.ts
@@ -10,4 +10,4 @@ export const tool = defineTool('list', {
shortDescription: '',
keywords: ['truncate'],
component: lazy(() => import('./index'))
-});
\ No newline at end of file
+});
diff --git a/src/pages/list/truncate/service.ts b/src/pages/list/truncate/service.ts
index 0ac2dfa..6769ef5 100644
--- a/src/pages/list/truncate/service.ts
+++ b/src/pages/list/truncate/service.ts
@@ -1,30 +1,31 @@
export type SplitOperatorType = 'symbol' | 'regex';
export function truncateList(
- splitOperatorType: SplitOperatorType,
- input: string,
- splitSeparator: string,
- joinSeparator: string,
- end: boolean,
- length?: number,
+ splitOperatorType: SplitOperatorType,
+ input: string,
+ splitSeparator: string,
+ joinSeparator: string,
+ end: boolean,
+ length?: number
): string {
- let array: string[];
- let truncatedArray: string[];
- switch (splitOperatorType) {
- case 'symbol':
- array = input.split(splitSeparator);
- break;
- case 'regex':
- array = input.split(new RegExp(splitSeparator));
- break;
+ let array: string[];
+ let truncatedArray: string[];
+ switch (splitOperatorType) {
+ case 'symbol':
+ array = input.split(splitSeparator);
+ break;
+ case 'regex':
+ array = input.split(new RegExp(splitSeparator));
+ break;
+ }
+ if (length !== undefined) {
+ if (length < 0) {
+ throw new Error('Length value must be a positive number.');
}
- if (length !== undefined) {
- if (length < 0) {
- throw new Error("Length value must be a positive number.")
- }
- truncatedArray = end ? array.slice(0, length) : array.slice(array.length - length, array.length);
- return truncatedArray.join(joinSeparator);
- }
- throw new Error("Length value isn't a value number.");
-
-}
\ No newline at end of file
+ truncatedArray = end
+ ? array.slice(0, length)
+ : array.slice(array.length - length, array.length);
+ return truncatedArray.join(joinSeparator);
+ }
+ throw new Error("Length value isn't a value number.");
+}
diff --git a/src/pages/list/truncate/truncate.service.test.ts b/src/pages/list/truncate/truncate.service.test.ts
index c941f97..79d1763 100644
--- a/src/pages/list/truncate/truncate.service.test.ts
+++ b/src/pages/list/truncate/truncate.service.test.ts
@@ -1,185 +1,183 @@
import { expect, describe, it } from 'vitest';
-import {
- SplitOperatorType,
- truncateList,
-} from './service';
+import { SplitOperatorType, truncateList } from './service';
describe('truncate function', () => {
- it('should remove at the end (one element) if end is set to true', () => {
- const input: string = 'apple, pineaple, lemon, orange';
- const splitOperatorType: SplitOperatorType = 'symbol';
- const splitSeparator = ', ';
- const joinSeparator = ' ';
- const end = true;
- const length = 3;
+ it('should remove at the end (one element) if end is set to true', () => {
+ const input: string = 'apple, pineaple, lemon, orange';
+ const splitOperatorType: SplitOperatorType = 'symbol';
+ const splitSeparator = ', ';
+ const joinSeparator = ' ';
+ const end = true;
+ const length = 3;
- const result = truncateList(
- splitOperatorType,
- input,
- splitSeparator,
- joinSeparator,
- end,
- length);
+ const result = truncateList(
+ splitOperatorType,
+ input,
+ splitSeparator,
+ joinSeparator,
+ end,
+ length
+ );
- expect(result).toBe('apple pineaple lemon');
+ expect(result).toBe('apple pineaple lemon');
+ });
- });
+ it('should return 3 elements from the start if end is set to true', () => {
+ const input: string = 'apple, pineaple, lemon, orange, mango';
+ const splitOperatorType: SplitOperatorType = 'symbol';
+ const splitSeparator = ', ';
+ const joinSeparator = ' ';
+ const end = true;
+ const length = 3;
- it('should return 3 elements from the start if end is set to true', () => {
- const input: string = 'apple, pineaple, lemon, orange, mango';
- const splitOperatorType: SplitOperatorType = 'symbol';
- const splitSeparator = ', ';
- const joinSeparator = ' ';
- const end = true;
- const length = 3;
+ const result = truncateList(
+ splitOperatorType,
+ input,
+ splitSeparator,
+ joinSeparator,
+ end,
+ length
+ );
- const result = truncateList(
- splitOperatorType,
- input,
- splitSeparator,
- joinSeparator,
- end,
- length);
+ expect(result).toBe('apple pineaple lemon');
+ });
- expect(result).toBe('apple pineaple lemon');
+ it('should return 3 elements from the start if end is set to true', () => {
+ const input: string = 'apple, pineaple, lemon, orange, mango';
+ const splitOperatorType: SplitOperatorType = 'symbol';
+ const splitSeparator = ', ';
+ const joinSeparator = ' ';
+ const end = true;
+ const length = 3;
- });
+ const result = truncateList(
+ splitOperatorType,
+ input,
+ splitSeparator,
+ joinSeparator,
+ end,
+ length
+ );
- it('should return 3 elements from the start if end is set to true', () => {
- const input: string = 'apple, pineaple, lemon, orange, mango';
- const splitOperatorType: SplitOperatorType = 'symbol';
- const splitSeparator = ', ';
- const joinSeparator = ' ';
- const end = true;
- const length = 3;
+ expect(result).toBe('apple pineaple lemon');
+ });
- const result = truncateList(
- splitOperatorType,
- input,
- splitSeparator,
- joinSeparator,
- end,
- length);
+ it('should return 3 elements from the end if end is set to true', () => {
+ const input: string = 'apple, pineaple, lemon, orange, mango';
+ const splitOperatorType: SplitOperatorType = 'symbol';
+ const splitSeparator = ', ';
+ const joinSeparator = ' ';
+ const end = false;
+ const length = 3;
- expect(result).toBe('apple pineaple lemon');
+ const result = truncateList(
+ splitOperatorType,
+ input,
+ splitSeparator,
+ joinSeparator,
+ end,
+ length
+ );
- });
+ expect(result).toBe('lemon orange mango');
+ });
- it('should return 3 elements from the end if end is set to true', () => {
- const input: string = 'apple, pineaple, lemon, orange, mango';
- const splitOperatorType: SplitOperatorType = 'symbol';
- const splitSeparator = ', ';
- const joinSeparator = ' ';
- const end = false;
- const length = 3;
+ it('should return a void string if length is set to 0', () => {
+ const input: string = 'apple, pineaple, lemon, orange, mango';
+ const splitOperatorType: SplitOperatorType = 'symbol';
+ const splitSeparator = ', ';
+ const joinSeparator = ' ';
+ const end = false;
+ const length = 0;
- const result = truncateList(
- splitOperatorType,
- input,
- splitSeparator,
- joinSeparator,
- end,
- length);
+ const result = truncateList(
+ splitOperatorType,
+ input,
+ splitSeparator,
+ joinSeparator,
+ end,
+ length
+ );
- expect(result).toBe('lemon orange mango');
+ expect(result).toBe('');
+ });
- });
+ it('should return an element (first) string if length is set to 1 and end is set to true', () => {
+ const input: string = 'apple, pineaple, lemon, orange, mango';
+ const splitOperatorType: SplitOperatorType = 'symbol';
+ const splitSeparator = ', ';
+ const joinSeparator = ' ';
+ const end = true;
+ const length = 1;
- it('should return a void string if length is set to 0', () => {
- const input: string = 'apple, pineaple, lemon, orange, mango';
- const splitOperatorType: SplitOperatorType = 'symbol';
- const splitSeparator = ', ';
- const joinSeparator = ' ';
- const end = false;
- const length = 0;
+ const result = truncateList(
+ splitOperatorType,
+ input,
+ splitSeparator,
+ joinSeparator,
+ end,
+ length
+ );
- const result = truncateList(
- splitOperatorType,
- input,
- splitSeparator,
- joinSeparator,
- end,
- length);
+ expect(result).toBe('apple');
+ });
- expect(result).toBe('');
+ it('should return an element (last) string if length is set to 1 and end is set to false', () => {
+ const input: string = 'apple, pineaple, lemon, orange, mango';
+ const splitOperatorType: SplitOperatorType = 'symbol';
+ const splitSeparator = ', ';
+ const joinSeparator = ' ';
+ const end = false;
+ const length = 1;
- });
+ const result = truncateList(
+ splitOperatorType,
+ input,
+ splitSeparator,
+ joinSeparator,
+ end,
+ length
+ );
- it('should return an element (first) string if length is set to 1 and end is set to true', () => {
- const input: string = 'apple, pineaple, lemon, orange, mango';
- const splitOperatorType: SplitOperatorType = 'symbol';
- const splitSeparator = ', ';
- const joinSeparator = ' ';
- const end = true;
- const length = 1;
+ expect(result).toBe('mango');
+ });
- const result = truncateList(
- splitOperatorType,
- input,
- splitSeparator,
- joinSeparator,
- end,
- length);
+ it('should throw an error if the length value is negative', () => {
+ const input: string = 'apple, pineaple, lemon, orange, mango';
+ const splitOperatorType: SplitOperatorType = 'symbol';
+ const splitSeparator = ', ';
+ const joinSeparator = ' ';
+ const end = false;
+ const length = -5;
- expect(result).toBe('apple');
+ expect(() => {
+ truncateList(
+ splitOperatorType,
+ input,
+ splitSeparator,
+ joinSeparator,
+ end,
+ length
+ );
+ }).toThrow('Length value must be a positive number.');
+ });
- });
+ it('should throw an error if the length value is left blank', () => {
+ const input: string = 'apple, pineaple, lemon, orange, mango';
+ const splitOperatorType: SplitOperatorType = 'symbol';
+ const splitSeparator = ', ';
+ const joinSeparator = ' ';
+ const end = false;
- it('should return an element (last) string if length is set to 1 and end is set to false', () => {
- const input: string = 'apple, pineaple, lemon, orange, mango';
- const splitOperatorType: SplitOperatorType = 'symbol';
- const splitSeparator = ', ';
- const joinSeparator = ' ';
- const end = false;
- const length = 1;
-
- const result = truncateList(
- splitOperatorType,
- input,
- splitSeparator,
- joinSeparator,
- end,
- length);
-
- expect(result).toBe('mango');
-
- });
-
- it('should throw an error if the length value is negative', () => {
- const input: string = 'apple, pineaple, lemon, orange, mango';
- const splitOperatorType: SplitOperatorType = 'symbol';
- const splitSeparator = ', ';
- const joinSeparator = ' ';
- const end = false;
- const length = -5;
-
- expect(() => {
- truncateList(
- splitOperatorType,
- input,
- splitSeparator,
- joinSeparator,
- end,
- length)
- }).toThrow("Length value must be a positive number.");
- });
-
- it('should throw an error if the length value is left blank', () => {
- const input: string = 'apple, pineaple, lemon, orange, mango';
- const splitOperatorType: SplitOperatorType = 'symbol';
- const splitSeparator = ', ';
- const joinSeparator = ' ';
- const end = false;
-
- expect(() => {
- truncateList(
- splitOperatorType,
- input,
- splitSeparator,
- joinSeparator,
- end)
- }).toThrow("Length value isn't a value number.");
- });
-
-})
\ No newline at end of file
+ expect(() => {
+ truncateList(
+ splitOperatorType,
+ input,
+ splitSeparator,
+ joinSeparator,
+ end
+ );
+ }).toThrow("Length value isn't a value number.");
+ });
+});
diff --git a/src/pages/list/unwrap/index.tsx b/src/pages/list/unwrap/index.tsx
index 43db753..3c4b34d 100644
--- a/src/pages/list/unwrap/index.tsx
+++ b/src/pages/list/unwrap/index.tsx
@@ -8,4 +8,4 @@ const validationSchema = Yup.object({
});
export default function Unwrap() {
return Lorem ipsum;
-}
\ No newline at end of file
+}
diff --git a/src/pages/list/unwrap/meta.ts b/src/pages/list/unwrap/meta.ts
index a65c5b5..c526721 100644
--- a/src/pages/list/unwrap/meta.ts
+++ b/src/pages/list/unwrap/meta.ts
@@ -10,4 +10,4 @@ export const tool = defineTool('list', {
shortDescription: '',
keywords: ['unwrap'],
component: lazy(() => import('./index'))
-});
\ No newline at end of file
+});
diff --git a/src/pages/list/unwrap/service.ts b/src/pages/list/unwrap/service.ts
index d66a107..14ff6ba 100644
--- a/src/pages/list/unwrap/service.ts
+++ b/src/pages/list/unwrap/service.ts
@@ -1,69 +1,69 @@
export type SplitOperatorType = 'symbol' | 'regex';
function leftUnwrap(
- row: string,
- left: string = '',
- multiLevel: boolean
+ row: string,
+ left: string = '',
+ multiLevel: boolean
): string {
- if (left === '') return row; // Prevent infinite loop if left is an empty string
- while (row.startsWith(left)) {
- row = row.slice(left.length);
- if (!multiLevel) {
- break;
- }
+ if (left === '') return row; // Prevent infinite loop if left is an empty string
+ while (row.startsWith(left)) {
+ row = row.slice(left.length);
+ if (!multiLevel) {
+ break;
}
- return row;
+ }
+ return row;
}
function rightUnwrap(
- row: string,
- right: string = '',
- multiLevel: boolean
+ row: string,
+ right: string = '',
+ multiLevel: boolean
): string {
- if (right === '') return row; // Prevent infinite loop if right is an empty string
- while (row.endsWith(right)) {
- row = row.slice(0, row.length - right.length);
- if (!multiLevel) {
- break;
- }
+ if (right === '') return row; // Prevent infinite loop if right is an empty string
+ while (row.endsWith(right)) {
+ row = row.slice(0, row.length - right.length);
+ if (!multiLevel) {
+ break;
}
- return row;
+ }
+ return row;
}
export function unwrapList(
- splitOperatorType: SplitOperatorType,
- input: string,
- splitSeparator: string,
- joinSeparator: string,
- deleteEmptyItems: boolean,
- multiLevel: boolean,
- trimItems: boolean,
- left: string = '',
- right: string = ''
+ splitOperatorType: SplitOperatorType,
+ input: string,
+ splitSeparator: string,
+ joinSeparator: string,
+ deleteEmptyItems: boolean,
+ multiLevel: boolean,
+ trimItems: boolean,
+ left: string = '',
+ right: string = ''
): string {
- let array: string[];
- let unwrappedArray: string[] = [];
- switch (splitOperatorType) {
- case 'symbol':
- array = input.split(splitSeparator);
- break;
- case 'regex':
- array = input.split(new RegExp(splitSeparator));
- break;
- }
- if (deleteEmptyItems) {
- array = array.filter(Boolean);
- }
+ let array: string[];
+ let unwrappedArray: string[] = [];
+ switch (splitOperatorType) {
+ case 'symbol':
+ array = input.split(splitSeparator);
+ break;
+ case 'regex':
+ array = input.split(new RegExp(splitSeparator));
+ break;
+ }
+ if (deleteEmptyItems) {
+ array = array.filter(Boolean);
+ }
- // for each element of array unwrap left side then right side and push the result to a final array
- for (let row of array) {
- row = leftUnwrap(row, left, multiLevel);
- row = rightUnwrap(row, right, multiLevel);
- unwrappedArray.push(row);
- }
- // trim items if needed
- if (trimItems) {
- unwrappedArray = unwrappedArray.map(item => item.trim());
- }
- return unwrappedArray.join(joinSeparator);
+ // for each element of array unwrap left side then right side and push the result to a final array
+ for (let row of array) {
+ row = leftUnwrap(row, left, multiLevel);
+ row = rightUnwrap(row, right, multiLevel);
+ unwrappedArray.push(row);
+ }
+ // trim items if needed
+ if (trimItems) {
+ unwrappedArray = unwrappedArray.map((item) => item.trim());
+ }
+ return unwrappedArray.join(joinSeparator);
}
diff --git a/src/pages/list/unwrap/unwrap.service.test.ts b/src/pages/list/unwrap/unwrap.service.test.ts
index 29e12c3..98ac30b 100644
--- a/src/pages/list/unwrap/unwrap.service.test.ts
+++ b/src/pages/list/unwrap/unwrap.service.test.ts
@@ -2,69 +2,169 @@ import { expect, describe, it } from 'vitest';
import { unwrapList } from './service';
describe('unwrapList function', () => {
- it('should unwrap elements correctly with symbol split', () => {
- const input = "##Hello##\n##World##";
- const result = unwrapList('symbol', input, '\n', ' ', true, true, true, '#', '#');
- expect(result).toBe("Hello World");
- });
+ it('should unwrap elements correctly with symbol split', () => {
+ const input = '##Hello##\n##World##';
+ const result = unwrapList(
+ 'symbol',
+ input,
+ '\n',
+ ' ',
+ true,
+ true,
+ true,
+ '#',
+ '#'
+ );
+ expect(result).toBe('Hello World');
+ });
- it('should unwrap elements correctly with regex split', () => {
- const input = "##Hello##||##World##";
- const result = unwrapList('regex', input, '\\|\\|', ' ', true, true, true, '#', '#');
- expect(result).toBe("Hello World");
- });
+ it('should unwrap elements correctly with regex split', () => {
+ const input = '##Hello##||##World##';
+ const result = unwrapList(
+ 'regex',
+ input,
+ '\\|\\|',
+ ' ',
+ true,
+ true,
+ true,
+ '#',
+ '#'
+ );
+ expect(result).toBe('Hello World');
+ });
- it('should handle multiple levels of unwrapping', () => {
- const input = "###Hello###";
- const result = unwrapList('symbol', input, '\n', ' ', true, true, true, '#', '#');
- expect(result).toBe("Hello");
- });
+ it('should handle multiple levels of unwrapping', () => {
+ const input = '###Hello###';
+ const result = unwrapList(
+ 'symbol',
+ input,
+ '\n',
+ ' ',
+ true,
+ true,
+ true,
+ '#',
+ '#'
+ );
+ expect(result).toBe('Hello');
+ });
- it('should handle single level of unwrapping', () => {
- const input = "###Hello###";
- const result = unwrapList('symbol', input, '\n', ' ', true, false, true, '#', '#');
- expect(result).toBe("##Hello##");
- });
+ it('should handle single level of unwrapping', () => {
+ const input = '###Hello###';
+ const result = unwrapList(
+ 'symbol',
+ input,
+ '\n',
+ ' ',
+ true,
+ false,
+ true,
+ '#',
+ '#'
+ );
+ expect(result).toBe('##Hello##');
+ });
- it('should delete empty items', () => {
- const input = "##Hello##\n\n##World##";
- const result = unwrapList('symbol', input, '\n', ' ', true, true, true, '#', '#');
- expect(result).toBe("Hello World");
- });
+ it('should delete empty items', () => {
+ const input = '##Hello##\n\n##World##';
+ const result = unwrapList(
+ 'symbol',
+ input,
+ '\n',
+ ' ',
+ true,
+ true,
+ true,
+ '#',
+ '#'
+ );
+ expect(result).toBe('Hello World');
+ });
- it('should keep empty items if deleteEmptyItems is false', () => {
- const input = "##Hello##\n\n##World##";
- const result = unwrapList('symbol', input, '\n', ' ', false, true, true, '#', '#');
- expect(result).toBe("Hello World");
- });
+ it('should keep empty items if deleteEmptyItems is false', () => {
+ const input = '##Hello##\n\n##World##';
+ const result = unwrapList(
+ 'symbol',
+ input,
+ '\n',
+ ' ',
+ false,
+ true,
+ true,
+ '#',
+ '#'
+ );
+ expect(result).toBe('Hello World');
+ });
- it('should trim items', () => {
- const input = "## Hello ##\n## World ##";
- const result = unwrapList('symbol', input, '\n', ' ', true, true, true, '#', '#');
- expect(result).toBe("Hello World");
- });
+ it('should trim items', () => {
+ const input = '## Hello ##\n## World ##';
+ const result = unwrapList(
+ 'symbol',
+ input,
+ '\n',
+ ' ',
+ true,
+ true,
+ true,
+ '#',
+ '#'
+ );
+ expect(result).toBe('Hello World');
+ });
- it('should handle no left or right unwrapping', () => {
- const input = "Hello\nWorld";
- const result = unwrapList('symbol', input, '\n', ' ', true, true, true);
- expect(result).toBe("Hello World");
- });
+ it('should handle no left or right unwrapping', () => {
+ const input = 'Hello\nWorld';
+ const result = unwrapList('symbol', input, '\n', ' ', true, true, true);
+ expect(result).toBe('Hello World');
+ });
- it('should handle mixed levels of unwrapping', () => {
- const input = "###Hello##\n#World###";
- const result = unwrapList('symbol', input, '\n', ' ', true, true, true, '#', '#');
- expect(result).toBe("Hello World");
- });
+ it('should handle mixed levels of unwrapping', () => {
+ const input = '###Hello##\n#World###';
+ const result = unwrapList(
+ 'symbol',
+ input,
+ '\n',
+ ' ',
+ true,
+ true,
+ true,
+ '#',
+ '#'
+ );
+ expect(result).toBe('Hello World');
+ });
- it('should handle complex regex split', () => {
- const input = "##Hello##||###World###||####Test####";
- const result = unwrapList('regex', input, '\\|\\|', ' ', true, true, true, '#', '#');
- expect(result).toBe("Hello World Test");
- });
+ it('should handle complex regex split', () => {
+ const input = '##Hello##||###World###||####Test####';
+ const result = unwrapList(
+ 'regex',
+ input,
+ '\\|\\|',
+ ' ',
+ true,
+ true,
+ true,
+ '#',
+ '#'
+ );
+ expect(result).toBe('Hello World Test');
+ });
- it('should handle different joinSeparator', () => {
- const input = "##Hello##\n##World##";
- const result = unwrapList('symbol', input, '\n', '-', true, true, true, '#', '#');
- expect(result).toBe("Hello-World");
- });
-});
\ No newline at end of file
+ it('should handle different joinSeparator', () => {
+ const input = '##Hello##\n##World##';
+ const result = unwrapList(
+ 'symbol',
+ input,
+ '\n',
+ '-',
+ true,
+ true,
+ true,
+ '#',
+ '#'
+ );
+ expect(result).toBe('Hello-World');
+ });
+});
diff --git a/src/pages/list/wrap/index.tsx b/src/pages/list/wrap/index.tsx
index ff4c040..426bd94 100644
--- a/src/pages/list/wrap/index.tsx
+++ b/src/pages/list/wrap/index.tsx
@@ -8,4 +8,4 @@ const validationSchema = Yup.object({
});
export default function Wrap() {
return Lorem ipsum;
-}
\ No newline at end of file
+}
diff --git a/src/pages/list/wrap/meta.ts b/src/pages/list/wrap/meta.ts
index 5a394d0..38cee24 100644
--- a/src/pages/list/wrap/meta.ts
+++ b/src/pages/list/wrap/meta.ts
@@ -10,4 +10,4 @@ export const tool = defineTool('list', {
shortDescription: '',
keywords: ['wrap'],
component: lazy(() => import('./index'))
-});
\ No newline at end of file
+});
diff --git a/src/pages/list/wrap/service.ts b/src/pages/list/wrap/service.ts
index c92bd09..f57e82e 100644
--- a/src/pages/list/wrap/service.ts
+++ b/src/pages/list/wrap/service.ts
@@ -1,32 +1,31 @@
export type SplitOperatorType = 'symbol' | 'regex';
function wrap(array: string[], left: string, right: string): string[] {
- return array.map((element) => left + element + right);
+ return array.map((element) => left + element + right);
}
export function wrapList(
- splitOperatorType: SplitOperatorType,
- input: string,
- splitSeparator: string,
- joinSeparator: string,
- deleteEmptyItems: boolean,
- left: string = '',
- right: string = '',
-
+ splitOperatorType: SplitOperatorType,
+ input: string,
+ splitSeparator: string,
+ joinSeparator: string,
+ deleteEmptyItems: boolean,
+ left: string = '',
+ right: string = ''
): string {
- let array: string[];
- let wrappedArray: string[];
- switch (splitOperatorType) {
- case 'symbol':
- array = input.split(splitSeparator);
- break;
- case 'regex':
- array = input.split(new RegExp(splitSeparator));
- break;
- }
- if (deleteEmptyItems) {
- array = array.filter(Boolean);
- }
- wrappedArray = wrap(array, left, right);
- return wrappedArray.join(joinSeparator);
+ let array: string[];
+ let wrappedArray: string[];
+ switch (splitOperatorType) {
+ case 'symbol':
+ array = input.split(splitSeparator);
+ break;
+ case 'regex':
+ array = input.split(new RegExp(splitSeparator));
+ break;
+ }
+ if (deleteEmptyItems) {
+ array = array.filter(Boolean);
+ }
+ wrappedArray = wrap(array, left, right);
+ return wrappedArray.join(joinSeparator);
}
diff --git a/src/pages/list/wrap/wrap.service.test.ts b/src/pages/list/wrap/wrap.service.test.ts
index 19c8e1d..ef8c0e4 100644
--- a/src/pages/list/wrap/wrap.service.test.ts
+++ b/src/pages/list/wrap/wrap.service.test.ts
@@ -1,137 +1,132 @@
import { expect, describe, it } from 'vitest';
-import {
- SplitOperatorType,
- wrapList
-} from './service';
+import { SplitOperatorType, wrapList } from './service';
describe('wrap function', () => {
- it('should return the same input if no left and right are blanked', () => {
- const input: string = 'apple, pineaple, lemon, orange, mango';
- const splitOperatorType: SplitOperatorType = 'symbol';
- const splitSeparator = ', ';
- const joinSeparator = ', ';
- const deleteEmptyItems = false;
+ it('should return the same input if no left and right are blanked', () => {
+ const input: string = 'apple, pineaple, lemon, orange, mango';
+ const splitOperatorType: SplitOperatorType = 'symbol';
+ const splitSeparator = ', ';
+ const joinSeparator = ', ';
+ const deleteEmptyItems = false;
+ const result = wrapList(
+ splitOperatorType,
+ input,
+ splitSeparator,
+ joinSeparator,
+ deleteEmptyItems
+ );
- const result = wrapList(
- splitOperatorType,
- input,
- splitSeparator,
- joinSeparator,
- deleteEmptyItems
- );
+ expect(result).toBe('apple, pineaple, lemon, orange, mango');
+ });
- expect(result).toBe('apple, pineaple, lemon, orange, mango');
+ it('should append to left if defined', () => {
+ const input: string = 'apple, pineaple, lemon, orange, mango';
+ const splitOperatorType: SplitOperatorType = 'symbol';
+ const splitSeparator = ', ';
+ const joinSeparator = ', ';
+ const left = 'the ';
+ const deleteEmptyItems = false;
- });
+ const result = wrapList(
+ splitOperatorType,
+ input,
+ splitSeparator,
+ joinSeparator,
+ deleteEmptyItems,
+ left
+ );
- it('should append to left if defined', () => {
- const input: string = 'apple, pineaple, lemon, orange, mango';
- const splitOperatorType: SplitOperatorType = 'symbol';
- const splitSeparator = ', ';
- const joinSeparator = ', ';
- const left = 'the ';
- const deleteEmptyItems = false;
+ expect(result).toBe(
+ 'the apple, the pineaple, the lemon, the orange, the mango'
+ );
+ });
- const result = wrapList(
- splitOperatorType,
- input,
- splitSeparator,
- joinSeparator,
- deleteEmptyItems,
- left);
+ it('should append to right if defined', () => {
+ const input: string = 'apple, pineaple, lemon, orange, mango';
+ const splitOperatorType: SplitOperatorType = 'symbol';
+ const splitSeparator = ', ';
+ const joinSeparator = ', ';
+ const left = '';
+ const right = 'z';
+ const deleteEmptyItems = false;
- expect(result).toBe('the apple, the pineaple, the lemon, the orange, the mango');
+ const result = wrapList(
+ splitOperatorType,
+ input,
+ splitSeparator,
+ joinSeparator,
+ deleteEmptyItems,
+ left,
+ right
+ );
- });
+ expect(result).toBe('applez, pineaplez, lemonz, orangez, mangoz');
+ });
- it('should append to right if defined', () => {
- const input: string = 'apple, pineaple, lemon, orange, mango';
- const splitOperatorType: SplitOperatorType = 'symbol';
- const splitSeparator = ', ';
- const joinSeparator = ', ';
- const left = '';
- const right = 'z';
- const deleteEmptyItems = false;
+ it('should append to both side if both defined', () => {
+ const input: string = 'apple, pineaple, lemon, orange, mango';
+ const splitOperatorType: SplitOperatorType = 'symbol';
+ const splitSeparator = ', ';
+ const joinSeparator = ', ';
+ const deleteEmptyItems = false;
+ const left = 'K';
+ const right = 'z';
- const result = wrapList(
- splitOperatorType,
- input,
- splitSeparator,
- joinSeparator,
- deleteEmptyItems,
- left,
- right);
+ const result = wrapList(
+ splitOperatorType,
+ input,
+ splitSeparator,
+ joinSeparator,
+ deleteEmptyItems,
+ left,
+ right
+ );
- expect(result).toBe('applez, pineaplez, lemonz, orangez, mangoz');
- });
+ expect(result).toBe('Kapplez, Kpineaplez, Klemonz, Korangez, Kmangoz');
+ });
- it('should append to both side if both defined', () => {
- const input: string = 'apple, pineaple, lemon, orange, mango';
- const splitOperatorType: SplitOperatorType = 'symbol';
- const splitSeparator = ', ';
- const joinSeparator = ', ';
- const deleteEmptyItems = false;
- const left = 'K';
- const right = 'z';
+ it('should append to both side if both defined and not delete empty items', () => {
+ const input: string = 'apple, pineaple, lemon, orange, mango, ';
+ const splitOperatorType: SplitOperatorType = 'symbol';
+ const splitSeparator = ', ';
+ const joinSeparator = ', ';
+ const deleteEmptyItems = false;
+ const left = 'K';
+ const right = 'z';
- const result = wrapList(
- splitOperatorType,
- input,
- splitSeparator,
- joinSeparator,
- deleteEmptyItems,
- left,
- right);
+ const result = wrapList(
+ splitOperatorType,
+ input,
+ splitSeparator,
+ joinSeparator,
+ deleteEmptyItems,
+ left,
+ right
+ );
- expect(result).toBe('Kapplez, Kpineaplez, Klemonz, Korangez, Kmangoz');
+ expect(result).toBe('Kapplez, Kpineaplez, Klemonz, Korangez, Kmangoz, Kz');
+ });
- });
+ it('should append to both side if both defined and delete empty items', () => {
+ const input: string = 'apple, pineaple, lemon, , orange, mango';
+ const splitOperatorType: SplitOperatorType = 'symbol';
+ const splitSeparator = ', ';
+ const joinSeparator = ', ';
+ const deleteEmptyItems = true;
+ const left = 'K';
+ const right = 'z';
- it('should append to both side if both defined and not delete empty items', () => {
- const input: string = 'apple, pineaple, lemon, orange, mango, ';
- const splitOperatorType: SplitOperatorType = 'symbol';
- const splitSeparator = ', ';
- const joinSeparator = ', ';
- const deleteEmptyItems = false;
- const left = 'K';
- const right = 'z';
+ const result = wrapList(
+ splitOperatorType,
+ input,
+ splitSeparator,
+ joinSeparator,
+ deleteEmptyItems,
+ left,
+ right
+ );
- const result = wrapList(
- splitOperatorType,
- input,
- splitSeparator,
- joinSeparator,
- deleteEmptyItems,
- left,
- right);
-
- expect(result).toBe('Kapplez, Kpineaplez, Klemonz, Korangez, Kmangoz, Kz');
-
- });
-
-
- it('should append to both side if both defined and delete empty items', () => {
- const input: string = 'apple, pineaple, lemon, , orange, mango';
- const splitOperatorType: SplitOperatorType = 'symbol';
- const splitSeparator = ', ';
- const joinSeparator = ', ';
- const deleteEmptyItems = true;
- const left = 'K';
- const right = 'z';
-
- const result = wrapList(
- splitOperatorType,
- input,
- splitSeparator,
- joinSeparator,
- deleteEmptyItems,
- left,
- right);
-
- expect(result).toBe('Kapplez, Kpineaplez, Klemonz, Korangez, Kmangoz');
-
- });
-
-
-})
\ No newline at end of file
+ expect(result).toBe('Kapplez, Kpineaplez, Klemonz, Korangez, Kmangoz');
+ });
+});