pacc 6.1.1 → 6.2.0
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/package.json +1 -1
- package/src/module.mjs +1 -0
- package/src/time.mjs +27 -1
- package/src/types.mjs +3 -3
- package/types/module.d.mts +1 -0
- package/types/time.d.mts +7 -1
package/package.json
CHANGED
package/src/module.mjs
CHANGED
package/src/time.mjs
CHANGED
|
@@ -25,7 +25,7 @@ const units = {
|
|
|
25
25
|
* @param {number|string} value
|
|
26
26
|
* @returns {number} seconds
|
|
27
27
|
*/
|
|
28
|
-
export function
|
|
28
|
+
export function parseDuration(value) {
|
|
29
29
|
if (typeof value === "string") {
|
|
30
30
|
let seconds = 0;
|
|
31
31
|
|
|
@@ -44,3 +44,29 @@ export function parseTime(value) {
|
|
|
44
44
|
|
|
45
45
|
return value;
|
|
46
46
|
}
|
|
47
|
+
|
|
48
|
+
const durations = [
|
|
49
|
+
[604800, "w"],
|
|
50
|
+
[86400, "d"],
|
|
51
|
+
[3600, "h"],
|
|
52
|
+
[60, "m"],
|
|
53
|
+
[1, "s"]
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
*
|
|
58
|
+
* @param {number} seconds
|
|
59
|
+
* @returns {string} formatted duration
|
|
60
|
+
*/
|
|
61
|
+
export function formatDuration(seconds) {
|
|
62
|
+
const out = [];
|
|
63
|
+
for (const d of durations) {
|
|
64
|
+
const n = Math.floor(seconds / Number(d[0]));
|
|
65
|
+
if (n > 0) {
|
|
66
|
+
out.push(`${n}${d[1]}`);
|
|
67
|
+
seconds -= n * Number(d[0]);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return out.join(" ");
|
|
72
|
+
}
|
package/src/types.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { attributeIterator } from "./attributes.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { parseDuration } from "./time.mjs";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @typedef {Object} Type
|
|
@@ -40,12 +40,12 @@ export const types = {
|
|
|
40
40
|
duration: {
|
|
41
41
|
name: "duration",
|
|
42
42
|
primitive: true,
|
|
43
|
-
prepareValue: value =>
|
|
43
|
+
prepareValue: value => parseDuration(value)
|
|
44
44
|
},
|
|
45
45
|
duration_ms: {
|
|
46
46
|
name: "duration_ms",
|
|
47
47
|
primitive: true,
|
|
48
|
-
prepareValue: value =>
|
|
48
|
+
prepareValue: value => parseDuration(value) * 1000
|
|
49
49
|
},
|
|
50
50
|
url: {
|
|
51
51
|
name: "url",
|
package/types/module.d.mts
CHANGED
package/types/time.d.mts
CHANGED
|
@@ -3,4 +3,10 @@
|
|
|
3
3
|
* @param {number|string} value
|
|
4
4
|
* @returns {number} seconds
|
|
5
5
|
*/
|
|
6
|
-
export function
|
|
6
|
+
export function parseDuration(value: number | string): number;
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @param {number} seconds
|
|
10
|
+
* @returns {string} formatted duration
|
|
11
|
+
*/
|
|
12
|
+
export function formatDuration(seconds: number): string;
|