Skip to content

Commit

Permalink
Adding tool links
Browse files Browse the repository at this point in the history
  • Loading branch information
Made4Uo committed Jun 23, 2024
1 parent e47de40 commit 4604c32
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 15 deletions.
24 changes: 17 additions & 7 deletions src/pages/string/join/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { mergeText } from './service';
import { CustomSnackBarContext } from '../../../contexts/CustomSnackBarContext';

const initialValues = {
joinCharacter: ' ',
joinCharacter: '',
deleteBlank: true,
deleteTrailing: true
};
Expand All @@ -29,6 +29,7 @@ const validationSchema = Yup.object().shape({
});

const mergeOptions = {
placeholder: 'Join Character',
description:
'Symbol that connects broken\n' + 'pieces of text. (Space by default.)\n',
accessor: 'joinCharacter' as keyof typeof initialValues
Expand All @@ -41,29 +42,33 @@ const blankTrailingOptions: {
}[] = [
{
title: 'Delete Blank Lines',
description: "Delete lines that don't have\n" + 'text symbols.\n',
description: "Delete lines that don't have\n text symbols.\n",
accessor: 'deleteBlank'
},
{
title: 'Delete Trailing Spaces',
description: 'Remove spaces and tabs at\n' + 'the end of the lines.\n',
description: 'Remove spaces and tabs at\n the end of the lines.\n',
accessor: 'deleteTrailing'
}
];

const InputWithDesc = ({
placeholder,
description,
value,
onChange
}: {
placeholder: string;
description: string;
value: string;
onChange: (value: string) => void;
}) => {
return (
<Box>
<Box width={240}>
<TextField
sx={{ backgroundColor: 'white' }}
sx={{ backgroundColor: 'white', padding: 0 }}
size="small"
placeholder={placeholder}
value={value}
onChange={(event) => onChange(event.target.value)}
/>
Expand Down Expand Up @@ -116,13 +121,15 @@ export default function JoinText() {

useEffect(() => {
try {
console.log('Form values:', values['joinCharacter']);
setResult(mergeText(input, deleteBlank, deleteTrailing, joinCharacter));
} catch (exception: unknown) {
if (exception instanceof Error)
showSnackBar(exception.message, 'error');
}
}, [values, input]);

console.log('deleteBlank', deleteBlank);
return null;
};

Expand Down Expand Up @@ -153,8 +160,11 @@ export default function JoinText() {
<Box>
<Typography fontSize={22}>Text Merged Options</Typography>
<InputWithDesc
value={values.joinCharacter}
onChange={(value) => setFieldValue('joinCharacter', value)}
placeholder={mergeOptions.placeholder}
value={values['joinCharacter']}
onChange={(value) =>
setFieldValue(mergeOptions.accessor, value)
}
description={mergeOptions.description}
/>
</Box>
Expand Down
31 changes: 23 additions & 8 deletions src/pages/string/join/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,29 @@ export function mergeText(
): string {
const lines = text.split('\n');

const processedLines = lines
.map((line) =>
deleteTrailingSpaces ? line.replace(/ |\r\n|\n|\r/gm, '') : line
)
.filter((line) => !deleteBlankLines || line.trim() !== '');
let processedLines = lines;
if (deleteBlankLines) {
lines.map((line) =>
deleteTrailingSpaces
? line
// .split(' ')
// .join('')
// .replace(/|\r\n|\n|\r/gm, '')
.trimEnd()
: line
);
} else {
lines;
}

if (deleteBlankLines) {
processedLines = lines.filter(
(line) => !deleteBlankLines || line.trim() !== ''
);
} else {
lines;
}

return processedLines.join(joinCharacter);
}

Expand All @@ -21,7 +39,4 @@ Another line with trailing spaces
Final line without trailing spaces`;

export const mergedTextWithBlankLines: string = mergeText(text, false);
console.log('With blank lines:\n', mergedTextWithBlankLines);

export const mergedTextWithoutBlankLines: string = mergeText(text, true);
console.log('Without blank lines:\n', mergedTextWithoutBlankLines);

0 comments on commit 4604c32

Please sign in to comment.