feat(new tool): Running Pace Calculator

Fix #400 (and #413)
This commit is contained in:
ShareVB committed 2026-06-23 23:18:38 +02:00
1 parent 464e005afd
commit 93d4318884
6 files changed
+191 -1

No files matched your search

+3 -1
View File
@@ -317,6 +317,7 @@
"riimut": "^0.9.1",
"roboto-base64": "^0.1.2",
"rtf-stream-parser": "^3.8.1",
"run-pace": "^2.2.0",
"safe-license-list": "^0.1.2",
"sandybox": "^1.1.2",
"sanitize-html": "^2.17.0",
@@ -467,7 +468,8 @@
},
"patchedDependencies": {
"node-forge@1.4.0": "patches/node-forge@1.4.0.patch",
"esm-potrace-wasm": "patches/esm-potrace-wasm.patch"
"esm-potrace-wasm": "patches/esm-potrace-wasm.patch",
"run-pace": "patches/run-pace.patch"
}
},
"scarfSettings": {
+12
View File
@@ -0,0 +1,12 @@
diff --git a/lib/run-pace.js b/lib/run-pace.js
index 2b20a32ff4b5712016dd869a734ff25f730cdb12..9b9b72187e6675db6b295a827f2293950d12a111 100644
--- a/lib/run-pace.js
+++ b/lib/run-pace.js
@@ -119,7 +119,3 @@ function removeTrailingZeroes(number) {
function removeLeadingZero(number) {
return number.replace(/^0/, "");
}
-
-function zeroPad(number) {
- return `0${number}`.slice(-2);
-}
+12
View File
@@ -15,6 +15,9 @@ patchedDependencies:
node-forge@1.4.0:
hash: be4w4shpo4tldv77tcysxrioha
path: patches/node-forge@1.4.0.patch
run-pace:
hash: flfgxpnzx6iyo2pksk6djrkobe
path: patches/run-pace.patch
importers:
@@ -845,6 +848,9 @@ importers:
rtf-stream-parser:
specifier: ^3.8.1
version: 3.8.1
run-pace:
specifier: ^2.2.0
version: 2.2.0(patch_hash=flfgxpnzx6iyo2pksk6djrkobe)
safe-license-list:
specifier: ^0.1.2
version: 0.1.2
@@ -10146,6 +10152,10 @@ packages:
resolution: {integrity: sha512-DPe5pVFaAsinSaV6QjQ6gdiedWDcRCbUuiQfQa2wmWV7+xC9bGulGI8+TdRmoFkAPaBXk8CrAbnlY2ISniJ47Q==}
engines: {node: '>=18'}
run-pace@2.2.0:
resolution: {integrity: sha512-IeBogfkMIxyg97mxE+vbf71Iimda/+qAYgfqcn+JTXHJSb8efECyMWazlBE2Jrzgaxu8QHAKZbudPjyX+o+Cew==}
hasBin: true
run-parallel@1.2.0:
resolution: {integrity: sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==}
@@ -22190,6 +22200,8 @@ snapshots:
run-applescript@7.1.0: {}
run-pace@2.2.0(patch_hash=flfgxpnzx6iyo2pksk6djrkobe): {}
run-parallel@1.2.0:
dependencies:
queue-microtask: 1.2.3
@@ -0,0 +1,13 @@
import { Run } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'Running Pace Calculator',
path: '/running-pace-calculator',
description: 'Calculate your running pace, estimate your finish times for popular races, break down splits, and find your training zones.',
keywords: ['running', 'pace', 'calculator'],
component: () => import('./running-pace-calculator.vue'),
icon: Run,
createdAt: new Date('2026-06-21'),
category: 'Data',
});
+26
View File
@@ -0,0 +1,26 @@
declare module 'run-pace' {
export function calculatePace(options: {
time: string;
length: string;
imperial?: boolean;
metric?: boolean;
speed?: boolean;
}): string;
export function calculateLength(options: {
time: string;
pace: string;
imperial?: boolean;
metric?: boolean;
}): string;
export function calculateTime(options: {
length: string;
pace: string;
imperial?: boolean;
metric?: boolean;
}): string;
export function paceToSpeed(options: {
pace: string;
imperial?: boolean;
metric?: boolean;
}): string;
}
@@ -0,0 +1,125 @@
<script setup lang="ts">
import * as runPace from 'run-pace';
// Inputs
const length = ref<string>('');
const time = ref<string>('');
const pace = ref<string>('');
// Options
const unit = ref<'km' | 'mile'>('km');
const speed = ref<boolean>(false);
// Output
const result = ref<string>('');
const resultType = ref<string>('');
const error = ref<string>('');
function calculateStuff() {
result.value = '';
error.value = '';
const options: any = {
length: length.value,
time: time.value,
pace: pace.value,
};
// Unit selection
if (unit.value === 'km') {
options.metric = true;
}
if (unit.value === 'mile') {
options.imperial = true;
}
options.speed = speed.value;
try {
if (options.time && options.length && options.pace) {
throw new Error(
'Only two of "time", "length" and "pace" may be provided at any time',
);
}
else if (options.time && options.pace) {
if (options.speed) {
throw new Error('Speed is only valid when (only) pace is given or calculated');
}
resultType.value = 'Length';
result.value = `${runPace.calculateLength(options)}`;
}
else if (options.time && options.length) {
const label = options.speed ? 'Speed' : 'Pace';
resultType.value = label;
result.value = `${runPace.calculatePace(options)}`;
}
else if (options.pace && options.length) {
if (options.speed) {
throw new Error('Speed is only valid when (only) pace is given or calculated');
}
resultType.value = 'Time';
result.value = `${runPace.calculateTime(options)}`;
}
else if (options.pace && options.speed) {
resultType.value = 'Speed';
result.value = `${runPace.paceToSpeed(options)}`;
}
else {
throw new Error(
'Two of "time", "length" and "pace" must be provided.\nSpeed is only valid when pace is given or calculated.',
);
}
}
catch (e: any) {
error.value = e.message;
}
}
</script>
<template>
<div>
<NForm label-placement="left" label-width="70px">
<NFormItem label="Length:">
<NInput v-model:value="length" placeholder="e.g. 10km or 100m" clearable />
</NFormItem>
<NFormItem label="Time:">
<NInput v-model:value="time" placeholder="e.g. 45:00 or 45min or 1h30..." clearable />
</NFormItem>
<NFormItem label="Pace:">
<NInput v-model:value="pace" placeholder="e.g. 4:30/km" clearable />
</NFormItem>
<n-space justify="center">
<NFormItem label="Unit:">
<NRadioGroup v-model:value="unit">
<NRadio value="km">
km
</NRadio>
<NRadio value="mile">
mile
</NRadio>
</NRadioGroup>
</NFormItem>
<NFormItem label="Output speed in instead of pace:" label-width="auto">
<NSwitch v-model:value="speed" />
</NFormItem>
</n-space>
</NForm>
<n-space justify="center" mb-2>
<NButton type="primary" @click="calculateStuff">
Calculate
</NButton>
</n-space>
<c-alert v-if="error">
{{ error }}
</c-alert>
<c-card v-if="result" title="Result">
<input-copyable :label="`${resultType}:`" label-position="left" :value="result" />
</c-card>
</div>
</template>