fix: style

This commit is contained in:
Ibrahima G. Coulibaly
2024-07-09 23:38:29 +01:00
parent e4c726c7b5
commit 7b021d0770
36 changed files with 1107 additions and 955 deletions

View File

@@ -8,4 +8,4 @@ const validationSchema = Yup.object({
});
export default function Reverse() {
return <Box>Lorem ipsum</Box>;
}
}

View File

@@ -10,4 +10,4 @@ export const tool = defineTool('list', {
shortDescription: '',
keywords: ['reverse'],
component: lazy(() => import('./index'))
});
});

View File

@@ -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');
});
});
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');
});
});

View File

@@ -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);
}