pacc 6.1.0 → 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/README.md CHANGED
@@ -63,7 +63,6 @@ const result = getAttribute({ a: [0,{ b: 4 }]}, "a[1].b");
63
63
  * [private\_key\_attribute](#private_key_attribute)
64
64
  * [public\_key\_attribute](#public_key_attribute)
65
65
  * [number\_attribute](#number_attribute)
66
- * [number\_attribute](#number_attribute-1)
67
66
  * [number\_attribute\_writable](#number_attribute_writable)
68
67
  * [integer\_attribute](#integer_attribute)
69
68
  * [integer\_attribute](#integer_attribute-1)
@@ -78,6 +77,8 @@ const result = getAttribute({ a: [0,{ b: 4 }]}, "a[1].b");
78
77
  * [id\_attribute](#id_attribute)
79
78
  * [title\_attribute\_writable](#title_attribute_writable)
80
79
  * [priority\_attribute](#priority_attribute)
80
+ * [duration\_attribute](#duration_attribute)
81
+ * [duration\_ms\_attribute](#duration_ms_attribute)
81
82
  * [timeout\_attribute](#timeout_attribute)
82
83
  * [language\_attribute](#language_attribute)
83
84
  * [environmentValues](#environmentvalues)
@@ -101,11 +102,13 @@ const result = getAttribute({ a: [0,{ b: 4 }]}, "a[1].b");
101
102
  * [Parameters](#parameters-11)
102
103
  * [getAttributeAndOperator](#getattributeandoperator)
103
104
  * [Parameters](#parameters-12)
105
+ * [parseTime](#parsetime)
106
+ * [Parameters](#parameters-13)
104
107
  * [lookup](#lookup)
105
108
  * [Token](#token)
106
109
  * [Properties](#properties-1)
107
110
  * [createToken](#createtoken)
108
- * [Parameters](#parameters-13)
111
+ * [Parameters](#parameters-14)
109
112
  * [PLUS](#plus)
110
113
  * [MINUS](#minus)
111
114
  * [STAR](#star)
@@ -317,10 +320,6 @@ Type: [AttributeDefinition](#attributedefinition)
317
320
 
318
321
  Type: [AttributeDefinition](#attributedefinition)
319
322
 
320
- ## number\_attribute
321
-
322
- Type: [AttributeDefinition](#attributedefinition)
323
-
324
323
  ## number\_attribute\_writable
325
324
 
326
325
  Type: [AttributeDefinition](#attributedefinition)
@@ -384,6 +383,14 @@ this defines the order.
384
383
 
385
384
  Type: [AttributeDefinition](#attributedefinition)
386
385
 
386
+ ## duration\_attribute
387
+
388
+ Type: [AttributeDefinition](#attributedefinition)
389
+
390
+ ## duration\_ms\_attribute
391
+
392
+ Type: [AttributeDefinition](#attributedefinition)
393
+
387
394
  ## timeout\_attribute
388
395
 
389
396
  Type: [AttributeDefinition](#attributedefinition)
@@ -511,6 +518,14 @@ The name may be a property path like 'a.b.c <='.
511
518
 
512
519
  Returns **\[any, [Token](#token)]** value associated with the given property name
513
520
 
521
+ ## parseTime
522
+
523
+ ### Parameters
524
+
525
+ * `value` **([number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number) | [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String))**&#x20;
526
+
527
+ Returns **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**&#x20;
528
+
514
529
  ## lookup
515
530
 
516
531
  Token lookup
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pacc",
3
- "version": "6.1.0",
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
@@ -1,18 +1,31 @@
1
1
  const units = {
2
2
  ms: 0.001,
3
+ millisecond: 0.001,
4
+ milliseconds: 0.001,
3
5
  s: 1,
6
+ second: 1,
7
+ seconds: 1,
4
8
  m: 60,
9
+ min: 60,
10
+ minute: 60,
11
+ minutes: 60,
5
12
  h: 3600,
13
+ hour: 3600,
14
+ hours: 3600,
6
15
  d: 86400,
7
- w: 604800
16
+ day: 86400,
17
+ days: 86400,
18
+ w: 604800,
19
+ week: 604800,
20
+ weeks: 604800
8
21
  };
9
22
 
10
23
  /**
11
- *
24
+ * Convert duration formatted string into number of seconds.
12
25
  * @param {number|string} value
13
- * @returns {number}
26
+ * @returns {number} seconds
14
27
  */
15
- export function parseTime(value) {
28
+ export function parseDuration(value) {
16
29
  if (typeof value === "string") {
17
30
  let seconds = 0;
18
31
 
@@ -31,3 +44,29 @@ export function parseTime(value) {
31
44
 
32
45
  return value;
33
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
@@ -1,6 +1,12 @@
1
1
  /**
2
- *
2
+ * Convert duration formatted string into number of seconds.
3
3
  * @param {number|string} value
4
- * @returns {number}
4
+ * @returns {number} seconds
5
+ */
6
+ export function parseDuration(value: number | string): number;
7
+ /**
8
+ *
9
+ * @param {number} seconds
10
+ * @returns {string} formatted duration
5
11
  */
6
- export function parseTime(value: number | string): number;
12
+ export function formatDuration(seconds: number): string;