@vaibhavt07/pace-utils 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +34 -0
- package/dist/index.cjs +52 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +27 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.mjs +49 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +67 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Vaibhav Tyagi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# @vaibhavt07/pace-utils
|
|
2
|
+
|
|
3
|
+
Tiny utilities for formatting running pace and duration. Zero dependencies. ESM + CJS + TypeScript types.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @vaibhavt07/pace-utils
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { formatPace, formatDuration } from '@vaibhavt07/pace-utils'
|
|
15
|
+
|
|
16
|
+
formatPace(330) // "5:30 /km"
|
|
17
|
+
formatDuration(5025) // "1h 23m 45s"
|
|
18
|
+
formatDuration(125) // "2m 5s"
|
|
19
|
+
formatDuration(30) // "30s"
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## API
|
|
23
|
+
|
|
24
|
+
### `formatPace(secondsPerKm: number): string`
|
|
25
|
+
|
|
26
|
+
Formats a pace value (seconds per kilometer) as a runner-friendly string. Throws `RangeError` on negative or non-finite input.
|
|
27
|
+
|
|
28
|
+
### `formatDuration(seconds: number): string`
|
|
29
|
+
|
|
30
|
+
Formats a duration (in seconds) as a human-readable string. Omits leading zero units. Throws `RangeError` on negative or non-finite input.
|
|
31
|
+
|
|
32
|
+
## License
|
|
33
|
+
|
|
34
|
+
MIT © [Vaibhav Tyagi](https://vaibhavt07.com)
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Format a pace value (seconds per kilometer) as a runner-friendly string.
|
|
5
|
+
*
|
|
6
|
+
* @param secondsPerKm - Pace in seconds per kilometer. Must be a non-negative finite number.
|
|
7
|
+
* @returns Formatted string like `"5:30 /km"`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* formatPace(330) // "5:30 /km"
|
|
11
|
+
* formatPace(285) // "4:45 /km"
|
|
12
|
+
*/
|
|
13
|
+
function formatPace(secondsPerKm) {
|
|
14
|
+
if (!Number.isFinite(secondsPerKm) || secondsPerKm < 0) {
|
|
15
|
+
throw new RangeError(`secondsPerKm must be a non-negative finite number, received: ${secondsPerKm}`);
|
|
16
|
+
}
|
|
17
|
+
const total = Math.round(secondsPerKm);
|
|
18
|
+
const minutes = Math.floor(total / 60);
|
|
19
|
+
const seconds = total % 60;
|
|
20
|
+
return `${minutes}:${seconds.toString().padStart(2, '0')} /km`;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Format a duration (in seconds) as a human-readable string.
|
|
24
|
+
*
|
|
25
|
+
* Always emits the largest non-zero unit and everything below it down to seconds.
|
|
26
|
+
*
|
|
27
|
+
* @param seconds - Duration in seconds. Must be a non-negative finite number.
|
|
28
|
+
* @returns Formatted string like `"1h 23m 45s"`, `"2m 5s"`, or `"30s"`.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* formatDuration(5025) // "1h 23m 45s"
|
|
32
|
+
* formatDuration(125) // "2m 5s"
|
|
33
|
+
* formatDuration(30) // "30s"
|
|
34
|
+
*/
|
|
35
|
+
function formatDuration(seconds) {
|
|
36
|
+
if (!Number.isFinite(seconds) || seconds < 0) {
|
|
37
|
+
throw new RangeError(`seconds must be a non-negative finite number, received: ${seconds}`);
|
|
38
|
+
}
|
|
39
|
+
const total = Math.round(seconds);
|
|
40
|
+
const h = Math.floor(total / 3600);
|
|
41
|
+
const m = Math.floor((total % 3600) / 60);
|
|
42
|
+
const s = total % 60;
|
|
43
|
+
if (h > 0)
|
|
44
|
+
return `${h}h ${m}m ${s}s`;
|
|
45
|
+
if (m > 0)
|
|
46
|
+
return `${m}m ${s}s`;
|
|
47
|
+
return `${s}s`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
exports.formatDuration = formatDuration;
|
|
51
|
+
exports.formatPace = formatPace;
|
|
52
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index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,CAAC;AAAE,QAAA,OAAO,CAAA,EAAG,CAAC,CAAA,EAAA,EAAK,CAAC,GAAG;IAC/B,OAAO,CAAA,EAAG,CAAC,CAAA,CAAA,CAAG;AAChB;;;;;"}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Format a pace value (seconds per kilometer) as a runner-friendly string.
|
|
3
|
+
*
|
|
4
|
+
* @param secondsPerKm - Pace in seconds per kilometer. Must be a non-negative finite number.
|
|
5
|
+
* @returns Formatted string like `"5:30 /km"`.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* formatPace(330) // "5:30 /km"
|
|
9
|
+
* formatPace(285) // "4:45 /km"
|
|
10
|
+
*/
|
|
11
|
+
declare function formatPace(secondsPerKm: number): string;
|
|
12
|
+
/**
|
|
13
|
+
* Format a duration (in seconds) as a human-readable string.
|
|
14
|
+
*
|
|
15
|
+
* Always emits the largest non-zero unit and everything below it down to seconds.
|
|
16
|
+
*
|
|
17
|
+
* @param seconds - Duration in seconds. Must be a non-negative finite number.
|
|
18
|
+
* @returns Formatted string like `"1h 23m 45s"`, `"2m 5s"`, or `"30s"`.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* formatDuration(5025) // "1h 23m 45s"
|
|
22
|
+
* formatDuration(125) // "2m 5s"
|
|
23
|
+
* formatDuration(30) // "30s"
|
|
24
|
+
*/
|
|
25
|
+
declare function formatDuration(seconds: number): string;
|
|
26
|
+
|
|
27
|
+
export { formatDuration, formatPace };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Format a pace value (seconds per kilometer) as a runner-friendly string.
|
|
3
|
+
*
|
|
4
|
+
* @param secondsPerKm - Pace in seconds per kilometer. Must be a non-negative finite number.
|
|
5
|
+
* @returns Formatted string like `"5:30 /km"`.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* formatPace(330) // "5:30 /km"
|
|
9
|
+
* formatPace(285) // "4:45 /km"
|
|
10
|
+
*/
|
|
11
|
+
declare function formatPace(secondsPerKm: number): string;
|
|
12
|
+
/**
|
|
13
|
+
* Format a duration (in seconds) as a human-readable string.
|
|
14
|
+
*
|
|
15
|
+
* Always emits the largest non-zero unit and everything below it down to seconds.
|
|
16
|
+
*
|
|
17
|
+
* @param seconds - Duration in seconds. Must be a non-negative finite number.
|
|
18
|
+
* @returns Formatted string like `"1h 23m 45s"`, `"2m 5s"`, or `"30s"`.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* formatDuration(5025) // "1h 23m 45s"
|
|
22
|
+
* formatDuration(125) // "2m 5s"
|
|
23
|
+
* formatDuration(30) // "30s"
|
|
24
|
+
*/
|
|
25
|
+
declare function formatDuration(seconds: number): string;
|
|
26
|
+
|
|
27
|
+
export { formatDuration, formatPace };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Format a pace value (seconds per kilometer) as a runner-friendly string.
|
|
3
|
+
*
|
|
4
|
+
* @param secondsPerKm - Pace in seconds per kilometer. Must be a non-negative finite number.
|
|
5
|
+
* @returns Formatted string like `"5:30 /km"`.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* formatPace(330) // "5:30 /km"
|
|
9
|
+
* formatPace(285) // "4:45 /km"
|
|
10
|
+
*/
|
|
11
|
+
function formatPace(secondsPerKm) {
|
|
12
|
+
if (!Number.isFinite(secondsPerKm) || secondsPerKm < 0) {
|
|
13
|
+
throw new RangeError(`secondsPerKm must be a non-negative finite number, received: ${secondsPerKm}`);
|
|
14
|
+
}
|
|
15
|
+
const total = Math.round(secondsPerKm);
|
|
16
|
+
const minutes = Math.floor(total / 60);
|
|
17
|
+
const seconds = total % 60;
|
|
18
|
+
return `${minutes}:${seconds.toString().padStart(2, '0')} /km`;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Format a duration (in seconds) as a human-readable string.
|
|
22
|
+
*
|
|
23
|
+
* Always emits the largest non-zero unit and everything below it down to seconds.
|
|
24
|
+
*
|
|
25
|
+
* @param seconds - Duration in seconds. Must be a non-negative finite number.
|
|
26
|
+
* @returns Formatted string like `"1h 23m 45s"`, `"2m 5s"`, or `"30s"`.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* formatDuration(5025) // "1h 23m 45s"
|
|
30
|
+
* formatDuration(125) // "2m 5s"
|
|
31
|
+
* formatDuration(30) // "30s"
|
|
32
|
+
*/
|
|
33
|
+
function formatDuration(seconds) {
|
|
34
|
+
if (!Number.isFinite(seconds) || seconds < 0) {
|
|
35
|
+
throw new RangeError(`seconds must be a non-negative finite number, received: ${seconds}`);
|
|
36
|
+
}
|
|
37
|
+
const total = Math.round(seconds);
|
|
38
|
+
const h = Math.floor(total / 3600);
|
|
39
|
+
const m = Math.floor((total % 3600) / 60);
|
|
40
|
+
const s = total % 60;
|
|
41
|
+
if (h > 0)
|
|
42
|
+
return `${h}h ${m}m ${s}s`;
|
|
43
|
+
if (m > 0)
|
|
44
|
+
return `${m}m ${s}s`;
|
|
45
|
+
return `${s}s`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { formatDuration, formatPace };
|
|
49
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/index.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAA;;;;;;;;;AASG;AACG,SAAU,UAAU,CAAC,YAAoB,EAAA;AAC7C,IAAA,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,YAAY,GAAG,CAAC,EAAE;AACtD,QAAA,MAAM,IAAI,UAAU,CAClB,gEAAgE,YAAY,CAAA,CAAE,CAC/E;IACH;IAEA,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC;IACtC,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,EAAE,CAAC;AACtC,IAAA,MAAM,OAAO,GAAG,KAAK,GAAG,EAAE;AAE1B,IAAA,OAAO,CAAA,EAAG,OAAO,CAAA,CAAA,EAAI,OAAO,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,MAAM;AAChE;AAEA;;;;;;;;;;;;AAYG;AACG,SAAU,cAAc,CAAC,OAAe,EAAA;AAC5C,IAAA,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,OAAO,GAAG,CAAC,EAAE;AAC5C,QAAA,MAAM,IAAI,UAAU,CAClB,2DAA2D,OAAO,CAAA,CAAE,CACrE;IACH;IAEA,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;IACjC,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC;AAClC,IAAA,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,GAAG,IAAI,IAAI,EAAE,CAAC;AACzC,IAAA,MAAM,CAAC,GAAG,KAAK,GAAG,EAAE;IAEpB,IAAI,CAAC,GAAG,CAAC;AAAE,QAAA,OAAO,GAAG,CAAC,CAAA,EAAA,EAAK,CAAC,CAAA,EAAA,EAAK,CAAC,GAAG;IACrC,IAAI,CAAC,GAAG,CAAC;AAAE,QAAA,OAAO,CAAA,EAAG,CAAC,CAAA,EAAA,EAAK,CAAC,GAAG;IAC/B,OAAO,CAAA,EAAG,CAAC,CAAA,CAAA,CAAG;AAChB;;;;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vaibhavt07/pace-utils",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Tiny utilities for formatting running pace and duration.",
|
|
5
|
+
"keywords": ["running", "pace", "duration", "format", "strava", "fitness"],
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "Vaibhav Tyagi <vaibhavtyagi438@gmail.com> (https://vaibhavt07.com)",
|
|
8
|
+
"homepage": "https://github.com/mrtyagi07/pace-utils#readme",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/mrtyagi07/pace-utils.git"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/mrtyagi07/pace-utils/issues"
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
"type": "module",
|
|
18
|
+
"sideEffects": false,
|
|
19
|
+
|
|
20
|
+
"main": "./dist/index.cjs",
|
|
21
|
+
"module": "./dist/index.mjs",
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"import": {
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"default": "./dist/index.mjs"
|
|
28
|
+
},
|
|
29
|
+
"require": {
|
|
30
|
+
"types": "./dist/index.d.cts",
|
|
31
|
+
"default": "./dist/index.cjs"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"./package.json": "./package.json"
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
"files": [
|
|
38
|
+
"dist",
|
|
39
|
+
"README.md",
|
|
40
|
+
"LICENSE"
|
|
41
|
+
],
|
|
42
|
+
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": ">=18"
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public"
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
"scripts": {
|
|
52
|
+
"clean": "rm -rf dist",
|
|
53
|
+
"prebuild": "npm run clean",
|
|
54
|
+
"build": "rollup -c",
|
|
55
|
+
"typecheck": "tsc --noEmit",
|
|
56
|
+
"prepublishOnly": "npm run typecheck && npm run build"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@rollup/plugin-typescript": "^12.3.0",
|
|
60
|
+
"@types/node": "^25.9.1",
|
|
61
|
+
"rollup": "^4.60.4",
|
|
62
|
+
"rollup-plugin-dts": "^6.4.1",
|
|
63
|
+
"tslib": "^2.8.1",
|
|
64
|
+
"tsx": "^4.22.3",
|
|
65
|
+
"typescript": "^6.0.3"
|
|
66
|
+
}
|
|
67
|
+
}
|