mirror of
https://github.com/iib0011/omni-tools.git
synced 2025-09-19 14:09:31 +02:00
fix: style
This commit is contained in:
31
.idea/workspace.xml
generated
31
.idea/workspace.xml
generated
@@ -4,13 +4,8 @@
|
||||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="b30e2810-c4c1-4aad-b134-794e52cc1c7d" name="Changes" comment="feat: find most popular ui">
|
||||
<list default="true" id="b30e2810-c4c1-4aad-b134-794e52cc1c7d" name="Changes" comment="fix: misc">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/components/options/SelectWithDesc.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/options/SelectWithDesc.tsx" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/components/result/ToolTextResult.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/result/ToolTextResult.tsx" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/pages/list/find-most-popular/find-most-popular.service.test.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/list/find-most-popular/find-most-popular.service.test.ts" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/pages/list/sort/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/list/sort/index.tsx" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/utils/string.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/utils/string.ts" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
@@ -206,15 +201,7 @@
|
||||
<workItem from="1719492452780" duration="8000" />
|
||||
<workItem from="1719496624579" duration="6148000" />
|
||||
<workItem from="1720542757452" duration="5355000" />
|
||||
<workItem from="1720557527691" duration="1135000" />
|
||||
</task>
|
||||
<task id="LOCAL-00041" summary="ci: fix">
|
||||
<option name="closed" value="true" />
|
||||
<created>1719185893875</created>
|
||||
<option name="number" value="00041" />
|
||||
<option name="presentableId" value="LOCAL-00041" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1719185893875</updated>
|
||||
<workItem from="1720557527691" duration="3245000" />
|
||||
</task>
|
||||
<task id="LOCAL-00042" summary="ci: fix">
|
||||
<option name="closed" value="true" />
|
||||
@@ -600,7 +587,15 @@
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1720546921899</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="90" />
|
||||
<task id="LOCAL-00090" summary="fix: misc">
|
||||
<option name="closed" value="true" />
|
||||
<created>1720558690146</created>
|
||||
<option name="number" value="00090" />
|
||||
<option name="presentableId" value="LOCAL-00090" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1720558690147</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="91" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
@@ -658,7 +653,6 @@
|
||||
<MESSAGE value="feat: change gif speed" />
|
||||
<MESSAGE value="chore: remove unused deps" />
|
||||
<MESSAGE value="style: lint" />
|
||||
<MESSAGE value="fix: misc" />
|
||||
<MESSAGE value="fix: radio and list sort init" />
|
||||
<MESSAGE value="chore: formik updateField" />
|
||||
<MESSAGE value="ci: run e2e tests" />
|
||||
@@ -669,7 +663,8 @@
|
||||
<MESSAGE value="chore: idea config" />
|
||||
<MESSAGE value="feat: sort list" />
|
||||
<MESSAGE value="feat: find most popular ui" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="feat: find most popular ui" />
|
||||
<MESSAGE value="fix: misc" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="fix: misc" />
|
||||
</component>
|
||||
<component name="XSLT-Support.FileAssociations.UIState">
|
||||
<expand />
|
||||
|
@@ -3,5 +3,5 @@ a {
|
||||
}
|
||||
|
||||
a:hover {
|
||||
color: #030362
|
||||
color: #030362;
|
||||
}
|
||||
|
@@ -44,7 +44,7 @@ function displayFormater(
|
||||
dict: { [key: string]: number },
|
||||
displayFormat: DisplayFormat
|
||||
): string[] {
|
||||
let formattedOutput: string[] = [];
|
||||
const formattedOutput: string[] = [];
|
||||
const total = Object.values(dict).reduce((acc, val) => acc + val, 0);
|
||||
|
||||
switch (displayFormat) {
|
||||
|
@@ -5,43 +5,106 @@ import { TopItemsList } from './service';
|
||||
describe('TopItemsList Function', () => {
|
||||
test('should return unique items ignoring case sensitivity', () => {
|
||||
const input = 'apple,banana,Apple,orange,Banana,apple';
|
||||
const result = TopItemsList('symbol', ',', '\n', input, true, true, false, true);
|
||||
const result = TopItemsList(
|
||||
'symbol',
|
||||
',',
|
||||
'\n',
|
||||
input,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
true
|
||||
);
|
||||
expect(result).toBe('orange');
|
||||
});
|
||||
|
||||
test('should return unique items considering case sensitivity', () => {
|
||||
const input = 'apple,banana,Apple,orange,Banana,apple';
|
||||
const result = TopItemsList('symbol', ',', '\n', input, true, true, true, true);
|
||||
const result = TopItemsList(
|
||||
'symbol',
|
||||
',',
|
||||
'\n',
|
||||
input,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true
|
||||
);
|
||||
expect(result).toBe('banana\nApple\norange\nBanana');
|
||||
});
|
||||
|
||||
test('should return all unique items ignoring case sensitivity', () => {
|
||||
const input = 'apple,banana,Apple,orange,Banana,apple';
|
||||
const result = TopItemsList('symbol', ',', '\n', input, true, true, false, false);
|
||||
const result = TopItemsList(
|
||||
'symbol',
|
||||
',',
|
||||
'\n',
|
||||
input,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
false
|
||||
);
|
||||
expect(result).toBe('apple\nbanana\norange');
|
||||
});
|
||||
|
||||
test('should return all unique items considering case sensitivity', () => {
|
||||
const input = 'apple,banana,Apple,orange,Banana,apple';
|
||||
const result = TopItemsList('symbol', ',', '\n', input, true, true, true, false);
|
||||
const result = TopItemsList(
|
||||
'symbol',
|
||||
',',
|
||||
'\n',
|
||||
input,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
false
|
||||
);
|
||||
expect(result).toBe('apple\nbanana\nApple\norange\nBanana');
|
||||
});
|
||||
|
||||
test('should handle empty items deletion', () => {
|
||||
const input = 'apple,,banana, ,orange';
|
||||
const result = TopItemsList('symbol', ',', '\n', input, true, true, false, false);
|
||||
const result = TopItemsList(
|
||||
'symbol',
|
||||
',',
|
||||
'\n',
|
||||
input,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
false
|
||||
);
|
||||
expect(result).toBe('apple\nbanana\norange');
|
||||
});
|
||||
|
||||
test('should handle trimming items', () => {
|
||||
const input = ' apple , banana , orange ';
|
||||
const result = TopItemsList('symbol', ',', '\n', input, false, false, false, false);
|
||||
const result = TopItemsList(
|
||||
'symbol',
|
||||
',',
|
||||
'\n',
|
||||
input,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
);
|
||||
expect(result).toBe(' apple \n banana \n orange ');
|
||||
});
|
||||
|
||||
test('should handle regex split', () => {
|
||||
const input = 'apple banana orange';
|
||||
const result = TopItemsList('regex', '\\s+', '\n', input, false, false, false, false);
|
||||
const result = TopItemsList(
|
||||
'regex',
|
||||
'\\s+',
|
||||
'\n',
|
||||
input,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
);
|
||||
expect(result).toBe('apple\nbanana\norange');
|
||||
});
|
||||
});
|
||||
|
@@ -37,22 +37,28 @@ export function TopItemsList(
|
||||
array = input.split(splitSeparator);
|
||||
break;
|
||||
case 'regex':
|
||||
array = input.split(new RegExp(splitSeparator)).filter(item => item !== '');
|
||||
array = input
|
||||
.split(new RegExp(splitSeparator))
|
||||
.filter((item) => item !== '');
|
||||
break;
|
||||
}
|
||||
|
||||
// Trim items if required
|
||||
if (trimItems) {
|
||||
array = array.map(item => item.trim());
|
||||
array = array.map((item) => item.trim());
|
||||
}
|
||||
|
||||
// Delete empty items after initial split
|
||||
if (deleteEmptyItems) {
|
||||
array = array.filter(item => item !== '');
|
||||
array = array.filter((item) => item !== '');
|
||||
}
|
||||
|
||||
// Format the output with desired format
|
||||
const uniqueListItems = uniqueListBuilder(array, caseSensitive, absolutelyUnique);
|
||||
const uniqueListItems = uniqueListBuilder(
|
||||
array,
|
||||
caseSensitive,
|
||||
absolutelyUnique
|
||||
);
|
||||
|
||||
return uniqueListItems.join(joinSeparator);
|
||||
}
|
||||
|
@@ -4,7 +4,7 @@ import { groupList, SplitOperatorType } from './service';
|
||||
|
||||
describe('groupList', () => {
|
||||
it('splits by symbol, groups, pads, and formats correctly', () => {
|
||||
const input = "a,b,c,d,e,f,g,h,i,j";
|
||||
const input = 'a,b,c,d,e,f,g,h,i,j';
|
||||
const splitOperatorType: SplitOperatorType = 'symbol';
|
||||
const splitSeparator = ',';
|
||||
const groupNumber = 3;
|
||||
@@ -16,7 +16,7 @@ describe('groupList', () => {
|
||||
const padNonFullGroup = true;
|
||||
const paddingChar = 'x';
|
||||
|
||||
const expectedOutput = "[a-b-c] | [d-e-f] | [g-h-i] | [j-x-x]";
|
||||
const expectedOutput = '[a-b-c] | [d-e-f] | [g-h-i] | [j-x-x]';
|
||||
|
||||
const result = groupList(
|
||||
splitOperatorType,
|
||||
@@ -36,7 +36,7 @@ describe('groupList', () => {
|
||||
});
|
||||
|
||||
it('handles regex split, no padding, and formats correctly', () => {
|
||||
const input = "a1b2c3d4e5f6g7h8i9j";
|
||||
const input = 'a1b2c3d4e5f6g7h8i9j';
|
||||
const splitOperatorType: SplitOperatorType = 'regex';
|
||||
const splitSeparator = '\\d';
|
||||
const groupNumber = 4;
|
||||
@@ -47,7 +47,7 @@ describe('groupList', () => {
|
||||
const deleteEmptyItems = true;
|
||||
const padNonFullGroup = false;
|
||||
|
||||
const expectedOutput = "(a,b,c,d) / (e,f,g,h) / (i,j)";
|
||||
const expectedOutput = '(a,b,c,d) / (e,f,g,h) / (i,j)';
|
||||
|
||||
const result = groupList(
|
||||
splitOperatorType,
|
||||
@@ -66,7 +66,7 @@ describe('groupList', () => {
|
||||
});
|
||||
|
||||
it('handles empty items removal and padd the last group with a z', () => {
|
||||
const input = "a,,b,,c,,d,,e,,";
|
||||
const input = 'a,,b,,c,,d,,e,,';
|
||||
const splitOperatorType: SplitOperatorType = 'symbol';
|
||||
const splitSeparator = ',';
|
||||
const groupNumber = 2;
|
||||
@@ -78,7 +78,7 @@ describe('groupList', () => {
|
||||
const padNonFullGroup = true;
|
||||
const paddingChar = 'z';
|
||||
|
||||
const expectedOutput = "<a:b> & <c:d> & <e:z>";
|
||||
const expectedOutput = '<a:b> & <c:d> & <e:z>';
|
||||
|
||||
const result = groupList(
|
||||
splitOperatorType,
|
||||
|
@@ -1,11 +1,7 @@
|
||||
export type SplitOperatorType = 'symbol' | 'regex';
|
||||
|
||||
|
||||
// function that split the array into an array of subarray of desired length
|
||||
function groupMaker(
|
||||
array: string[],
|
||||
groupNumber: number,
|
||||
): string[][] {
|
||||
function groupMaker(array: string[], groupNumber: number): string[][] {
|
||||
const result: string[][] = [];
|
||||
for (let i = 0; i < array.length; i += groupNumber) {
|
||||
result.push(array.slice(i, i + groupNumber));
|
||||
@@ -18,7 +14,7 @@ function groupFiller(
|
||||
array: string[][],
|
||||
groupNumber: number,
|
||||
padNonFullGroup: boolean,
|
||||
paddingChar: string = '',
|
||||
paddingChar: string = ''
|
||||
): string[][] {
|
||||
if (padNonFullGroup) {
|
||||
const lastSubArray: string[] = array[array.length - 1];
|
||||
@@ -30,7 +26,6 @@ function groupFiller(
|
||||
array[array.length - 1] = lastSubArray;
|
||||
}
|
||||
return array;
|
||||
|
||||
}
|
||||
|
||||
// function that join with the item separator and wrap with left and right each subArray of the Array
|
||||
@@ -38,14 +33,13 @@ function groupJoinerAndWrapper(
|
||||
array: string[][],
|
||||
itemSeparator: string = '',
|
||||
leftWrap: string = '',
|
||||
rightWrap: string = '',
|
||||
rightWrap: string = ''
|
||||
): string[] {
|
||||
return array.map(subArray => {
|
||||
return array.map((subArray) => {
|
||||
return leftWrap + subArray.join(itemSeparator) + rightWrap;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
export function groupList(
|
||||
splitOperatorType: SplitOperatorType,
|
||||
splitSeparator: string,
|
||||
@@ -57,8 +51,7 @@ export function groupList(
|
||||
groupSeparator: string,
|
||||
deleteEmptyItems: boolean,
|
||||
padNonFullGroup: boolean,
|
||||
paddingChar: string = '',
|
||||
|
||||
paddingChar: string = ''
|
||||
): string {
|
||||
let array: string[];
|
||||
let splitedArray: string[][];
|
||||
@@ -74,19 +67,28 @@ export function groupList(
|
||||
}
|
||||
// delete empty items after intial split
|
||||
if (deleteEmptyItems) {
|
||||
array = array.filter(item => item !== '');
|
||||
array = array.filter((item) => item !== '');
|
||||
}
|
||||
|
||||
// split the input into an array of subArray with the desired length
|
||||
splitedArray = groupMaker(array, groupNumber);
|
||||
|
||||
// fill the last subArray is PadNonFullGroup is enabled
|
||||
fullSplitedArray = groupFiller(splitedArray, groupNumber, padNonFullGroup, paddingChar);
|
||||
fullSplitedArray = groupFiller(
|
||||
splitedArray,
|
||||
groupNumber,
|
||||
padNonFullGroup,
|
||||
paddingChar
|
||||
);
|
||||
|
||||
// get the list of formated subArray with the item separator and left and right wrapper
|
||||
result = groupJoinerAndWrapper(fullSplitedArray, itemSeparator, leftWrap, rightWrap);
|
||||
result = groupJoinerAndWrapper(
|
||||
fullSplitedArray,
|
||||
itemSeparator,
|
||||
leftWrap,
|
||||
rightWrap
|
||||
);
|
||||
|
||||
// finnaly join the group separator before returning
|
||||
return result.join(groupSeparator);
|
||||
}
|
||||
|
||||
|
@@ -4,7 +4,7 @@ export function reverseList(
|
||||
splitOperatorType: SplitOperatorType,
|
||||
splitSeparator: string,
|
||||
joinSeparator: string = '\n',
|
||||
input: string,
|
||||
input: string
|
||||
): string {
|
||||
let array: string[] = [];
|
||||
switch (splitOperatorType) {
|
||||
@@ -12,7 +12,9 @@ export function reverseList(
|
||||
array = input.split(splitSeparator);
|
||||
break;
|
||||
case 'regex':
|
||||
array = input.split(new RegExp(splitSeparator)).filter(item => item !== '');
|
||||
array = input
|
||||
.split(new RegExp(splitSeparator))
|
||||
.filter((item) => item !== '');
|
||||
break;
|
||||
}
|
||||
|
||||
|
@@ -1,8 +1,5 @@
|
||||
import { expect, describe, it } from 'vitest';
|
||||
import {
|
||||
SplitOperatorType,
|
||||
rotateList
|
||||
} from './service';
|
||||
import { SplitOperatorType, rotateList } from './service';
|
||||
|
||||
describe('rotate function', () => {
|
||||
it('should rotate right side if right is set to true', () => {
|
||||
@@ -20,10 +17,10 @@ describe('rotate function', () => {
|
||||
joinSeparator,
|
||||
right,
|
||||
|
||||
step);
|
||||
step
|
||||
);
|
||||
|
||||
expect(result).toBe('mango apple pineaple lemon orange');
|
||||
|
||||
});
|
||||
|
||||
it('should rotate left side if right is set to true', () => {
|
||||
@@ -41,10 +38,10 @@ describe('rotate function', () => {
|
||||
joinSeparator,
|
||||
right,
|
||||
|
||||
step);
|
||||
step
|
||||
);
|
||||
|
||||
expect(result).toBe('pineaple lemon orange mango apple');
|
||||
|
||||
});
|
||||
|
||||
it('should rotate left side with 2 step if right is set to true', () => {
|
||||
@@ -62,10 +59,10 @@ describe('rotate function', () => {
|
||||
joinSeparator,
|
||||
right,
|
||||
|
||||
step);
|
||||
step
|
||||
);
|
||||
|
||||
expect(result).toBe('lemon orange mango apple pineaple');
|
||||
|
||||
});
|
||||
|
||||
it('should raise an error if step is negative', () => {
|
||||
@@ -83,9 +80,9 @@ describe('rotate function', () => {
|
||||
splitSeparator,
|
||||
joinSeparator,
|
||||
right,
|
||||
step);
|
||||
step
|
||||
);
|
||||
}).toThrowError('Rotation step must be greater than zero.');
|
||||
|
||||
});
|
||||
|
||||
it('should raise an error if step is undefined', () => {
|
||||
@@ -101,10 +98,8 @@ describe('rotate function', () => {
|
||||
input,
|
||||
splitSeparator,
|
||||
joinSeparator,
|
||||
right);
|
||||
right
|
||||
);
|
||||
}).toThrowError('Rotation step contains non-digits.');
|
||||
|
||||
});
|
||||
|
||||
|
||||
})
|
||||
});
|
||||
|
@@ -1,10 +1,7 @@
|
||||
import { isNumber } from 'utils/string';
|
||||
export type SplitOperatorType = 'symbol' | 'regex';
|
||||
|
||||
function rotateArray(
|
||||
array: string[],
|
||||
step: number,
|
||||
right: boolean): string[] {
|
||||
function rotateArray(array: string[], step: number, right: boolean): string[] {
|
||||
const length = array.length;
|
||||
|
||||
// Normalize the step to be within the bounds of the array length
|
||||
@@ -12,10 +9,14 @@ function rotateArray(
|
||||
|
||||
if (right) {
|
||||
// Rotate right
|
||||
return array.slice(-normalizedPositions).concat(array.slice(0, -normalizedPositions));
|
||||
return array
|
||||
.slice(-normalizedPositions)
|
||||
.concat(array.slice(0, -normalizedPositions));
|
||||
} else {
|
||||
// Rotate left
|
||||
return array.slice(normalizedPositions).concat(array.slice(0, normalizedPositions));
|
||||
return array
|
||||
.slice(normalizedPositions)
|
||||
.concat(array.slice(0, normalizedPositions));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +26,7 @@ export function rotateList(
|
||||
splitSeparator: string,
|
||||
joinSeparator: string,
|
||||
right: boolean,
|
||||
step?: number,
|
||||
step?: number
|
||||
): string {
|
||||
let array: string[];
|
||||
let rotatedArray: string[];
|
||||
@@ -39,10 +40,10 @@ export function rotateList(
|
||||
}
|
||||
if (step !== undefined) {
|
||||
if (step <= 0) {
|
||||
throw new Error("Rotation step must be greater than zero.");
|
||||
throw new Error('Rotation step must be greater than zero.');
|
||||
}
|
||||
rotatedArray = rotateArray(array, step, right);
|
||||
return rotatedArray.join(joinSeparator);
|
||||
}
|
||||
throw new Error("Rotation step contains non-digits.")
|
||||
throw new Error('Rotation step contains non-digits.');
|
||||
}
|
@@ -2,7 +2,7 @@ export type SplitOperatorType = 'symbol' | 'regex';
|
||||
|
||||
// function that randomize the array
|
||||
function shuffleArray(array: string[]): string[] {
|
||||
let shuffledArray = array.slice(); // Create a copy of the array
|
||||
const shuffledArray = array.slice(); // Create a copy of the array
|
||||
for (let i = shuffledArray.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
[shuffledArray[i], shuffledArray[j]] = [shuffledArray[j], shuffledArray[i]];
|
||||
@@ -15,7 +15,7 @@ export function shuffleList(
|
||||
input: string,
|
||||
splitSeparator: string,
|
||||
joinSeparator: string,
|
||||
length?: number, // "?" is to handle the case the user let the input blank
|
||||
length?: number // "?" is to handle the case the user let the input blank
|
||||
): string {
|
||||
let array: string[];
|
||||
let shuffledArray: string[];
|
||||
@@ -30,7 +30,7 @@ export function shuffleList(
|
||||
shuffledArray = shuffleArray(array);
|
||||
if (length !== undefined) {
|
||||
if (length <= 0) {
|
||||
throw new Error("Length value must be a positive number.");
|
||||
throw new Error('Length value must be a positive number.');
|
||||
}
|
||||
return shuffledArray.slice(0, length).join(joinSeparator);
|
||||
}
|
||||
|
@@ -1,11 +1,7 @@
|
||||
import { expect, describe, it } from 'vitest';
|
||||
import {
|
||||
shuffleList,
|
||||
SplitOperatorType
|
||||
} from './service';
|
||||
import { shuffleList, SplitOperatorType } from './service';
|
||||
|
||||
describe('shuffle function', () => {
|
||||
|
||||
it('should be a 4 length list if no length value defined ', () => {
|
||||
const input: string = 'apple, pineaple, lemon, orange';
|
||||
const splitOperatorType: SplitOperatorType = 'symbol';
|
||||
@@ -90,5 +86,4 @@ describe('shuffle function', () => {
|
||||
console.log(result);
|
||||
expect(result).toBe('');
|
||||
});
|
||||
|
||||
})
|
||||
});
|
||||
|
@@ -6,7 +6,7 @@ export function truncateList(
|
||||
splitSeparator: string,
|
||||
joinSeparator: string,
|
||||
end: boolean,
|
||||
length?: number,
|
||||
length?: number
|
||||
): string {
|
||||
let array: string[];
|
||||
let truncatedArray: string[];
|
||||
@@ -20,11 +20,12 @@ export function truncateList(
|
||||
}
|
||||
if (length !== undefined) {
|
||||
if (length < 0) {
|
||||
throw new Error("Length value must be a positive number.")
|
||||
throw new Error('Length value must be a positive number.');
|
||||
}
|
||||
truncatedArray = end ? array.slice(0, length) : array.slice(array.length - length, array.length);
|
||||
truncatedArray = end
|
||||
? array.slice(0, length)
|
||||
: array.slice(array.length - length, array.length);
|
||||
return truncatedArray.join(joinSeparator);
|
||||
}
|
||||
throw new Error("Length value isn't a value number.");
|
||||
|
||||
}
|
@@ -1,9 +1,6 @@
|
||||
import { expect, describe, it } from 'vitest';
|
||||
|
||||
import {
|
||||
SplitOperatorType,
|
||||
truncateList,
|
||||
} from './service';
|
||||
import { SplitOperatorType, truncateList } from './service';
|
||||
|
||||
describe('truncate function', () => {
|
||||
it('should remove at the end (one element) if end is set to true', () => {
|
||||
@@ -20,10 +17,10 @@ describe('truncate function', () => {
|
||||
splitSeparator,
|
||||
joinSeparator,
|
||||
end,
|
||||
length);
|
||||
length
|
||||
);
|
||||
|
||||
expect(result).toBe('apple pineaple lemon');
|
||||
|
||||
});
|
||||
|
||||
it('should return 3 elements from the start if end is set to true', () => {
|
||||
@@ -40,10 +37,10 @@ describe('truncate function', () => {
|
||||
splitSeparator,
|
||||
joinSeparator,
|
||||
end,
|
||||
length);
|
||||
length
|
||||
);
|
||||
|
||||
expect(result).toBe('apple pineaple lemon');
|
||||
|
||||
});
|
||||
|
||||
it('should return 3 elements from the start if end is set to true', () => {
|
||||
@@ -60,10 +57,10 @@ describe('truncate function', () => {
|
||||
splitSeparator,
|
||||
joinSeparator,
|
||||
end,
|
||||
length);
|
||||
length
|
||||
);
|
||||
|
||||
expect(result).toBe('apple pineaple lemon');
|
||||
|
||||
});
|
||||
|
||||
it('should return 3 elements from the end if end is set to true', () => {
|
||||
@@ -80,10 +77,10 @@ describe('truncate function', () => {
|
||||
splitSeparator,
|
||||
joinSeparator,
|
||||
end,
|
||||
length);
|
||||
length
|
||||
);
|
||||
|
||||
expect(result).toBe('lemon orange mango');
|
||||
|
||||
});
|
||||
|
||||
it('should return a void string if length is set to 0', () => {
|
||||
@@ -100,10 +97,10 @@ describe('truncate function', () => {
|
||||
splitSeparator,
|
||||
joinSeparator,
|
||||
end,
|
||||
length);
|
||||
length
|
||||
);
|
||||
|
||||
expect(result).toBe('');
|
||||
|
||||
});
|
||||
|
||||
it('should return an element (first) string if length is set to 1 and end is set to true', () => {
|
||||
@@ -120,10 +117,10 @@ describe('truncate function', () => {
|
||||
splitSeparator,
|
||||
joinSeparator,
|
||||
end,
|
||||
length);
|
||||
length
|
||||
);
|
||||
|
||||
expect(result).toBe('apple');
|
||||
|
||||
});
|
||||
|
||||
it('should return an element (last) string if length is set to 1 and end is set to false', () => {
|
||||
@@ -140,10 +137,10 @@ describe('truncate function', () => {
|
||||
splitSeparator,
|
||||
joinSeparator,
|
||||
end,
|
||||
length);
|
||||
length
|
||||
);
|
||||
|
||||
expect(result).toBe('mango');
|
||||
|
||||
});
|
||||
|
||||
it('should throw an error if the length value is negative', () => {
|
||||
@@ -161,8 +158,9 @@ describe('truncate function', () => {
|
||||
splitSeparator,
|
||||
joinSeparator,
|
||||
end,
|
||||
length)
|
||||
}).toThrow("Length value must be a positive number.");
|
||||
length
|
||||
);
|
||||
}).toThrow('Length value must be a positive number.');
|
||||
});
|
||||
|
||||
it('should throw an error if the length value is left blank', () => {
|
||||
@@ -178,8 +176,8 @@ describe('truncate function', () => {
|
||||
input,
|
||||
splitSeparator,
|
||||
joinSeparator,
|
||||
end)
|
||||
end
|
||||
);
|
||||
}).toThrow("Length value isn't a value number.");
|
||||
});
|
||||
|
||||
})
|
||||
});
|
||||
|
@@ -63,7 +63,7 @@ export function unwrapList(
|
||||
}
|
||||
// trim items if needed
|
||||
if (trimItems) {
|
||||
unwrappedArray = unwrappedArray.map(item => item.trim());
|
||||
unwrappedArray = unwrappedArray.map((item) => item.trim());
|
||||
}
|
||||
return unwrappedArray.join(joinSeparator);
|
||||
}
|
||||
|
@@ -3,68 +3,168 @@ import { unwrapList } from './service';
|
||||
|
||||
describe('unwrapList function', () => {
|
||||
it('should unwrap elements correctly with symbol split', () => {
|
||||
const input = "##Hello##\n##World##";
|
||||
const result = unwrapList('symbol', input, '\n', ' ', true, true, true, '#', '#');
|
||||
expect(result).toBe("Hello World");
|
||||
const input = '##Hello##\n##World##';
|
||||
const result = unwrapList(
|
||||
'symbol',
|
||||
input,
|
||||
'\n',
|
||||
' ',
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
'#',
|
||||
'#'
|
||||
);
|
||||
expect(result).toBe('Hello World');
|
||||
});
|
||||
|
||||
it('should unwrap elements correctly with regex split', () => {
|
||||
const input = "##Hello##||##World##";
|
||||
const result = unwrapList('regex', input, '\\|\\|', ' ', true, true, true, '#', '#');
|
||||
expect(result).toBe("Hello World");
|
||||
const input = '##Hello##||##World##';
|
||||
const result = unwrapList(
|
||||
'regex',
|
||||
input,
|
||||
'\\|\\|',
|
||||
' ',
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
'#',
|
||||
'#'
|
||||
);
|
||||
expect(result).toBe('Hello World');
|
||||
});
|
||||
|
||||
it('should handle multiple levels of unwrapping', () => {
|
||||
const input = "###Hello###";
|
||||
const result = unwrapList('symbol', input, '\n', ' ', true, true, true, '#', '#');
|
||||
expect(result).toBe("Hello");
|
||||
const input = '###Hello###';
|
||||
const result = unwrapList(
|
||||
'symbol',
|
||||
input,
|
||||
'\n',
|
||||
' ',
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
'#',
|
||||
'#'
|
||||
);
|
||||
expect(result).toBe('Hello');
|
||||
});
|
||||
|
||||
it('should handle single level of unwrapping', () => {
|
||||
const input = "###Hello###";
|
||||
const result = unwrapList('symbol', input, '\n', ' ', true, false, true, '#', '#');
|
||||
expect(result).toBe("##Hello##");
|
||||
const input = '###Hello###';
|
||||
const result = unwrapList(
|
||||
'symbol',
|
||||
input,
|
||||
'\n',
|
||||
' ',
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
'#',
|
||||
'#'
|
||||
);
|
||||
expect(result).toBe('##Hello##');
|
||||
});
|
||||
|
||||
it('should delete empty items', () => {
|
||||
const input = "##Hello##\n\n##World##";
|
||||
const result = unwrapList('symbol', input, '\n', ' ', true, true, true, '#', '#');
|
||||
expect(result).toBe("Hello World");
|
||||
const input = '##Hello##\n\n##World##';
|
||||
const result = unwrapList(
|
||||
'symbol',
|
||||
input,
|
||||
'\n',
|
||||
' ',
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
'#',
|
||||
'#'
|
||||
);
|
||||
expect(result).toBe('Hello World');
|
||||
});
|
||||
|
||||
it('should keep empty items if deleteEmptyItems is false', () => {
|
||||
const input = "##Hello##\n\n##World##";
|
||||
const result = unwrapList('symbol', input, '\n', ' ', false, true, true, '#', '#');
|
||||
expect(result).toBe("Hello World");
|
||||
const input = '##Hello##\n\n##World##';
|
||||
const result = unwrapList(
|
||||
'symbol',
|
||||
input,
|
||||
'\n',
|
||||
' ',
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
'#',
|
||||
'#'
|
||||
);
|
||||
expect(result).toBe('Hello World');
|
||||
});
|
||||
|
||||
it('should trim items', () => {
|
||||
const input = "## Hello ##\n## World ##";
|
||||
const result = unwrapList('symbol', input, '\n', ' ', true, true, true, '#', '#');
|
||||
expect(result).toBe("Hello World");
|
||||
const input = '## Hello ##\n## World ##';
|
||||
const result = unwrapList(
|
||||
'symbol',
|
||||
input,
|
||||
'\n',
|
||||
' ',
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
'#',
|
||||
'#'
|
||||
);
|
||||
expect(result).toBe('Hello World');
|
||||
});
|
||||
|
||||
it('should handle no left or right unwrapping', () => {
|
||||
const input = "Hello\nWorld";
|
||||
const input = 'Hello\nWorld';
|
||||
const result = unwrapList('symbol', input, '\n', ' ', true, true, true);
|
||||
expect(result).toBe("Hello World");
|
||||
expect(result).toBe('Hello World');
|
||||
});
|
||||
|
||||
it('should handle mixed levels of unwrapping', () => {
|
||||
const input = "###Hello##\n#World###";
|
||||
const result = unwrapList('symbol', input, '\n', ' ', true, true, true, '#', '#');
|
||||
expect(result).toBe("Hello World");
|
||||
const input = '###Hello##\n#World###';
|
||||
const result = unwrapList(
|
||||
'symbol',
|
||||
input,
|
||||
'\n',
|
||||
' ',
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
'#',
|
||||
'#'
|
||||
);
|
||||
expect(result).toBe('Hello World');
|
||||
});
|
||||
|
||||
it('should handle complex regex split', () => {
|
||||
const input = "##Hello##||###World###||####Test####";
|
||||
const result = unwrapList('regex', input, '\\|\\|', ' ', true, true, true, '#', '#');
|
||||
expect(result).toBe("Hello World Test");
|
||||
const input = '##Hello##||###World###||####Test####';
|
||||
const result = unwrapList(
|
||||
'regex',
|
||||
input,
|
||||
'\\|\\|',
|
||||
' ',
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
'#',
|
||||
'#'
|
||||
);
|
||||
expect(result).toBe('Hello World Test');
|
||||
});
|
||||
|
||||
it('should handle different joinSeparator', () => {
|
||||
const input = "##Hello##\n##World##";
|
||||
const result = unwrapList('symbol', input, '\n', '-', true, true, true, '#', '#');
|
||||
expect(result).toBe("Hello-World");
|
||||
const input = '##Hello##\n##World##';
|
||||
const result = unwrapList(
|
||||
'symbol',
|
||||
input,
|
||||
'\n',
|
||||
'-',
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
'#',
|
||||
'#'
|
||||
);
|
||||
expect(result).toBe('Hello-World');
|
||||
});
|
||||
});
|
@@ -11,8 +11,7 @@ export function wrapList(
|
||||
joinSeparator: string,
|
||||
deleteEmptyItems: boolean,
|
||||
left: string = '',
|
||||
right: string = '',
|
||||
|
||||
right: string = ''
|
||||
): string {
|
||||
let array: string[];
|
||||
let wrappedArray: string[];
|
||||
|
@@ -1,8 +1,5 @@
|
||||
import { expect, describe, it } from 'vitest';
|
||||
import {
|
||||
SplitOperatorType,
|
||||
wrapList
|
||||
} from './service';
|
||||
import { SplitOperatorType, wrapList } from './service';
|
||||
|
||||
describe('wrap function', () => {
|
||||
it('should return the same input if no left and right are blanked', () => {
|
||||
@@ -12,7 +9,6 @@ describe('wrap function', () => {
|
||||
const joinSeparator = ', ';
|
||||
const deleteEmptyItems = false;
|
||||
|
||||
|
||||
const result = wrapList(
|
||||
splitOperatorType,
|
||||
input,
|
||||
@@ -22,7 +18,6 @@ describe('wrap function', () => {
|
||||
);
|
||||
|
||||
expect(result).toBe('apple, pineaple, lemon, orange, mango');
|
||||
|
||||
});
|
||||
|
||||
it('should append to left if defined', () => {
|
||||
@@ -39,10 +34,12 @@ describe('wrap function', () => {
|
||||
splitSeparator,
|
||||
joinSeparator,
|
||||
deleteEmptyItems,
|
||||
left);
|
||||
|
||||
expect(result).toBe('the apple, the pineaple, the lemon, the orange, the mango');
|
||||
left
|
||||
);
|
||||
|
||||
expect(result).toBe(
|
||||
'the apple, the pineaple, the lemon, the orange, the mango'
|
||||
);
|
||||
});
|
||||
|
||||
it('should append to right if defined', () => {
|
||||
@@ -61,7 +58,8 @@ describe('wrap function', () => {
|
||||
joinSeparator,
|
||||
deleteEmptyItems,
|
||||
left,
|
||||
right);
|
||||
right
|
||||
);
|
||||
|
||||
expect(result).toBe('applez, pineaplez, lemonz, orangez, mangoz');
|
||||
});
|
||||
@@ -82,10 +80,10 @@ describe('wrap function', () => {
|
||||
joinSeparator,
|
||||
deleteEmptyItems,
|
||||
left,
|
||||
right);
|
||||
right
|
||||
);
|
||||
|
||||
expect(result).toBe('Kapplez, Kpineaplez, Klemonz, Korangez, Kmangoz');
|
||||
|
||||
});
|
||||
|
||||
it('should append to both side if both defined and not delete empty items', () => {
|
||||
@@ -104,13 +102,12 @@ describe('wrap function', () => {
|
||||
joinSeparator,
|
||||
deleteEmptyItems,
|
||||
left,
|
||||
right);
|
||||
right
|
||||
);
|
||||
|
||||
expect(result).toBe('Kapplez, Kpineaplez, Klemonz, Korangez, Kmangoz, Kz');
|
||||
|
||||
});
|
||||
|
||||
|
||||
it('should append to both side if both defined and delete empty items', () => {
|
||||
const input: string = 'apple, pineaple, lemon, , orange, mango';
|
||||
const splitOperatorType: SplitOperatorType = 'symbol';
|
||||
@@ -127,11 +124,9 @@ describe('wrap function', () => {
|
||||
joinSeparator,
|
||||
deleteEmptyItems,
|
||||
left,
|
||||
right);
|
||||
right
|
||||
);
|
||||
|
||||
expect(result).toBe('Kapplez, Kpineaplez, Klemonz, Korangez, Kmangoz');
|
||||
|
||||
});
|
||||
|
||||
|
||||
})
|
||||
});
|
||||
|
Reference in New Issue
Block a user