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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pacc",
3
- "version": "6.1.1",
3
+ "version": "6.2.0",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
package/src/module.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./types.mjs";
2
+ export * from "./time.mjs";
2
3
  export * from "./attributes.mjs";
3
4
  export * from "./tokens.mjs";
4
5
  export * from "./filter.mjs";
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 parseTime(value) {
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 { parseTime } from "./time.mjs";
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 => parseTime(value)
43
+ prepareValue: value => parseDuration(value)
44
44
  },
45
45
  duration_ms: {
46
46
  name: "duration_ms",
47
47
  primitive: true,
48
- prepareValue: value => parseTime(value) * 1000
48
+ prepareValue: value => parseDuration(value) * 1000
49
49
  },
50
50
  url: {
51
51
  name: "url",
@@ -1,4 +1,5 @@
1
1
  export * from "./types.mjs";
2
+ export * from "./time.mjs";
2
3
  export * from "./attributes.mjs";
3
4
  export * from "./tokens.mjs";
4
5
  export * from "./filter.mjs";
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 parseTime(value: number | string): number;
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;