mirror of
https://github.com/iib0011/omni-tools.git
synced 2025-09-22 15:39:31 +02:00
feat: rotate ui
This commit is contained in:
82
.idea/workspace.xml
generated
82
.idea/workspace.xml
generated
@@ -4,10 +4,37 @@
|
|||||||
<option name="autoReloadType" value="SELECTIVE" />
|
<option name="autoReloadType" value="SELECTIVE" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="b30e2810-c4c1-4aad-b134-794e52cc1c7d" name="Changes" comment="feat: self host">
|
<list default="true" id="b30e2810-c4c1-4aad-b134-794e52cc1c7d" name="Changes" comment="chore: format number">
|
||||||
<change afterPath="$PROJECT_DIR$/src/utils/number.ts" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/pages/list/group/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/list/group/index.tsx" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/pages/list/duplicate/duplicate.service.test.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/list/duplicate/duplicate.service.test.ts" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/pages/list/duplicate/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/list/duplicate/index.tsx" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/pages/list/duplicate/meta.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/list/duplicate/meta.ts" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/pages/list/duplicate/service.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/list/duplicate/service.ts" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/pages/list/rotate/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/list/rotate/index.tsx" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/pages/string/create-palindrome/create-palindrome.service.test.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/create-palindrome/create-palindrome.service.test.ts" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/pages/string/create-palindrome/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/create-palindrome/index.tsx" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/pages/string/create-palindrome/meta.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/create-palindrome/meta.ts" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/pages/string/create-palindrome/service.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/create-palindrome/service.ts" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/pages/string/extract-substring/extract-substring.service.test.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/extract-substring/extract-substring.service.test.ts" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/pages/string/extract-substring/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/extract-substring/index.tsx" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/pages/string/extract-substring/meta.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/extract-substring/meta.ts" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/pages/string/extract-substring/service.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/extract-substring/service.ts" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/pages/string/palindrome/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/palindrome/index.tsx" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/pages/string/palindrome/meta.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/palindrome/meta.ts" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/pages/string/palindrome/palindrome.service.test.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/palindrome/palindrome.service.test.ts" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/pages/string/palindrome/service.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/palindrome/service.ts" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/pages/string/randomize-case/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/randomize-case/index.tsx" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/pages/string/randomize-case/meta.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/randomize-case/meta.ts" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/pages/string/randomize-case/randomize-case.service.test.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/randomize-case/randomize-case.service.test.ts" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/pages/string/randomize-case/service.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/randomize-case/service.ts" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/pages/string/reverse/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/reverse/index.tsx" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/pages/string/reverse/meta.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/reverse/meta.ts" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/pages/string/reverse/reverse.service.test.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/reverse/reverse.service.test.ts" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/pages/string/reverse/service.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/reverse/service.ts" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/pages/string/uppercase/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/uppercase/index.tsx" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/pages/string/uppercase/meta.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/uppercase/meta.ts" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/pages/string/uppercase/service.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/uppercase/service.ts" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/pages/string/uppercase/uppercase.service.test.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/uppercase/uppercase.service.test.ts" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
@@ -29,6 +56,18 @@
|
|||||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||||
<option name="RESET_MODE" value="HARD" />
|
<option name="RESET_MODE" value="HARD" />
|
||||||
</component>
|
</component>
|
||||||
|
<component name="GitHubPullRequestSearchHistory">{
|
||||||
|
"lastFilter": {
|
||||||
|
"state": "OPEN",
|
||||||
|
"assignee": "iib0011"
|
||||||
|
}
|
||||||
|
}</component>
|
||||||
|
<component name="GithubPullRequestsUISettings">{
|
||||||
|
"selectedUrlAndAccountId": {
|
||||||
|
"url": "https://github.com/iib0011/omni-tools",
|
||||||
|
"accountId": "59b4836a-7ded-49a0-a358-5e8d81d0d44b"
|
||||||
|
}
|
||||||
|
}</component>
|
||||||
<component name="KubernetesApiProvider">{
|
<component name="KubernetesApiProvider">{
|
||||||
"isMigrated": true
|
"isMigrated": true
|
||||||
}</component>
|
}</component>
|
||||||
@@ -117,7 +156,6 @@
|
|||||||
<settings>
|
<settings>
|
||||||
<option name="imageTag" value="omnitools" />
|
<option name="imageTag" value="omnitools" />
|
||||||
<option name="buildCliOptions" value="--target build" />
|
<option name="buildCliOptions" value="--target build" />
|
||||||
<option name="buildKitEnabled" value="true" />
|
|
||||||
<option name="containerName" value="omni-tools" />
|
<option name="containerName" value="omni-tools" />
|
||||||
<option name="publishAllPorts" value="true" />
|
<option name="publishAllPorts" value="true" />
|
||||||
<option name="sourceFilePath" value="Dockerfile" />
|
<option name="sourceFilePath" value="Dockerfile" />
|
||||||
@@ -179,13 +217,21 @@
|
|||||||
<recent_temporary>
|
<recent_temporary>
|
||||||
<list>
|
<list>
|
||||||
<item itemvalue="npm.dev" />
|
<item itemvalue="npm.dev" />
|
||||||
|
<item itemvalue="npm.lint" />
|
||||||
<item itemvalue="Docker.Dockerfile build" />
|
<item itemvalue="Docker.Dockerfile build" />
|
||||||
<item itemvalue="Docker.Dockerfile" />
|
<item itemvalue="Docker.Dockerfile" />
|
||||||
<item itemvalue="npm.lint" />
|
|
||||||
<item itemvalue="npm.test:e2e" />
|
<item itemvalue="npm.test:e2e" />
|
||||||
</list>
|
</list>
|
||||||
</recent_temporary>
|
</recent_temporary>
|
||||||
</component>
|
</component>
|
||||||
|
<component name="SharedIndexes">
|
||||||
|
<attachedChunks>
|
||||||
|
<set>
|
||||||
|
<option value="bundled-jdk-9f38398b9061-39b83d9b5494-intellij.indexing.shared.core-IU-241.18034.62" />
|
||||||
|
<option value="bundled-js-predefined-1d06a55b98c1-0b3e54e931b4-JavaScript-IU-241.18034.62" />
|
||||||
|
</set>
|
||||||
|
</attachedChunks>
|
||||||
|
</component>
|
||||||
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
||||||
<component name="TaskManager">
|
<component name="TaskManager">
|
||||||
<task active="true" id="Default" summary="Default task">
|
<task active="true" id="Default" summary="Default task">
|
||||||
@@ -224,15 +270,9 @@
|
|||||||
<workItem from="1720613598176" duration="8000" />
|
<workItem from="1720613598176" duration="8000" />
|
||||||
<workItem from="1720655252208" duration="3975000" />
|
<workItem from="1720655252208" duration="3975000" />
|
||||||
<workItem from="1720661825389" duration="4305000" />
|
<workItem from="1720661825389" duration="4305000" />
|
||||||
<workItem from="1720729165596" duration="730000" />
|
<workItem from="1720729165596" duration="3258000" />
|
||||||
</task>
|
<workItem from="1720911748039" duration="331000" />
|
||||||
<task id="LOCAL-00047" summary="feat: change colors in png">
|
<workItem from="1720912096050" duration="810000" />
|
||||||
<option name="closed" value="true" />
|
|
||||||
<created>1719197875189</created>
|
|
||||||
<option name="number" value="00047" />
|
|
||||||
<option name="presentableId" value="LOCAL-00047" />
|
|
||||||
<option name="project" value="LOCAL" />
|
|
||||||
<updated>1719197875189</updated>
|
|
||||||
</task>
|
</task>
|
||||||
<task id="LOCAL-00048" summary="chore: ResultFooter">
|
<task id="LOCAL-00048" summary="chore: ResultFooter">
|
||||||
<option name="closed" value="true" />
|
<option name="closed" value="true" />
|
||||||
@@ -618,7 +658,15 @@
|
|||||||
<option name="project" value="LOCAL" />
|
<option name="project" value="LOCAL" />
|
||||||
<updated>1720665220408</updated>
|
<updated>1720665220408</updated>
|
||||||
</task>
|
</task>
|
||||||
<option name="localTasksCounter" value="96" />
|
<task id="LOCAL-00096" summary="chore: format number">
|
||||||
|
<option name="closed" value="true" />
|
||||||
|
<created>1720730102816</created>
|
||||||
|
<option name="number" value="00096" />
|
||||||
|
<option name="presentableId" value="LOCAL-00096" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1720730102817</updated>
|
||||||
|
</task>
|
||||||
|
<option name="localTasksCounter" value="97" />
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
<component name="TypeScriptGeneratedFilesManager">
|
<component name="TypeScriptGeneratedFilesManager">
|
||||||
@@ -662,7 +710,6 @@
|
|||||||
<option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" />
|
<option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" />
|
||||||
<option name="CHECK_NEW_TODO" value="false" />
|
<option name="CHECK_NEW_TODO" value="false" />
|
||||||
<option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" />
|
<option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" />
|
||||||
<MESSAGE value="chore: make tool examples responsive" />
|
|
||||||
<MESSAGE value="chore: loading screen" />
|
<MESSAGE value="chore: loading screen" />
|
||||||
<MESSAGE value="chore: shuffle tools search" />
|
<MESSAGE value="chore: shuffle tools search" />
|
||||||
<MESSAGE value="refactor: toolOptions" />
|
<MESSAGE value="refactor: toolOptions" />
|
||||||
@@ -687,7 +734,8 @@
|
|||||||
<MESSAGE value="feat: group list ui" />
|
<MESSAGE value="feat: group list ui" />
|
||||||
<MESSAGE value="feat: reverse list ui" />
|
<MESSAGE value="feat: reverse list ui" />
|
||||||
<MESSAGE value="feat: self host" />
|
<MESSAGE value="feat: self host" />
|
||||||
<option name="LAST_COMMIT_MESSAGE" value="feat: self host" />
|
<MESSAGE value="chore: format number" />
|
||||||
|
<option name="LAST_COMMIT_MESSAGE" value="chore: format number" />
|
||||||
</component>
|
</component>
|
||||||
<component name="XSLT-Support.FileAssociations.UIState">
|
<component name="XSLT-Support.FileAssociations.UIState">
|
||||||
<expand />
|
<expand />
|
||||||
|
@@ -3,43 +3,45 @@ import { duplicateList } from './service';
|
|||||||
|
|
||||||
describe('duplicateList function', () => {
|
describe('duplicateList function', () => {
|
||||||
it('should duplicate elements correctly with symbol split', () => {
|
it('should duplicate elements correctly with symbol split', () => {
|
||||||
const input = "Hello World";
|
const input = 'Hello World';
|
||||||
const result = duplicateList('symbol', ' ', ' ', input, true, false, 2);
|
const result = duplicateList('symbol', ' ', ' ', input, true, false, 2);
|
||||||
expect(result).toBe("Hello World Hello World");
|
expect(result).toBe('Hello World Hello World');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should duplicate elements correctly with regex split', () => {
|
it('should duplicate elements correctly with regex split', () => {
|
||||||
const input = "Hello||World";
|
const input = 'Hello||World';
|
||||||
const result = duplicateList('regex', '\\|\\|', ' ', input, true, false, 2);
|
const result = duplicateList('regex', '\\|\\|', ' ', input, true, false, 2);
|
||||||
expect(result).toBe("Hello World Hello World");
|
expect(result).toBe('Hello World Hello World');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle fractional duplication', () => {
|
it('should handle fractional duplication', () => {
|
||||||
const input = "Hello World";
|
const input = 'Hello World';
|
||||||
const result = duplicateList('symbol', ' ', ' ', input, true, false, 1.5);
|
const result = duplicateList('symbol', ' ', ' ', input, true, false, 1.5);
|
||||||
expect(result).toBe("Hello World Hello");
|
expect(result).toBe('Hello World Hello');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle reverse option correctly', () => {
|
it('should handle reverse option correctly', () => {
|
||||||
const input = "Hello World";
|
const input = 'Hello World';
|
||||||
const result = duplicateList('symbol', ' ', ' ', input, true, true, 2);
|
const result = duplicateList('symbol', ' ', ' ', input, true, true, 2);
|
||||||
expect(result).toBe("Hello World World Hello");
|
expect(result).toBe('Hello World World Hello');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle concatenate option correctly', () => {
|
it('should handle concatenate option correctly', () => {
|
||||||
const input = "Hello World";
|
const input = 'Hello World';
|
||||||
const result = duplicateList('symbol', ' ', ' ', input, false, false, 2);
|
const result = duplicateList('symbol', ' ', ' ', input, false, false, 2);
|
||||||
expect(result).toBe("Hello Hello World World");
|
expect(result).toBe('Hello Hello World World');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle interweaving option correctly', () => {
|
it('should handle interweaving option correctly', () => {
|
||||||
const input = "Hello World";
|
const input = 'Hello World';
|
||||||
const result = duplicateList('symbol', ' ', ' ', input, false, false, 2);
|
const result = duplicateList('symbol', ' ', ' ', input, false, false, 2);
|
||||||
expect(result).toBe("Hello Hello World World");
|
expect(result).toBe('Hello Hello World World');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw an error for negative copies', () => {
|
it('should throw an error for negative copies', () => {
|
||||||
expect(() => duplicateList('symbol', ' ', ' ', "Hello World", true, false, -1)).toThrow("Number of copies cannot be negative");
|
expect(() =>
|
||||||
|
duplicateList('symbol', ' ', ' ', 'Hello World', true, false, -1)
|
||||||
|
).toThrow('Number of copies cannot be negative');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle interweaving option correctly 2', () => {
|
it('should handle interweaving option correctly 2', () => {
|
||||||
@@ -57,6 +59,8 @@ describe('duplicateList function', () => {
|
|||||||
it('should handle interweaving option correctly 3', () => {
|
it('should handle interweaving option correctly 3', () => {
|
||||||
const input = "je m'appelle king";
|
const input = "je m'appelle king";
|
||||||
const result = duplicateList('symbol', ' ', ', ', input, true, true, 2.7);
|
const result = duplicateList('symbol', ' ', ', ', input, true, true, 2.7);
|
||||||
expect(result).toBe("je, m'appelle, king, king, m'appelle, je, king, m'appelle");
|
expect(result).toBe(
|
||||||
|
"je, m'appelle, king, king, m'appelle, je, king, m'appelle"
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
@@ -1,8 +1,6 @@
|
|||||||
export type SplitOperatorType = 'symbol' | 'regex';
|
export type SplitOperatorType = 'symbol' | 'regex';
|
||||||
|
|
||||||
function interweave(
|
function interweave(array1: string[], array2: string[]) {
|
||||||
array1: string[],
|
|
||||||
array2: string[]) {
|
|
||||||
const result: string[] = [];
|
const result: string[] = [];
|
||||||
const maxLength = Math.max(array1.length, array2.length);
|
const maxLength = Math.max(array1.length, array2.length);
|
||||||
|
|
||||||
@@ -27,22 +25,34 @@ function duplicate(
|
|||||||
const whole = Math.floor(copy);
|
const whole = Math.floor(copy);
|
||||||
const fractional = copy - whole;
|
const fractional = copy - whole;
|
||||||
if (!reverse) {
|
if (!reverse) {
|
||||||
WholePart = concatenate ? Array(whole).fill(input).flat() : Array(whole - 1).fill(input).flat();
|
WholePart = concatenate
|
||||||
|
? Array(whole).fill(input).flat()
|
||||||
|
: Array(whole - 1)
|
||||||
|
.fill(input)
|
||||||
|
.flat();
|
||||||
fractionalPart = input.slice(0, Math.floor(input.length * fractional));
|
fractionalPart = input.slice(0, Math.floor(input.length * fractional));
|
||||||
toAdd = WholePart.concat(fractionalPart);
|
toAdd = WholePart.concat(fractionalPart);
|
||||||
result = concatenate ? WholePart.concat(fractionalPart) : interweave(input, toAdd);
|
result = concatenate
|
||||||
|
? WholePart.concat(fractionalPart)
|
||||||
|
: interweave(input, toAdd);
|
||||||
} else {
|
} else {
|
||||||
WholePart = Array(whole - 1).fill(input).flat().reverse()
|
WholePart = Array(whole - 1)
|
||||||
fractionalPart = input.slice().reverse().slice(0, Math.floor(input.length * fractional));
|
.fill(input)
|
||||||
|
.flat()
|
||||||
|
.reverse();
|
||||||
|
fractionalPart = input
|
||||||
|
.slice()
|
||||||
|
.reverse()
|
||||||
|
.slice(0, Math.floor(input.length * fractional));
|
||||||
toAdd = WholePart.concat(fractionalPart);
|
toAdd = WholePart.concat(fractionalPart);
|
||||||
result = concatenate ? input.concat(toAdd) : interweave(input, toAdd);
|
result = concatenate ? input.concat(toAdd) : interweave(input, toAdd);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
throw new Error("Number of copies cannot be negative");
|
throw new Error('Number of copies cannot be negative');
|
||||||
}
|
}
|
||||||
throw new Error("Number of copies must be a valid number");
|
throw new Error('Number of copies must be a valid number');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function duplicateList(
|
export function duplicateList(
|
||||||
@@ -61,7 +71,9 @@ export function duplicateList(
|
|||||||
array = input.split(splitSeparator);
|
array = input.split(splitSeparator);
|
||||||
break;
|
break;
|
||||||
case 'regex':
|
case 'regex':
|
||||||
array = input.split(new RegExp(splitSeparator)).filter(item => item !== '');
|
array = input
|
||||||
|
.split(new RegExp(splitSeparator))
|
||||||
|
.filter((item) => item !== '');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
result = duplicate(array, concatenate, reverse, copy);
|
result = duplicate(array, concatenate, reverse, copy);
|
||||||
|
@@ -1,11 +1,158 @@
|
|||||||
import { Box } from '@mui/material';
|
import { Box } from '@mui/material';
|
||||||
import React from 'react';
|
import React, { useState } from 'react';
|
||||||
|
import ToolTextInput from '../../../components/input/ToolTextInput';
|
||||||
|
import ToolTextResult from '../../../components/result/ToolTextResult';
|
||||||
import * as Yup from 'yup';
|
import * as Yup from 'yup';
|
||||||
|
import ToolOptions from '../../../components/options/ToolOptions';
|
||||||
|
import { rotateList, SplitOperatorType } from './service';
|
||||||
|
import ToolInputAndResult from '../../../components/ToolInputAndResult';
|
||||||
|
import SimpleRadio from '../../../components/options/SimpleRadio';
|
||||||
|
import TextFieldWithDesc from '../../../components/options/TextFieldWithDesc';
|
||||||
|
import { formatNumber } from '../../../utils/number';
|
||||||
|
|
||||||
|
const initialValues = {
|
||||||
|
splitOperatorType: 'symbol' as SplitOperatorType,
|
||||||
|
input: '',
|
||||||
|
splitSeparator: ',',
|
||||||
|
joinSeparator: ',',
|
||||||
|
right: true,
|
||||||
|
step: 1
|
||||||
|
};
|
||||||
|
const splitOperators: {
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
type: SplitOperatorType;
|
||||||
|
}[] = [
|
||||||
|
{
|
||||||
|
title: 'Use a Symbol for Splitting',
|
||||||
|
description: 'Delimit input list items with a character.',
|
||||||
|
type: 'symbol'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Use a Regex for Splitting',
|
||||||
|
type: 'regex',
|
||||||
|
description: 'Delimit input list items with a regular expression.'
|
||||||
|
}
|
||||||
|
];
|
||||||
|
const rotationDirections: {
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
value: boolean;
|
||||||
|
}[] = [
|
||||||
|
{
|
||||||
|
title: 'Rotate forward',
|
||||||
|
description:
|
||||||
|
'Rotate list items to the right. (Down if a vertical column list.)',
|
||||||
|
value: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Rotate backward',
|
||||||
|
description:
|
||||||
|
'Rotate list items to the left. (Up if a vertical column list.)',
|
||||||
|
value: false
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
const initialValues = {};
|
|
||||||
const validationSchema = Yup.object({
|
|
||||||
// splitSeparator: Yup.string().required('The separator is required')
|
|
||||||
});
|
|
||||||
export default function Rotate() {
|
export default function Rotate() {
|
||||||
return <Box>Lorem ipsum</Box>;
|
const [input, setInput] = useState<string>('');
|
||||||
|
const [result, setResult] = useState<string>('');
|
||||||
|
const compute = (optionsValues: typeof initialValues, input: any) => {
|
||||||
|
const { splitOperatorType, splitSeparator, joinSeparator, right, step } =
|
||||||
|
optionsValues;
|
||||||
|
|
||||||
|
setResult(
|
||||||
|
rotateList(
|
||||||
|
splitOperatorType,
|
||||||
|
input,
|
||||||
|
splitSeparator,
|
||||||
|
joinSeparator,
|
||||||
|
right,
|
||||||
|
step
|
||||||
|
)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
const validationSchema = Yup.object({
|
||||||
|
// splitSeparator: Yup.string().required('The separator is required')
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box>
|
||||||
|
<ToolInputAndResult
|
||||||
|
input={
|
||||||
|
<ToolTextInput
|
||||||
|
title={'Input list'}
|
||||||
|
value={input}
|
||||||
|
onChange={setInput}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
result={<ToolTextResult title={'Rotated list'} value={result} />}
|
||||||
|
/>
|
||||||
|
<ToolOptions
|
||||||
|
compute={compute}
|
||||||
|
getGroups={({ values, updateField }) => [
|
||||||
|
{
|
||||||
|
title: 'Item split mode',
|
||||||
|
component: (
|
||||||
|
<Box>
|
||||||
|
{splitOperators.map(({ title, description, type }) => (
|
||||||
|
<SimpleRadio
|
||||||
|
key={type}
|
||||||
|
onClick={() => updateField('splitOperatorType', type)}
|
||||||
|
title={title}
|
||||||
|
description={description}
|
||||||
|
checked={values.splitOperatorType === type}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
<TextFieldWithDesc
|
||||||
|
description={'Set a delimiting symbol or regular expression.'}
|
||||||
|
value={values.splitSeparator}
|
||||||
|
onOwnChange={(val) => updateField('splitSeparator', val)}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Rotation Direction and Count',
|
||||||
|
component: (
|
||||||
|
<Box>
|
||||||
|
{rotationDirections.map(({ title, description, value }) => (
|
||||||
|
<SimpleRadio
|
||||||
|
key={`${value}`}
|
||||||
|
onClick={() => updateField('right', Boolean(value))}
|
||||||
|
title={title}
|
||||||
|
description={description}
|
||||||
|
checked={values.right === value}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
<TextFieldWithDesc
|
||||||
|
description={'Number of items to rotate'}
|
||||||
|
value={values.step}
|
||||||
|
onOwnChange={(val) =>
|
||||||
|
updateField('step', formatNumber(val, 1))
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Rotated List Joining Symbol',
|
||||||
|
component: (
|
||||||
|
<Box>
|
||||||
|
<TextFieldWithDesc
|
||||||
|
value={values.joinSeparator}
|
||||||
|
onOwnChange={(value) => updateField('joinSeparator', value)}
|
||||||
|
description={
|
||||||
|
'Enter the character that goes between items in the rotated list.'
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
]}
|
||||||
|
initialValues={initialValues}
|
||||||
|
input={input}
|
||||||
|
validationSchema={validationSchema}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import { expect, describe, it } from 'vitest';
|
import { expect, describe, it } from 'vitest';
|
||||||
import { createPalindromeList, createPalindrome } from './service';
|
import { createPalindromeList, createPalindrome } from './service';
|
||||||
|
|
||||||
describe('createPalindrome', () => {
|
describe('createPalindrome', () => {
|
||||||
test('should create palindrome by reversing the entire string', () => {
|
test('should create palindrome by reversing the entire string', () => {
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { reverseString } from 'utils/string'
|
import { reverseString } from 'utils/string';
|
||||||
|
|
||||||
export function createPalindrome(
|
export function createPalindrome(
|
||||||
input: string,
|
input: string,
|
||||||
@@ -9,7 +9,9 @@ export function createPalindrome(
|
|||||||
let reversedString: string;
|
let reversedString: string;
|
||||||
|
|
||||||
// reverse the whole input if lastChar enabled
|
// reverse the whole input if lastChar enabled
|
||||||
reversedString = lastChar ? reverseString(input) : reverseString(input.slice(0, -1));
|
reversedString = lastChar
|
||||||
|
? reverseString(input)
|
||||||
|
: reverseString(input.slice(0, -1));
|
||||||
result = input.concat(reversedString);
|
result = input.concat(reversedString);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -21,7 +23,7 @@ export function createPalindromeList(
|
|||||||
): string {
|
): string {
|
||||||
if (!input) return '';
|
if (!input) return '';
|
||||||
let array: string[];
|
let array: string[];
|
||||||
let result: string[] = [];
|
const result: string[] = [];
|
||||||
|
|
||||||
if (!multiLine) return createPalindrome(input, lastChar);
|
if (!multiLine) return createPalindrome(input, lastChar);
|
||||||
else {
|
else {
|
||||||
@@ -31,5 +33,4 @@ export function createPalindromeList(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result.join('\n');
|
return result.join('\n');
|
||||||
|
|
||||||
}
|
}
|
@@ -39,8 +39,12 @@ describe('extractSubstring', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should handle negative start and length', () => {
|
it('should handle negative start and length', () => {
|
||||||
expect(() => extractSubstring('hello', -1, 5, false, false)).toThrow("Start index must be greater than zero.");
|
expect(() => extractSubstring('hello', -1, 5, false, false)).toThrow(
|
||||||
expect(() => extractSubstring('hello', 1, -5, false, false)).toThrow("Length value must be greater than or equal to zero.");
|
'Start index must be greater than zero.'
|
||||||
|
);
|
||||||
|
expect(() => extractSubstring('hello', 1, -5, false, false)).toThrow(
|
||||||
|
'Length value must be greater than or equal to zero.'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle zero length', () => {
|
it('should handle zero length', () => {
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { reverseString } from 'utils/string'
|
import { reverseString } from 'utils/string';
|
||||||
|
|
||||||
export function extractSubstring(
|
export function extractSubstring(
|
||||||
input: string,
|
input: string,
|
||||||
@@ -9,8 +9,9 @@ export function extractSubstring(
|
|||||||
): string {
|
): string {
|
||||||
if (!input) return '';
|
if (!input) return '';
|
||||||
// edge Cases
|
// edge Cases
|
||||||
if (start <= 0) throw new Error("Start index must be greater than zero.");
|
if (start <= 0) throw new Error('Start index must be greater than zero.');
|
||||||
if (length < 0) throw new Error("Length value must be greater than or equal to zero.");
|
if (length < 0)
|
||||||
|
throw new Error('Length value must be greater than or equal to zero.');
|
||||||
if (length === 0) return '';
|
if (length === 0) return '';
|
||||||
|
|
||||||
let array: string[];
|
let array: string[];
|
||||||
@@ -24,13 +25,12 @@ export function extractSubstring(
|
|||||||
|
|
||||||
if (!multiLine) {
|
if (!multiLine) {
|
||||||
result.push(extract(input, start, length));
|
result.push(extract(input, start, length));
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
array = input.split('\n');
|
array = input.split('\n');
|
||||||
for (const word of array) {
|
for (const word of array) {
|
||||||
result.push(extract(word, start, length));
|
result.push(extract(word, start, length));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result = reverse ? result.map(word => reverseString(word)) : result;
|
result = reverse ? result.map((word) => reverseString(word)) : result;
|
||||||
return result.join('\n');
|
return result.join('\n');
|
||||||
}
|
}
|
@@ -1,10 +1,6 @@
|
|||||||
export type SplitOperatorType = 'symbol' | 'regex';
|
export type SplitOperatorType = 'symbol' | 'regex';
|
||||||
|
|
||||||
function isPalindrome(
|
function isPalindrome(word: string, left: number, right: number): boolean {
|
||||||
word: string,
|
|
||||||
left: number,
|
|
||||||
right: number
|
|
||||||
): boolean {
|
|
||||||
if (left >= right) return true;
|
if (left >= right) return true;
|
||||||
if (word[left] !== word[right]) return false;
|
if (word[left] !== word[right]) return false;
|
||||||
|
|
||||||
@@ -13,7 +9,7 @@ function isPalindrome(
|
|||||||
|
|
||||||
// check each word of the input and add the palindrome status in an array
|
// check each word of the input and add the palindrome status in an array
|
||||||
function checkPalindromes(array: string[]): boolean[] {
|
function checkPalindromes(array: string[]): boolean[] {
|
||||||
let status: boolean[] = [];
|
const status: boolean[] = [];
|
||||||
for (const word of array) {
|
for (const word of array) {
|
||||||
const palindromeStatus = isPalindrome(word, 0, word.length - 1);
|
const palindromeStatus = isPalindrome(word, 0, word.length - 1);
|
||||||
status.push(palindromeStatus);
|
status.push(palindromeStatus);
|
||||||
@@ -24,7 +20,7 @@ function checkPalindromes(array: string[]): boolean[] {
|
|||||||
export function palindromeList(
|
export function palindromeList(
|
||||||
splitOperatorType: SplitOperatorType,
|
splitOperatorType: SplitOperatorType,
|
||||||
input: string,
|
input: string,
|
||||||
separator: string, // the splitting separator will be the joining separator for visual satisfaction
|
separator: string // the splitting separator will be the joining separator for visual satisfaction
|
||||||
): string {
|
): string {
|
||||||
if (!input) return '';
|
if (!input) return '';
|
||||||
let array: string[];
|
let array: string[];
|
||||||
@@ -41,7 +37,5 @@ export function palindromeList(
|
|||||||
|
|
||||||
const statusArray = checkPalindromes(array);
|
const statusArray = checkPalindromes(array);
|
||||||
|
|
||||||
return statusArray.map(status => status.toString()).join(separator);
|
return statusArray.map((status) => status.toString()).join(separator);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -15,7 +15,9 @@ describe('randomizeCase', () => {
|
|||||||
const resultChar = result[i];
|
const resultChar = result[i];
|
||||||
|
|
||||||
if (/[a-zA-Z]/.test(inputChar)) {
|
if (/[a-zA-Z]/.test(inputChar)) {
|
||||||
expect([inputChar.toLowerCase(), inputChar.toUpperCase()]).toContain(resultChar);
|
expect([inputChar.toLowerCase(), inputChar.toUpperCase()]).toContain(
|
||||||
|
resultChar
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
expect(inputChar).toBe(resultChar);
|
expect(inputChar).toBe(resultChar);
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
export function randomizeCase(input: string): string {
|
export function randomizeCase(input: string): string {
|
||||||
return input
|
return input
|
||||||
.split('')
|
.split('')
|
||||||
.map(char => (Math.random() < 0.5 ? char.toLowerCase() : char.toUpperCase()))
|
.map((char) =>
|
||||||
|
Math.random() < 0.5 ? char.toLowerCase() : char.toUpperCase()
|
||||||
|
)
|
||||||
.join('');
|
.join('');
|
||||||
}
|
}
|
@@ -12,20 +12,19 @@ export function stringReverser(
|
|||||||
// split the input in multiLine mode
|
// split the input in multiLine mode
|
||||||
if (multiLine) {
|
if (multiLine) {
|
||||||
array = input.split('\n');
|
array = input.split('\n');
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
array.push(input);
|
array.push(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle empty items
|
// handle empty items
|
||||||
if (emptyItems){
|
if (emptyItems) {
|
||||||
array = array.filter(Boolean);
|
array = array.filter(Boolean);
|
||||||
}
|
}
|
||||||
// Handle trim
|
// Handle trim
|
||||||
if (trim) {
|
if (trim) {
|
||||||
array = array.map(line => line.trim());
|
array = array.map((line) => line.trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
result = array.map(element => reverseString(element));
|
result = array.map((element) => reverseString(element));
|
||||||
return result.join('\n');
|
return result.join('\n');
|
||||||
}
|
}
|
Reference in New Issue
Block a user