diff --git a/README.md b/README.md index 1c04fa9c..4f7a69db 100644 --- a/README.md +++ b/README.md @@ -154,16 +154,16 @@ The translation files are [here](public/locales). Only edit these if you are a d | 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 | ## ⭐ Star History diff --git a/public/locales/en/xml.json b/public/locales/en/xml.json index 8acd4fcd..18b2e0a3 100644 --- a/public/locales/en/xml.json +++ b/public/locales/en/xml.json @@ -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" diff --git a/src/pages/tools/csv/csv-rows-to-columns/csv-rows-to-columns.service.test.ts b/src/pages/tools/csv/csv-rows-to-columns/csv-rows-to-columns.service.test.ts index 7faf0e7f..6cb849ea 100644 --- a/src/pages/tools/csv/csv-rows-to-columns/csv-rows-to-columns.service.test.ts +++ b/src/pages/tools/csv/csv-rows-to-columns/csv-rows-to-columns.service.test.ts @@ -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'); + }); }); diff --git a/src/pages/tools/csv/csv-rows-to-columns/service.ts b/src/pages/tools/csv/csv-rows-to-columns/service.ts index 614043fc..005fd643 100644 --- a/src/pages/tools/csv/csv-rows-to-columns/service.ts +++ b/src/pages/tools/csv/csv-rows-to-columns/service.ts @@ -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++) { diff --git a/src/pages/tools/image/generic/compress/compress.service.test.ts b/src/pages/tools/image/generic/compress/compress.service.test.ts new file mode 100644 index 00000000..fe374380 --- /dev/null +++ b/src/pages/tools/image/generic/compress/compress.service.test.ts @@ -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 }) + ); + }); +}); diff --git a/src/pages/tools/image/generic/compress/service.ts b/src/pages/tools/image/generic/compress/service.ts index 3b3afe80..6b6178e5 100644 --- a/src/pages/tools/image/generic/compress/service.ts +++ b/src/pages/tools/image/generic/compress/service.ts @@ -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 }; diff --git a/src/pages/tools/list/sort/service.ts b/src/pages/tools/list/sort/service.ts index f6fb5fa8..c6d2895c 100644 --- a/src/pages/tools/list/sort/service.ts +++ b/src/pages/tools/list/sort/service.ts @@ -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; } } diff --git a/src/pages/tools/list/sort/sort.service.test.ts b/src/pages/tools/list/sort/sort.service.test.ts index 3becba4d..d90afec1 100644 --- a/src/pages/tools/list/sort/sort.service.test.ts +++ b/src/pages/tools/list/sort/sort.service.test.ts @@ -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; diff --git a/src/pages/tools/number/sum/index.tsx b/src/pages/tools/number/sum/index.tsx index d649f995..08f0d1c2 100644 --- a/src/pages/tools/number/sum/index.tsx +++ b/src/pages/tools/number/sum/index.tsx @@ -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 ? ( 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(); }; diff --git a/src/pages/tools/number/sum/sum.service.test.ts b/src/pages/tools/number/sum/sum.service.test.ts index 944a28a9..c576fcb7 100644 --- a/src/pages/tools/number/sum/sum.service.test.ts +++ b/src/pages/tools/number/sum/sum.service.test.ts @@ -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'); + }); }); diff --git a/src/pages/tools/xml/xml-beautifier/index.tsx b/src/pages/tools/xml/xml-beautifier/index.tsx index c1adb57f..8a57fa00 100644 --- a/src/pages/tools/xml/xml-beautifier/index.tsx +++ b/src/pages/tools/xml/xml-beautifier/index.tsx @@ -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[] = [ { @@ -16,22 +20,37 @@ const exampleCards: CardExampleType[] = [ description: 'Beautify a compact XML string for readability.', sampleText: '12', sampleResult: `\n 1\n 2\n`, - 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(''); const [result, setResult] = useState(''); - 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 | null = ({ + values, + updateField + }) => [ + { + title: t('xmlBeautifier.options.title'), + component: ( + updateField('preserveAttributes', value)} + title={t('xmlBeautifier.options.preserveAttributesTitle')} + description={t('xmlBeautifier.options.preserveAttributesDesc')} + /> + ) + } + ]; + return ( ); diff --git a/src/pages/tools/xml/xml-beautifier/service.ts b/src/pages/tools/xml/xml-beautifier/service.ts index 8da42624..86259a55 100644 --- a/src/pages/tools/xml/xml-beautifier/service.ts +++ b/src/pages/tools/xml/xml-beautifier/service.ts @@ -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}`; diff --git a/src/pages/tools/xml/xml-beautifier/types.ts b/src/pages/tools/xml/xml-beautifier/types.ts index d4135c9c..1ee79584 100644 --- a/src/pages/tools/xml/xml-beautifier/types.ts +++ b/src/pages/tools/xml/xml-beautifier/types.ts @@ -1,3 +1,3 @@ export type InitialValuesType = { - // splitSeparator: string; + preserveAttributes: boolean; }; diff --git a/src/pages/tools/xml/xml-beautifier/xml-beautifier.service.test.ts b/src/pages/tools/xml/xml-beautifier/xml-beautifier.service.test.ts index e832bb81..70d93eab 100644 --- a/src/pages/tools/xml/xml-beautifier/xml-beautifier.service.test.ts +++ b/src/pages/tools/xml/xml-beautifier/xml-beautifier.service.test.ts @@ -4,15 +4,22 @@ import { beautifyXml } from './service'; describe('xml-beautifier', () => { it('beautifies valid XML', () => { const input = '12'; - const result = beautifyXml(input, {}); + const result = beautifyXml(input, { preserveAttributes: true }); expect(result).toContain(''); expect(result).toContain(' 1'); expect(result).toContain(' 2'); }); + it('preserves attributes while beautifying XML', () => { + const input = 'Alice'; + const result = beautifyXml(input, { preserveAttributes: true }); + + expect(result).toContain('Alice'); + }); + it('returns error for invalid XML', () => { const input = '1'; - const result = beautifyXml(input, {}); + const result = beautifyXml(input, { preserveAttributes: true }); expect(result).toMatch(/Invalid XML/i); }); });