mirror of
https://github.com/iib0011/omni-tools.git
synced 2025-12-29 16:16:02 +00:00
feat: rotate ui
This commit is contained in:
@@ -8,4 +8,4 @@ const validationSchema = Yup.object({
|
||||
});
|
||||
export default function Reverse() {
|
||||
return <Box>Lorem ipsum</Box>;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,4 +10,4 @@ export const tool = defineTool('string', {
|
||||
shortDescription: '',
|
||||
keywords: ['reverse'],
|
||||
component: lazy(() => import('./index'))
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,51 +2,51 @@ import { expect, describe, it } from 'vitest';
|
||||
import { stringReverser } from './service';
|
||||
|
||||
describe('stringReverser', () => {
|
||||
it('should reverse a single-line string', () => {
|
||||
const input = 'hello world';
|
||||
const result = stringReverser(input, false, false, false);
|
||||
expect(result).toBe('dlrow olleh');
|
||||
});
|
||||
it('should reverse a single-line string', () => {
|
||||
const input = 'hello world';
|
||||
const result = stringReverser(input, false, false, false);
|
||||
expect(result).toBe('dlrow olleh');
|
||||
});
|
||||
|
||||
it('should reverse each line in a multi-line string', () => {
|
||||
const input = 'hello\nworld';
|
||||
const result = stringReverser(input, true, false, false);
|
||||
expect(result).toBe('olleh\ndlrow');
|
||||
});
|
||||
it('should reverse each line in a multi-line string', () => {
|
||||
const input = 'hello\nworld';
|
||||
const result = stringReverser(input, true, false, false);
|
||||
expect(result).toBe('olleh\ndlrow');
|
||||
});
|
||||
|
||||
it('should remove empty items if emptyItems is true', () => {
|
||||
const input = 'hello\n\nworld';
|
||||
const result = stringReverser(input, true, true, false);
|
||||
expect(result).toBe('olleh\ndlrow');
|
||||
});
|
||||
it('should remove empty items if emptyItems is true', () => {
|
||||
const input = 'hello\n\nworld';
|
||||
const result = stringReverser(input, true, true, false);
|
||||
expect(result).toBe('olleh\ndlrow');
|
||||
});
|
||||
|
||||
it('should trim each line if trim is true', () => {
|
||||
const input = ' hello \n world ';
|
||||
const result = stringReverser(input, true, false, true);
|
||||
expect(result).toBe('olleh\ndlrow');
|
||||
});
|
||||
it('should trim each line if trim is true', () => {
|
||||
const input = ' hello \n world ';
|
||||
const result = stringReverser(input, true, false, true);
|
||||
expect(result).toBe('olleh\ndlrow');
|
||||
});
|
||||
|
||||
it('should handle empty input', () => {
|
||||
const input = '';
|
||||
const result = stringReverser(input, false, false, false);
|
||||
expect(result).toBe('');
|
||||
});
|
||||
it('should handle empty input', () => {
|
||||
const input = '';
|
||||
const result = stringReverser(input, false, false, false);
|
||||
expect(result).toBe('');
|
||||
});
|
||||
|
||||
it('should handle a single line with emptyItems and trim', () => {
|
||||
const input = ' hello world ';
|
||||
const result = stringReverser(input, false, true, true);
|
||||
expect(result).toBe('dlrow olleh');
|
||||
});
|
||||
it('should handle a single line with emptyItems and trim', () => {
|
||||
const input = ' hello world ';
|
||||
const result = stringReverser(input, false, true, true);
|
||||
expect(result).toBe('dlrow olleh');
|
||||
});
|
||||
|
||||
it('should handle a single line with emptyItems and non trim', () => {
|
||||
const input = ' hello world ';
|
||||
const result = stringReverser(input, false, true, false);
|
||||
expect(result).toBe(' dlrow olleh ');
|
||||
});
|
||||
it('should handle a single line with emptyItems and non trim', () => {
|
||||
const input = ' hello world ';
|
||||
const result = stringReverser(input, false, true, false);
|
||||
expect(result).toBe(' dlrow olleh ');
|
||||
});
|
||||
|
||||
it('should handle a multi line with emptyItems and non trim', () => {
|
||||
const input = ' hello\n\n\n\nworld ';
|
||||
const result = stringReverser(input, true, true, false);
|
||||
expect(result).toBe('olleh \n dlrow');
|
||||
});
|
||||
});
|
||||
it('should handle a multi line with emptyItems and non trim', () => {
|
||||
const input = ' hello\n\n\n\nworld ';
|
||||
const result = stringReverser(input, true, true, false);
|
||||
expect(result).toBe('olleh \n dlrow');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,31 +1,30 @@
|
||||
import { reverseString } from 'utils/string';
|
||||
|
||||
export function stringReverser(
|
||||
input: string,
|
||||
multiLine: boolean,
|
||||
emptyItems: boolean,
|
||||
trim: boolean
|
||||
input: string,
|
||||
multiLine: boolean,
|
||||
emptyItems: boolean,
|
||||
trim: boolean
|
||||
) {
|
||||
let array: string[] = [];
|
||||
let result: string[] = [];
|
||||
let array: string[] = [];
|
||||
let result: string[] = [];
|
||||
|
||||
// split the input in multiLine mode
|
||||
if (multiLine) {
|
||||
array = input.split('\n');
|
||||
}
|
||||
else {
|
||||
array.push(input);
|
||||
}
|
||||
// split the input in multiLine mode
|
||||
if (multiLine) {
|
||||
array = input.split('\n');
|
||||
} else {
|
||||
array.push(input);
|
||||
}
|
||||
|
||||
// handle empty items
|
||||
if (emptyItems){
|
||||
array = array.filter(Boolean);
|
||||
}
|
||||
// Handle trim
|
||||
if (trim) {
|
||||
array = array.map(line => line.trim());
|
||||
}
|
||||
// handle empty items
|
||||
if (emptyItems) {
|
||||
array = array.filter(Boolean);
|
||||
}
|
||||
// Handle trim
|
||||
if (trim) {
|
||||
array = array.map((line) => line.trim());
|
||||
}
|
||||
|
||||
result = array.map(element => reverseString(element));
|
||||
return result.join('\n');
|
||||
}
|
||||
result = array.map((element) => reverseString(element));
|
||||
return result.join('\n');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user