mirror of
https://github.com/iib0011/omni-tools.git
synced 2025-09-19 05:59:34 +02:00
wrap tool and testCases, then updated index file
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import { tool as listWrap } from './wrap/meta';
|
||||||
import { tool as listRotate } from './rotate/meta';
|
import { tool as listRotate } from './rotate/meta';
|
||||||
import { tool as listTruncate } from './truncate/meta';
|
import { tool as listTruncate } from './truncate/meta';
|
||||||
import { tool as listShuffle } from './shuffle/meta';
|
import { tool as listShuffle } from './shuffle/meta';
|
||||||
|
11
src/pages/list/wrap/index.tsx
Normal file
11
src/pages/list/wrap/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 Wrap() {
|
||||||
|
return <Box>Lorem ipsum</Box>;
|
||||||
|
}
|
13
src/pages/list/wrap/meta.ts
Normal file
13
src/pages/list/wrap/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: 'Wrap',
|
||||||
|
path: 'wrap',
|
||||||
|
// image,
|
||||||
|
description: '',
|
||||||
|
shortDescription: '',
|
||||||
|
keywords: ['wrap'],
|
||||||
|
component: lazy(() => import('./index'))
|
||||||
|
});
|
27
src/pages/list/wrap/service.ts
Normal file
27
src/pages/list/wrap/service.ts
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
export type SplitOperatorType = 'symbol' | 'regex';
|
||||||
|
|
||||||
|
function wrap(array: string[], left: string, right: string): string[] {
|
||||||
|
return array.map((element) => left + element + right);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function wrapList(
|
||||||
|
splitOperatorType: SplitOperatorType,
|
||||||
|
input: string,
|
||||||
|
splitSeparator: string,
|
||||||
|
joinSeparator: string,
|
||||||
|
left: string = '',
|
||||||
|
right: string = ''
|
||||||
|
): string {
|
||||||
|
let array: string[];
|
||||||
|
let wrappedArray: string[];
|
||||||
|
switch (splitOperatorType) {
|
||||||
|
case 'symbol':
|
||||||
|
array = input.split(splitSeparator);
|
||||||
|
break;
|
||||||
|
case 'regex':
|
||||||
|
array = input.split(new RegExp(splitSeparator));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
wrappedArray = wrap(array, left, right);
|
||||||
|
return wrappedArray.join(joinSeparator);
|
||||||
|
}
|
84
src/pages/list/wrap/wrap.service.test.ts
Normal file
84
src/pages/list/wrap/wrap.service.test.ts
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
import { expect, describe, it } from 'vitest';
|
||||||
|
import {
|
||||||
|
SplitOperatorType,
|
||||||
|
wrapList
|
||||||
|
} from './service';
|
||||||
|
|
||||||
|
describe('wrap function', () => {
|
||||||
|
it('should return the same input if no left and right are blanked', () => {
|
||||||
|
const input: string = 'apple, pineaple, lemon, orange, mango';
|
||||||
|
const splitOperatorType: SplitOperatorType = 'symbol';
|
||||||
|
const splitSeparator = ', ';
|
||||||
|
const joinSeparator = ', ';
|
||||||
|
|
||||||
|
|
||||||
|
const result = wrapList(
|
||||||
|
splitOperatorType,
|
||||||
|
input,
|
||||||
|
splitSeparator,
|
||||||
|
joinSeparator,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(result).toBe('apple, pineaple, lemon, orange, mango');
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should append to left if defined', () => {
|
||||||
|
const input: string = 'apple, pineaple, lemon, orange, mango';
|
||||||
|
const splitOperatorType: SplitOperatorType = 'symbol';
|
||||||
|
const splitSeparator = ', ';
|
||||||
|
const joinSeparator = ', ';
|
||||||
|
const left = 'the ';
|
||||||
|
|
||||||
|
const result = wrapList(
|
||||||
|
splitOperatorType,
|
||||||
|
input,
|
||||||
|
splitSeparator,
|
||||||
|
joinSeparator,
|
||||||
|
left);
|
||||||
|
|
||||||
|
expect(result).toBe('the apple, the pineaple, the lemon, the orange, the mango');
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should append to right if defined', () => {
|
||||||
|
const input: string = 'apple, pineaple, lemon, orange, mango';
|
||||||
|
const splitOperatorType: SplitOperatorType = 'symbol';
|
||||||
|
const splitSeparator = ', ';
|
||||||
|
const joinSeparator = ', ';
|
||||||
|
const left = '';
|
||||||
|
const right = 'z';
|
||||||
|
|
||||||
|
const result = wrapList(
|
||||||
|
splitOperatorType,
|
||||||
|
input,
|
||||||
|
splitSeparator,
|
||||||
|
joinSeparator,
|
||||||
|
left,
|
||||||
|
right);
|
||||||
|
|
||||||
|
expect(result).toBe('applez, pineaplez, lemonz, orangez, mangoz');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should append to both side if both defined', () => {
|
||||||
|
const input: string = 'apple, pineaple, lemon, orange, mango';
|
||||||
|
const splitOperatorType: SplitOperatorType = 'symbol';
|
||||||
|
const splitSeparator = ', ';
|
||||||
|
const joinSeparator = ', ';
|
||||||
|
const left = 'K';
|
||||||
|
const right = 'z';
|
||||||
|
|
||||||
|
const result = wrapList(
|
||||||
|
splitOperatorType,
|
||||||
|
input,
|
||||||
|
splitSeparator,
|
||||||
|
joinSeparator,
|
||||||
|
left,
|
||||||
|
right);
|
||||||
|
|
||||||
|
expect(result).toBe('Kapplez, Kpineaplez, Klemonz, Korangez, Kmangoz');
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
})
|
Reference in New Issue
Block a user