mirror of
https://github.com/iib0011/omni-tools.git
synced 2026-11-25 07:04:40 +03:00
Merge branch 'main' into pr/Sushanth012/456
This commit is contained in:
commit
fe42c0f3ef
15 files changed
+155
-56
No files matched your search
@@ -154,16 +154,16 @@ The translation files are [here](public/locales). Only edit these if you are a d
|
||||
<!-- I18N-COVERAGE:START -->
|
||||
| Language | Translation status | Missing keys |
|
||||
|----------|--------------------|--------------|
|
||||
| uk - Ukrainian | `▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ 100%` | 0 |
|
||||
| zh - Chinese | `▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░ 72%` | 478 |
|
||||
| hi - Hindi | `▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░ 71%` | 505 |
|
||||
| ru - Russian | `▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░ 71%` | 493 |
|
||||
| de - German | `▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░ 70%` | 515 |
|
||||
| es - Spanish | `▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░ 70%` | 515 |
|
||||
| fr - French | `▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░ 70%` | 515 |
|
||||
| ja - Japanese | `▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░ 70%` | 515 |
|
||||
| nl - Dutch | `▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░ 70%` | 515 |
|
||||
| pt - Portuguese | `▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░ 70%` | 515 |
|
||||
| uk - Ukrainian | `▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ 100%` | 3 |
|
||||
| zh - Chinese | `▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░ 72%` | 481 |
|
||||
| ru - Russian | `▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░ 71%` | 496 |
|
||||
| de - German | `▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░ 70%` | 518 |
|
||||
| es - Spanish | `▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░ 70%` | 518 |
|
||||
| fr - French | `▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░ 70%` | 518 |
|
||||
| hi - Hindi | `▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░ 70%` | 508 |
|
||||
| ja - Japanese | `▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░ 70%` | 518 |
|
||||
| nl - Dutch | `▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░ 70%` | 518 |
|
||||
| pt - Portuguese | `▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░ 70%` | 518 |
|
||||
<!-- I18N-COVERAGE:END -->
|
||||
|
||||
## ⭐ Star History
|
||||
|
||||
@@ -6,6 +6,11 @@
|
||||
"resultTitle": "Beautified XML",
|
||||
"shortDescription": "Format and beautify XML code",
|
||||
"title": "XML Beautifier",
|
||||
"options": {
|
||||
"title": "Options",
|
||||
"preserveAttributesTitle": "Preserve Attributes",
|
||||
"preserveAttributesDesc": "Preserve the original XML attribute formatting and order."
|
||||
},
|
||||
"toolInfo": {
|
||||
"description": "This tool allows you to format XML data with proper indentation and spacing, making it more readable and easier to work with.",
|
||||
"title": "XML Beautifier"
|
||||
|
||||
@@ -58,4 +58,16 @@ describe('csvRowsToColumns', () => {
|
||||
'Variety,Arabica,Robusta,Liberica,Mocha\nOrigin,Ethiopia,Africa,Philippines,1x'
|
||||
);
|
||||
});
|
||||
|
||||
it('should remove blank lines', () => {
|
||||
const input = 'a,b\n\n1,2\n\nx,y';
|
||||
const result = csvRowsToColumns(input, false, '', '#');
|
||||
expect(result).toBe('a,1,x\nb,2,y');
|
||||
});
|
||||
|
||||
it('should remove lines that contain only whitespace', () => {
|
||||
const input = 'a,b\n \n1,2';
|
||||
const result = csvRowsToColumns(input, false, '', '#');
|
||||
expect(result).toBe('a,1\nb,2');
|
||||
});
|
||||
});
|
||||
@@ -25,7 +25,9 @@ export function csvRowsToColumns(
|
||||
.split('\n')
|
||||
.map((row) => row.split(','))
|
||||
.filter(
|
||||
(row) => row.length > 0 && !row[0].trim().startsWith(commentCharacter)
|
||||
(row) =>
|
||||
!(row.length === 1 && row[0].trim() === '') &&
|
||||
!row[0].trim().startsWith(commentCharacter)
|
||||
);
|
||||
const columnCount = Math.max(...rows.map((row) => row.length));
|
||||
for (let i = 0; i < rows.length; i++) {
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import imageCompression from 'browser-image-compression';
|
||||
import { compressImages } from './service';
|
||||
|
||||
vi.mock('browser-image-compression', () => ({
|
||||
default: vi.fn()
|
||||
}));
|
||||
|
||||
describe('compressImages', () => {
|
||||
beforeEach(() => {
|
||||
vi.mocked(imageCompression).mockResolvedValue(
|
||||
new File(['compressed'], 'photo.jpg', { type: 'image/jpeg' })
|
||||
);
|
||||
});
|
||||
|
||||
it('preserves JPEG EXIF metadata while compressing', async () => {
|
||||
const input = new File(['original'], 'photo.jpg', {
|
||||
type: 'image/jpeg'
|
||||
});
|
||||
|
||||
await compressImages([input], { maxFileSizeInMB: 1, quality: 80 });
|
||||
|
||||
expect(imageCompression).toHaveBeenCalledWith(
|
||||
input,
|
||||
expect.objectContaining({ preserveExif: true })
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -14,6 +14,7 @@ export const compressImages = async (
|
||||
maxSizeMB: maxFileSizeInMB,
|
||||
maxWidthOrHeight: 1920, // Reasonable default for most use cases
|
||||
useWebWorker: true,
|
||||
preserveExif: true,
|
||||
initialQuality: quality / 100 // Convert percentage to decimal
|
||||
};
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ function customAlphabeticSort(
|
||||
return a.toLowerCase().localeCompare(b.toLowerCase());
|
||||
} else {
|
||||
// Case-sensitive comparison
|
||||
return a.charCodeAt(0) - b.charCodeAt(0);
|
||||
return a === b ? 0 : a < b ? -1 : 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -183,6 +183,12 @@ describe('numericSort function', () => {
|
||||
});
|
||||
|
||||
// CASE SENSITIVE TEST
|
||||
it('should compare the full string when prefixes match', () => {
|
||||
const result = alphabeticSort(['az', 'aa'], true, ',', false, true);
|
||||
|
||||
expect(result).toBe('aa,az');
|
||||
});
|
||||
|
||||
it('should sort a list of string (uppercase) in decreasing order with comma separator ', () => {
|
||||
const array: string[] = ['Apple', 'Pineaple', 'Lemon', 'Orange'];
|
||||
const increasing: boolean = false;
|
||||
|
||||
@@ -130,7 +130,7 @@ export default function SumNumbers({ title }: ToolComponentProps) {
|
||||
{
|
||||
title: t('sum.numberExtraction'),
|
||||
component: extractionTypes.map(
|
||||
({ title, description, type, withTextField, textValueAccessor }) =>
|
||||
({ title, type, withTextField, textValueAccessor }) =>
|
||||
withTextField ? (
|
||||
<RadioWithTextField
|
||||
key={type}
|
||||
|
||||
@@ -1,10 +1,23 @@
|
||||
export type NumberExtractionType = 'smart' | 'delimiter';
|
||||
|
||||
function getAllNumbers(text: string): number[] {
|
||||
const regex = /\d+/g;
|
||||
const matches = text.match(regex);
|
||||
const matches = text.match(/-?\d+(?:\.\d+)?/g);
|
||||
return matches ? matches.map(Number) : [];
|
||||
}
|
||||
function getDelimitedNumbers(text: string, separator: string): number[] {
|
||||
const normalizedSeparator = separator.replace(/\\n/g, '\n').trim();
|
||||
const pattern = normalizedSeparator
|
||||
? new RegExp(
|
||||
normalizedSeparator.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + '\\s*'
|
||||
)
|
||||
: /\s+/;
|
||||
|
||||
return text
|
||||
.split(pattern)
|
||||
.map((part) => part.trim())
|
||||
.filter((part) => part !== '' && !Number.isNaN(Number(part)))
|
||||
.map(Number);
|
||||
}
|
||||
|
||||
export const compute = (
|
||||
input: string,
|
||||
@@ -12,26 +25,17 @@ export const compute = (
|
||||
printRunningSum: boolean,
|
||||
separator: string
|
||||
): string => {
|
||||
let numbers: number[] = [];
|
||||
if (extractionType === 'smart') {
|
||||
numbers = getAllNumbers(input);
|
||||
} else {
|
||||
const parts = input.split(separator);
|
||||
// Filter out and convert parts that are numbers
|
||||
numbers = parts
|
||||
.filter((part) => !isNaN(Number(part)) && part.trim() !== '')
|
||||
.map(Number);
|
||||
}
|
||||
const numbers =
|
||||
extractionType === 'smart'
|
||||
? getAllNumbers(input)
|
||||
: getDelimitedNumbers(input, separator);
|
||||
|
||||
if (printRunningSum) {
|
||||
let result: string = '';
|
||||
let sum: number = 0;
|
||||
for (const i of numbers) {
|
||||
sum = sum + i;
|
||||
result = result + sum + '\n';
|
||||
}
|
||||
return result;
|
||||
} else
|
||||
return numbers
|
||||
.reduce((previousValue, currentValue) => previousValue + currentValue, 0)
|
||||
.toString();
|
||||
let sum = 0;
|
||||
return (
|
||||
numbers.map((n) => (sum += n)).join('\n') + (numbers.length ? '\n' : '')
|
||||
);
|
||||
}
|
||||
|
||||
return numbers.reduce((acc, n) => acc + n, 0).toString();
|
||||
};
|
||||
@@ -61,4 +61,16 @@ describe('compute function', () => {
|
||||
const result = compute(input, 'delimiter', false, ';');
|
||||
expect(result).toBe('13');
|
||||
});
|
||||
|
||||
it('should treat a literal \\n separator as a real line break (multiline sum)', () => {
|
||||
const input = '1\n2\n4';
|
||||
const result = compute(input, 'delimiter', false, '\\n');
|
||||
expect(result).toBe('7');
|
||||
});
|
||||
|
||||
it('should return running sum with a literal \\n separator', () => {
|
||||
const input = '1\n2\n4';
|
||||
const result = compute(input, 'delimiter', true, '\\n');
|
||||
expect(result).toBe('1\n3\n7\n');
|
||||
});
|
||||
});
|
||||
@@ -4,11 +4,15 @@ import { ToolComponentProps } from '@tools/defineTool';
|
||||
import ToolTextInput from '@components/input/ToolTextInput';
|
||||
import ToolTextResult from '@components/result/ToolTextResult';
|
||||
import { CardExampleType } from '@components/examples/ToolExamples';
|
||||
import { GetGroupsType } from '@components/options/ToolOptions';
|
||||
import CheckboxWithDesc from '@components/options/CheckboxWithDesc';
|
||||
import { beautifyXml } from './service';
|
||||
import { InitialValuesType } from './types';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
const initialValues: InitialValuesType = {};
|
||||
const initialValues: InitialValuesType = {
|
||||
preserveAttributes: true
|
||||
};
|
||||
|
||||
const exampleCards: CardExampleType<InitialValuesType>[] = [
|
||||
{
|
||||
@@ -16,22 +20,37 @@ const exampleCards: CardExampleType<InitialValuesType>[] = [
|
||||
description: 'Beautify a compact XML string for readability.',
|
||||
sampleText: '<root><item>1</item><item>2</item></root>',
|
||||
sampleResult: `<root>\n <item>1</item>\n <item>2</item>\n</root>`,
|
||||
sampleOptions: {}
|
||||
sampleOptions: { preserveAttributes: true }
|
||||
}
|
||||
];
|
||||
|
||||
export default function XmlBeautifier({
|
||||
title,
|
||||
longDescription
|
||||
}: ToolComponentProps) {
|
||||
export default function XmlBeautifier({ title }: ToolComponentProps) {
|
||||
const { t } = useTranslation('xml');
|
||||
const [input, setInput] = useState<string>('');
|
||||
const [result, setResult] = useState<string>('');
|
||||
|
||||
const compute = (_values: InitialValuesType, input: string) => {
|
||||
setResult(beautifyXml(input, {}));
|
||||
const compute = (values: InitialValuesType, input: string) => {
|
||||
if (!input || input.trim() == '') return;
|
||||
setResult(beautifyXml(input, values));
|
||||
};
|
||||
|
||||
const getGroups: GetGroupsType<InitialValuesType> | null = ({
|
||||
values,
|
||||
updateField
|
||||
}) => [
|
||||
{
|
||||
title: t('xmlBeautifier.options.title'),
|
||||
component: (
|
||||
<CheckboxWithDesc
|
||||
checked={values.preserveAttributes}
|
||||
onChange={(value) => updateField('preserveAttributes', value)}
|
||||
title={t('xmlBeautifier.options.preserveAttributesTitle')}
|
||||
description={t('xmlBeautifier.options.preserveAttributesDesc')}
|
||||
/>
|
||||
)
|
||||
}
|
||||
];
|
||||
|
||||
return (
|
||||
<ToolContent
|
||||
title={title}
|
||||
@@ -52,12 +71,12 @@ export default function XmlBeautifier({
|
||||
}
|
||||
initialValues={initialValues}
|
||||
exampleCards={exampleCards}
|
||||
getGroups={null}
|
||||
getGroups={getGroups}
|
||||
setInput={setInput}
|
||||
compute={compute}
|
||||
toolInfo={{
|
||||
title: t('xmlBeautifier.toolInfo.title', { title }),
|
||||
description: longDescription
|
||||
title: t('xmlBeautifier.toolInfo.title'),
|
||||
description: t('xmlBeautifier.toolInfo.description')
|
||||
}}
|
||||
/>
|
||||
);
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
import { InitialValuesType } from './types';
|
||||
import { XMLParser, XMLBuilder, XMLValidator } from 'fast-xml-parser';
|
||||
|
||||
export function beautifyXml(
|
||||
input: string,
|
||||
_options: InitialValuesType
|
||||
): string {
|
||||
export function beautifyXml(input: string, options: InitialValuesType): string {
|
||||
const valid = XMLValidator.validate(input);
|
||||
if (valid !== true) {
|
||||
if (typeof valid === 'object' && valid.err) {
|
||||
@@ -12,10 +9,16 @@ export function beautifyXml(
|
||||
}
|
||||
return 'Invalid XML';
|
||||
}
|
||||
|
||||
const { preserveAttributes } = options;
|
||||
try {
|
||||
const parser = new XMLParser();
|
||||
const parser = new XMLParser({ ignoreAttributes: !preserveAttributes });
|
||||
const obj = parser.parse(input);
|
||||
const builder = new XMLBuilder({ format: true, indentBy: ' ' });
|
||||
const builder = new XMLBuilder({
|
||||
format: true,
|
||||
indentBy: ' ',
|
||||
ignoreAttributes: !preserveAttributes
|
||||
});
|
||||
return builder.build(obj);
|
||||
} catch (e: any) {
|
||||
return `Invalid XML: ${e.message}`;
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export type InitialValuesType = {
|
||||
// splitSeparator: string;
|
||||
preserveAttributes: boolean;
|
||||
};
|
||||
@@ -4,15 +4,22 @@ import { beautifyXml } from './service';
|
||||
describe('xml-beautifier', () => {
|
||||
it('beautifies valid XML', () => {
|
||||
const input = '<root><a>1</a><b>2</b></root>';
|
||||
const result = beautifyXml(input, {});
|
||||
const result = beautifyXml(input, { preserveAttributes: true });
|
||||
expect(result).toContain('<root>');
|
||||
expect(result).toContain(' <a>1</a>');
|
||||
expect(result).toContain(' <b>2</b>');
|
||||
});
|
||||
|
||||
it('preserves attributes while beautifying XML', () => {
|
||||
const input = '<root><user id="42" role="admin">Alice</user></root>';
|
||||
const result = beautifyXml(input, { preserveAttributes: true });
|
||||
|
||||
expect(result).toContain('<user id="42" role="admin">Alice</user>');
|
||||
});
|
||||
|
||||
it('returns error for invalid XML', () => {
|
||||
const input = '<root><a>1</b></root>';
|
||||
const result = beautifyXml(input, {});
|
||||
const result = beautifyXml(input, { preserveAttributes: true });
|
||||
expect(result).toMatch(/Invalid XML/i);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user