mirror of
https://github.com/iib0011/omni-tools.git
synced 2025-09-22 07:29:39 +02:00
reverse tool (easiest) and testCases then updated index file
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import { tool as listReverse } from './reverse/meta';
|
||||||
import { tool as listFindUnique } from './find-unique/meta';
|
import { tool as listFindUnique } from './find-unique/meta';
|
||||||
import { tool as listFindMostPopular } from './find-most-popular/meta';
|
import { tool as listFindMostPopular } from './find-most-popular/meta';
|
||||||
import { tool as listGroup } from './group/meta';
|
import { tool as listGroup } from './group/meta';
|
||||||
|
11
src/pages/list/reverse/index.tsx
Normal file
11
src/pages/list/reverse/index.tsx
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import { Box } from '@mui/material';
|
||||||
|
import React from 'react';
|
||||||
|
import * as Yup from 'yup';
|
||||||
|
|
||||||
|
const initialValues = {};
|
||||||
|
const validationSchema = Yup.object({
|
||||||
|
// splitSeparator: Yup.string().required('The separator is required')
|
||||||
|
});
|
||||||
|
export default function Reverse() {
|
||||||
|
return <Box>Lorem ipsum</Box>;
|
||||||
|
}
|
13
src/pages/list/reverse/meta.ts
Normal file
13
src/pages/list/reverse/meta.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import { defineTool } from '@tools/defineTool';
|
||||||
|
import { lazy } from 'react';
|
||||||
|
// import image from '@assets/text.png';
|
||||||
|
|
||||||
|
export const tool = defineTool('list', {
|
||||||
|
name: 'Reverse',
|
||||||
|
path: 'reverse',
|
||||||
|
// image,
|
||||||
|
description: '',
|
||||||
|
shortDescription: '',
|
||||||
|
keywords: ['reverse'],
|
||||||
|
component: lazy(() => import('./index'))
|
||||||
|
});
|
28
src/pages/list/reverse/reverse.service.test.ts
Normal file
28
src/pages/list/reverse/reverse.service.test.ts
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
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');
|
||||||
|
});
|
||||||
|
});
|
21
src/pages/list/reverse/service.ts
Normal file
21
src/pages/list/reverse/service.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
type SplitOperatorType = 'symbol' | 'regex';
|
||||||
|
|
||||||
|
export function reverseList(
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
const reversedList = array.reverse();
|
||||||
|
return reversedList.join(joinSeparator);
|
||||||
|
}
|
Reference in New Issue
Block a user