Compare commits

...
Author SHA1 Message Date
renovate[bot] 4676066313 fix(deps): update dependency figue to v3 2026-11-20 23:32:12 +00:00
ShareVB d07563cf5e fix: update nginx for CVE
Fix #600
2026-11-19 09:59:15 +01:00
ShareVB cf6df4e9f3 ci: fix e2e 2026-11-15 23:06:50 +01:00
JoAdo07 91ee2ab7a8 fix(percentage-calculator): clear the result when an input is cleared
n-input-number emits null when its text is cleared, while the computeds only
treated undefined as a missing value. The arithmetic then coerced null to 0,
so emptying To showed -100 and emptying X showed 0.

The three formulas moved into a service that treats null and undefined alike,
with unit tests for the cleared cases and an e2e case that clears a filled
field.

Fixes #1906
2026-11-15 23:03:42 +01:00
9 changed files with 160 additions and 60 deletions

No files matched your search

+1 -1
View File
@@ -26,7 +26,7 @@ RUN pnpm build \
-exec gzip -9 -n -k {} +
# production stage
FROM nginxinc/nginx-unprivileged:stable-alpine@sha256:f5116ed4606f3eb015dd4a8e28cb9b351476dc0ad4bc6e9f93b19cec130cdf03 AS production-stage
FROM nginx/nginx-unprivileged:alpine AS production-stage
LABEL maintainer="ShareVB <sharevb@gmail.com>" \
org.opencontainers.image.authors="ShareVB <sharevb@gmail.com>"
+1 -1
View File
@@ -205,7 +205,7 @@
"fast_array_intersect": "^1.1.0",
"fflate": "^0.8.3",
"figlet": "^1.11.0",
"figue": "^1.2.0",
"figue": "^3.0.0",
"file-type": "^22.0.1",
"flatten-anything": "^4.0.2",
"flexsearch": "^0.8.212",
+36 -36
View File
@@ -693,8 +693,8 @@ importers:
specifier: ^1.11.0
version: 1.11.0
figue:
specifier: ^1.2.0
version: 1.2.0
specifier: ^3.0.0
version: 3.3.0
file-type:
specifier: ^22.0.1
version: 22.0.1(supports-color@8.1.1)
@@ -1466,7 +1466,7 @@ importers:
version: 4.6.7
node:
specifier: runtime:24.x
version: runtime:24.21.0
version: runtime:24.22.3
oxfmt:
specifier: ^0.57.0
version: 0.57.0(svelte@5.56.4(@typescript-eslint/types@8.62.1))
@@ -7270,8 +7270,8 @@ packages:
engines: {node: '>= 17.0.0'}
hasBin: true
figue@1.2.0:
resolution: {integrity: sha512-CXKr12kiNWjKtUK3X+YHeXKepn80s9Rg6pgZXoLQYEybgwaGJ9uGW4DrBrVK30ZWZf1mcvTbXF56AcovG7gLVw==}
figue@3.3.0:
resolution: {integrity: sha512-1iLhSecjG23Q0gOeqFEbWSnmeNQRNG+bHKaRuqOmN+HZgPId1A0TAZatxUbznswujkEzhOeOwF2KEKSpMk8MOw==}
file-entry-cache@8.0.0:
resolution: {integrity: sha512-XXTUwCvisa5oacNGRP9SfNtYBNAMi+RPwBFmblZEF7N7swHYQS6/Zfk7SRwx4D5j3CH211YNRco1DEMNVfZCnQ==}
@@ -9216,7 +9216,7 @@ packages:
resolution: {integrity: sha512-X75ZN8DCLftGM5iKwoYLA3rjnrAEs97MkzvSd4q2746Tgpg8b8XWiBGiBG4ZpgcAqBgtgPHTiAc8ZMCvZuikDw==}
engines: {node: '>=10'}
node@runtime:24.21.0:
node@runtime:24.22.3:
resolution:
type: variations
variants:
@@ -9224,9 +9224,9 @@ packages:
archive: tarball
bin:
node: bin/node
integrity: sha256-rseyRkr7mfB4wZywbSAdVDvTsxHLoHEoK84bF8l+WLs=
integrity: sha256-aT/ojEqF5+Fy7BMvdg5ns5JbLWRCyxyzp0tz/Pgx9wo=
type: binary
url: https://nodejs.org/download/release/v24.21.0/node-v24.21.0-aix-ppc64.tar.gz
url: https://nodejs.org/download/release/v24.22.3/node-v24.22.3-aix-ppc64.tar.gz
targets:
- cpu: ppc64
os: aix
@@ -9234,9 +9234,9 @@ packages:
archive: tarball
bin:
node: bin/node
integrity: sha256-vtfupTJeEQjzLOUijd1qXw8IpJnuQqp0Qq6lg3AvYFc=
integrity: sha256-/24X1IdLdtJyISuQjMAg1ugV+6Wmx+qqBq3XJYQDB/0=
type: binary
url: https://nodejs.org/download/release/v24.21.0/node-v24.21.0-darwin-arm64.tar.gz
url: https://nodejs.org/download/release/v24.22.3/node-v24.22.3-darwin-arm64.tar.gz
targets:
- cpu: arm64
os: darwin
@@ -9244,9 +9244,9 @@ packages:
archive: tarball
bin:
node: bin/node
integrity: sha256-FGLLOzBGuBXPjqQ209pFDsGp8R2sflpGsK2lMF1+gJc=
integrity: sha256-l3YUrwUEyBBF5/2FWW28oOX5UblmgVFtra/tzKjER/c=
type: binary
url: https://nodejs.org/download/release/v24.21.0/node-v24.21.0-darwin-x64.tar.gz
url: https://nodejs.org/download/release/v24.22.3/node-v24.22.3-darwin-x64.tar.gz
targets:
- cpu: x64
os: darwin
@@ -9254,9 +9254,9 @@ packages:
archive: tarball
bin:
node: bin/node
integrity: sha256-ckKCw7Q67JmKqVJzgEZbRdIp4CG1gDX19PYwleq/5dU=
integrity: sha256-JhryryUN/X6fJc8VHRsnE6Ct+PEKmtEWxJR/aGJ6/+g=
type: binary
url: https://nodejs.org/download/release/v24.21.0/node-v24.21.0-linux-arm64.tar.gz
url: https://nodejs.org/download/release/v24.22.3/node-v24.22.3-linux-arm64.tar.gz
targets:
- cpu: arm64
os: linux
@@ -9264,9 +9264,9 @@ packages:
archive: tarball
bin:
node: bin/node
integrity: sha256-UcXVMGbukpILYXg7A7Buy5nzZhFg97Fcp36EdBFaZ7w=
integrity: sha256-uksmreH3s/W6Z1aFaBXeWONTdGAE5+RsyDgkOmy/Mpk=
type: binary
url: https://nodejs.org/download/release/v24.21.0/node-v24.21.0-linux-ppc64le.tar.gz
url: https://nodejs.org/download/release/v24.22.3/node-v24.22.3-linux-ppc64le.tar.gz
targets:
- cpu: ppc64le
os: linux
@@ -9274,9 +9274,9 @@ packages:
archive: tarball
bin:
node: bin/node
integrity: sha256-Xy+jdCLgx13jXBaG/lHXgyTywqj+LMI5pB2cAAop2Tg=
integrity: sha256-2PhDl8FHjA7QwbKTQ2Ju0PXxoJhd8MWXXDDwwDg2Yx8=
type: binary
url: https://nodejs.org/download/release/v24.21.0/node-v24.21.0-linux-s390x.tar.gz
url: https://nodejs.org/download/release/v24.22.3/node-v24.22.3-linux-s390x.tar.gz
targets:
- cpu: s390x
os: linux
@@ -9284,9 +9284,9 @@ packages:
archive: tarball
bin:
node: bin/node
integrity: sha256-PWNAX8ZaDS0pdsHwvC/Se7C9ByEkaecFqsPwOuWrTJw=
integrity: sha256-VJm2Y/Yscgk3FdqY9K6m+DQnrYurnPnHXwkk4ORWzhQ=
type: binary
url: https://nodejs.org/download/release/v24.21.0/node-v24.21.0-linux-x64-musl.tar.gz
url: https://nodejs.org/download/release/v24.22.3/node-v24.22.3-linux-x64-musl.tar.gz
targets:
- cpu: x64
os: linux
@@ -9295,9 +9295,9 @@ packages:
archive: tarball
bin:
node: bin/node
integrity: sha256-bh24fvWLiBnl1UAu/xU2SRsY7djre+5e94l4duiNxf8=
integrity: sha256-Bh7D4wYhFXBbVrUfqcwzCrUNNLaWk4fU5LGlDGgJrMI=
type: binary
url: https://nodejs.org/download/release/v24.21.0/node-v24.21.0-linux-x64.tar.gz
url: https://nodejs.org/download/release/v24.22.3/node-v24.22.3-linux-x64.tar.gz
targets:
- cpu: x64
os: linux
@@ -9305,10 +9305,10 @@ packages:
archive: zip
bin:
node: node.exe
integrity: sha256-h3mxveHTn41CDjtXqmV7OYka9DTT3kSpGQRM7AZ4WSE=
prefix: node-v24.21.0-win-arm64
integrity: sha256-s8x0opWznU8nMnHpb1jAbdKzV1fKEqvsZMfQWYtDTxQ=
prefix: node-v24.22.3-win-arm64
type: binary
url: https://nodejs.org/download/release/v24.21.0/node-v24.21.0-win-arm64.zip
url: https://nodejs.org/download/release/v24.22.3/node-v24.22.3-win-arm64.zip
targets:
- cpu: arm64
os: win32
@@ -9316,10 +9316,10 @@ packages:
archive: zip
bin:
node: node.exe
integrity: sha256-FY92hbRN5R9sDfHRU1JsvNPhvHOajfxgdyHO913p5UE=
prefix: node-v24.21.0-win-x64
integrity: sha256-5hKvmfYmq0FeoiWva85clx/rRIy1yuJQuxw/pQxffZ8=
prefix: node-v24.22.3-win-x64
type: binary
url: https://nodejs.org/download/release/v24.21.0/node-v24.21.0-win-x64.zip
url: https://nodejs.org/download/release/v24.22.3/node-v24.22.3-win-x64.zip
targets:
- cpu: x64
os: win32
@@ -9327,9 +9327,9 @@ packages:
archive: tarball
bin:
node: bin/node
integrity: sha256-MEiwgR4VjKDYZytZyDmGF2PhREkpgNjSmzad/uRXR+Q=
integrity: sha256-JIyWqE9sgzhka5/XO/ElEkZ4+PsI218jAj9GIFXg7tw=
type: binary
url: https://unofficial-builds.nodejs.org/download/release/v24.21.0/node-v24.21.0-linux-arm64-musl.tar.gz
url: https://unofficial-builds.nodejs.org/download/release/v24.22.3/node-v24.22.3-linux-arm64-musl.tar.gz
targets:
- cpu: arm64
os: linux
@@ -9338,14 +9338,14 @@ packages:
archive: tarball
bin:
node: bin/node
integrity: sha256-AacT402pjntNKjGR7nyj+T3QOE0aLvI8N5shYe5uEzo=
integrity: sha256-LbT4pAq+X1tdEZlkIj/tycTHxefGMpAa6GCvUix4RLI=
type: binary
url: https://unofficial-builds.nodejs.org/download/release/v24.21.0/node-v24.21.0-linux-x64-musl.tar.gz
url: https://unofficial-builds.nodejs.org/download/release/v24.22.3/node-v24.22.3-linux-x64-musl.tar.gz
targets:
- cpu: x64
os: linux
libc: musl
version: 24.21.0
version: 24.22.3
hasBin: true
nodemailer@9.0.1:
@@ -18218,9 +18218,9 @@ snapshots:
dependencies:
commander: 14.0.3
figue@1.2.0:
figue@3.3.0:
dependencies:
lodash: 4.18.1
'@standard-schema/spec': 1.1.0
file-entry-cache@8.0.0:
dependencies:
@@ -20290,7 +20290,7 @@ snapshots:
util: 0.12.5
vm-browserify: 1.1.2
node@runtime:24.21.0: {}
node@runtime:24.22.3: {}
nodemailer@9.0.1: {}
@@ -58,7 +58,7 @@ test.describe('Tool - Paste image', () => {
});
test('Has title', async ({ page }) => {
await expect(page).toHaveTitle('Paste image - Toolbox');
await expect(page).toHaveTitle('Paste Image - IT Tools');
});
test('A pasted image is added to the history and can be downloaded', async ({ page }) => {
@@ -33,4 +33,22 @@ test.describe('Tool - Percentage calculator', () => {
await page.getByTestId('numberFrom').locator('input').pressSequentially('123\n');
await expect(page.getByTestId('percentageIncreaseDecrease').locator('input')).toHaveValue('');
});
test('Displays empty results after an input is cleared', async ({ page }) => {
await page.getByTestId('percentageX').locator('input').pressSequentially('40\n');
await page.getByTestId('percentageY').locator('input').pressSequentially('50\n');
await expect(page.getByTestId('percentageResult').locator('input')).toHaveValue('20');
await page.getByTestId('numberFrom').locator('input').pressSequentially('40\n');
await page.getByTestId('numberTo').locator('input').pressSequentially('46\n');
await expect(page.getByTestId('percentageIncreaseDecrease').locator('input')).toHaveValue('15');
await page.getByTestId('percentageY').locator('input').clear();
await page.getByTestId('numberTo').locator('input').clear();
await page.getByTestId('percentageX').locator('input').clear();
await page.getByTestId('numberFrom').locator('input').clear();
await expect(page.getByTestId('percentageResult').locator('input')).toHaveValue('');
await expect(page.getByTestId('percentageIncreaseDecrease').locator('input')).toHaveValue('');
});
});
@@ -0,0 +1,58 @@
import { describe, expect, it } from 'vitest';
import {
computeIsWhatPercentOf,
computePercentageIncreaseDecrease,
computePercentageOf,
} from './percentage-calculator.service';
describe('percentage-calculator', () => {
describe('computePercentageOf', () => {
it('computes a percentage of a value', () => {
expect(computePercentageOf(123, 456)).toBe('560.88');
expect(computePercentageOf(0, 200)).toBe('0');
});
it('returns an empty result when an input is missing', () => {
expect(computePercentageOf(undefined, 200)).toBe('');
expect(computePercentageOf(200, undefined)).toBe('');
expect(computePercentageOf(null, 200)).toBe('');
expect(computePercentageOf(200, null)).toBe('');
});
});
describe('computeIsWhatPercentOf', () => {
it('computes what percent x is of y', () => {
expect(computeIsWhatPercentOf(123, 456)).toBe('26.973684210526315');
});
it('returns an empty result when an input is missing', () => {
expect(computeIsWhatPercentOf(undefined, 12)).toBe('');
expect(computeIsWhatPercentOf(12, undefined)).toBe('');
expect(computeIsWhatPercentOf(null, 12)).toBe('');
expect(computeIsWhatPercentOf(12, null)).toBe('');
});
it('returns an empty result when the divisor is zero', () => {
expect(computeIsWhatPercentOf(12, 0)).toBe('');
});
});
describe('computePercentageIncreaseDecrease', () => {
it('computes the increase and the decrease', () => {
expect(computePercentageIncreaseDecrease(123, 456)).toBe('270.7317073170732');
expect(computePercentageIncreaseDecrease(40, 46)).toBe('15');
expect(computePercentageIncreaseDecrease(46, 40)).toBe('-13.043478260869565');
});
it('returns an empty result when an input is missing', () => {
expect(computePercentageIncreaseDecrease(undefined, 46)).toBe('');
expect(computePercentageIncreaseDecrease(40, undefined)).toBe('');
expect(computePercentageIncreaseDecrease(null, 46)).toBe('');
expect(computePercentageIncreaseDecrease(40, null)).toBe('');
});
it('returns an empty result when the reference value is zero', () => {
expect(computePercentageIncreaseDecrease(0, 46)).toBe('');
});
});
});
@@ -0,0 +1,35 @@
export type PercentageInput = number | null | undefined;
export { computePercentageOf, computeIsWhatPercentOf, computePercentageIncreaseDecrease };
function isMissing(value: PercentageInput): value is null | undefined {
return value === null || value === undefined;
}
function formatFinite(value: number): string {
return Number.isFinite(value) ? value.toString() : '';
}
function computePercentageOf(x: PercentageInput, y: PercentageInput): string {
if (isMissing(x) || isMissing(y)) {
return '';
}
return formatFinite((x / 100) * y);
}
function computeIsWhatPercentOf(x: PercentageInput, y: PercentageInput): string {
if (isMissing(x) || isMissing(y)) {
return '';
}
return formatFinite((100 * x) / y);
}
function computePercentageIncreaseDecrease(from: PercentageInput, to: PercentageInput): string {
if (isMissing(from) || isMissing(to)) {
return '';
}
return formatFinite(((to - from) / from) * 100);
}
@@ -1,35 +1,24 @@
<script setup lang="ts">
import { useI18n } from 'vue-i18n';
import {
computeIsWhatPercentOf,
computePercentageIncreaseDecrease,
computePercentageOf,
} from './percentage-calculator.service';
const { t } = useI18n();
const percentageX = ref();
const percentageY = ref();
const percentageResult = computed(() => {
if (percentageX.value === undefined || percentageY.value === undefined) {
return '';
}
return ((percentageX.value / 100) * percentageY.value).toString();
});
const percentageResult = computed(() => computePercentageOf(percentageX.value, percentageY.value));
const numberX = ref();
const numberY = ref();
const numberResult = computed(() => {
if (numberX.value === undefined || numberY.value === undefined) {
return '';
}
const result = (100 * numberX.value) / numberY.value;
return !Number.isFinite(result) || Number.isNaN(result) ? '' : result.toString();
});
const numberResult = computed(() => computeIsWhatPercentOf(numberX.value, numberY.value));
const numberFrom = ref();
const numberTo = ref();
const percentageIncreaseDecrease = computed(() => {
if (numberFrom.value === undefined || numberTo.value === undefined) {
return '';
}
const result = ((numberTo.value - numberFrom.value) / numberFrom.value) * 100;
return !Number.isFinite(result) || Number.isNaN(result) ? '' : result.toString();
});
const percentageIncreaseDecrease = computed(() => computePercentageIncreaseDecrease(numberFrom.value, numberTo.value));
</script>
<template>
@@ -32,7 +32,7 @@ test.describe('Tool - Whitespace cleaner', () => {
});
test('Has correct title', async ({ page }) => {
await expect(page).toHaveTitle('Whitespace cleaner - Toolbox');
await expect(page).toHaveTitle('Whitespace Cleaner - IT Tools');
});
test('U1 updates the output on input with no button press', async ({ page }) => {