mirror of
https://github.com/iib0011/omni-tools.git
synced 2025-09-19 14:09:31 +02:00
rot13 tool, testCases then updated index file
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import { tool as stringRot13 } from './rot13/meta';
|
||||||
import { tool as stringReverse } from './reverse/meta';
|
import { tool as stringReverse } from './reverse/meta';
|
||||||
import { tool as stringRandomizeCase } from './randomize-case/meta';
|
import { tool as stringRandomizeCase } from './randomize-case/meta';
|
||||||
import { tool as stringUppercase } from './uppercase/meta';
|
import { tool as stringUppercase } from './uppercase/meta';
|
||||||
|
11
src/pages/string/rot13/index.tsx
Normal file
11
src/pages/string/rot13/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 Rot13() {
|
||||||
|
return <Box>Lorem ipsum</Box>;
|
||||||
|
}
|
13
src/pages/string/rot13/meta.ts
Normal file
13
src/pages/string/rot13/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('string', {
|
||||||
|
name: 'Rot13',
|
||||||
|
path: 'rot13',
|
||||||
|
// image,
|
||||||
|
description: '',
|
||||||
|
shortDescription: '',
|
||||||
|
keywords: ['rot13'],
|
||||||
|
component: lazy(() => import('./index'))
|
||||||
|
});
|
58
src/pages/string/rot13/rot13.service.test.ts
Normal file
58
src/pages/string/rot13/rot13.service.test.ts
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
import { expect, describe, it } from 'vitest';
|
||||||
|
import { rot13 } from './service';
|
||||||
|
|
||||||
|
describe('rot13', () => {
|
||||||
|
it('should encode a simple string using ROT13', () => {
|
||||||
|
const input = 'hello';
|
||||||
|
const result = rot13(input);
|
||||||
|
expect(result).toBe('uryyb');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should decode a ROT13 encoded string', () => {
|
||||||
|
const input = 'uryyb';
|
||||||
|
const result = rot13(input);
|
||||||
|
expect(result).toBe('hello');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle uppercase letters correctly', () => {
|
||||||
|
const input = 'HELLO';
|
||||||
|
const result = rot13(input);
|
||||||
|
expect(result).toBe('URYYB');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle mixed case letters correctly', () => {
|
||||||
|
const input = 'HelloWorld';
|
||||||
|
const result = rot13(input);
|
||||||
|
expect(result).toBe('UryybJbeyq');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle non-alphabetic characters correctly', () => {
|
||||||
|
const input = 'Hello, World!';
|
||||||
|
const result = rot13(input);
|
||||||
|
expect(result).toBe('Uryyb, Jbeyq!');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle an empty string', () => {
|
||||||
|
const input = '';
|
||||||
|
const result = rot13(input);
|
||||||
|
expect(result).toBe('');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle a string with numbers correctly', () => {
|
||||||
|
const input = '1234';
|
||||||
|
const result = rot13(input);
|
||||||
|
expect(result).toBe('1234');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle a string with symbols correctly', () => {
|
||||||
|
const input = '!@#$%^&*()_+-=';
|
||||||
|
const result = rot13(input);
|
||||||
|
expect(result).toBe('!@#$%^&*()_+-=');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle a string with mixed characters correctly', () => {
|
||||||
|
const input = 'Hello, World! 123';
|
||||||
|
const result = rot13(input);
|
||||||
|
expect(result).toBe('Uryyb, Jbeyq! 123');
|
||||||
|
});
|
||||||
|
});
|
7
src/pages/string/rot13/service.ts
Normal file
7
src/pages/string/rot13/service.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
export function rot13(input: string): string {
|
||||||
|
return input.replace(/[a-zA-Z]/g, (char) => {
|
||||||
|
const charCode = char.charCodeAt(0);
|
||||||
|
const baseCode = charCode >= 97 ? 97 : 65; // 'a' or 'A'
|
||||||
|
return String.fromCharCode(((charCode - baseCode + 13) % 26) + baseCode);
|
||||||
|
});
|
||||||
|
}
|
Reference in New Issue
Block a user