pacc 5.2.0 → 5.3.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
@@ -8,7 +8,6 @@
8
8
  [![Styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
9
9
  [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
10
10
  [![Known Vulnerabilities](https://snyk.io/test/github/arlac77/pacc/badge.svg)](https://snyk.io/test/github/arlac77/pacc)
11
- [![Coverage Status](https://coveralls.io/repos/arlac77/pacc/badge.svg)](https://coveralls.io/github/arlac77/pacc)
12
11
 
13
12
  # pacc
14
13
 
@@ -135,6 +134,8 @@ const result = getAttribute({ a: [0,{ b: 4 }]}, "a[1].b");
135
134
  * [DOUBLE\_BAR](#double_bar)
136
135
  * [IDENTIFIER](#identifier)
137
136
  * [EOF](#eof)
137
+ * [Type](#type)
138
+ * [Properties](#properties-2)
138
139
 
139
140
  ## prepareAttributesDefinitions
140
141
 
@@ -182,6 +183,7 @@ Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Globa
182
183
  * `mandatory` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** 
183
184
  * `collection` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** 
184
185
  * `private` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** should the value be shown
186
+ * `credential` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** any type of credential
185
187
  * `depends` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** name of an attribute we depend on
186
188
  * `description` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** human readable
187
189
  * `default` **any?** the default value
@@ -643,6 +645,16 @@ Type: [Token](#token)
643
645
 
644
646
  Type: [Token](#token)
645
647
 
648
+ ## Type
649
+
650
+ Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)
651
+
652
+ ### Properties
653
+
654
+ * `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** 
655
+ * `primitive` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** 
656
+ * `prepareValue` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)?** 
657
+
646
658
  # install
647
659
 
648
660
  With [npm](http://npmjs.org) do:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pacc",
3
- "version": "5.2.0",
3
+ "version": "5.3.0",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
@@ -39,14 +39,14 @@
39
39
  },
40
40
  "devDependencies": {
41
41
  "ava": "^6.4.1",
42
- "browser-ava": "^2.3.45",
42
+ "browser-ava": "^2.3.47",
43
43
  "c8": "^10.1.3",
44
44
  "documentation": "^14.0.3",
45
45
  "semantic-release": "^25.0.2",
46
46
  "typescript": "^5.9.3"
47
47
  },
48
48
  "engines": {
49
- "node": ">=24.11.1"
49
+ "node": ">=24.12.0"
50
50
  },
51
51
  "repository": {
52
52
  "type": "git",
package/src/time.mjs ADDED
@@ -0,0 +1,33 @@
1
+ const units = {
2
+ ms: 0.001,
3
+ s: 1,
4
+ m: 60,
5
+ h: 3600,
6
+ d: 86400,
7
+ w: 604800
8
+ };
9
+
10
+ /**
11
+ *
12
+ * @param {number|string} value
13
+ * @returns {number}
14
+ */
15
+ export function parseTime(value) {
16
+ if (typeof value === "string") {
17
+ let seconds = 0;
18
+
19
+ for (const match of value.matchAll(/([\d\.\-]+)\s*(\w*)/gi)) {
20
+ const v = parseFloat(match[1]);
21
+
22
+ if (match[2]) {
23
+ seconds += v * units[match[2]];
24
+ } else {
25
+ seconds += v;
26
+ }
27
+ }
28
+
29
+ return seconds;
30
+ }
31
+
32
+ return value;
33
+ }
package/src/types.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  import { attributeIterator } from "./attributes.mjs";
2
+ import { parseTime } from "./time.mjs";
2
3
 
3
4
  /**
4
5
  * @typedef {Object} Type
@@ -39,8 +40,7 @@ export const types = {
39
40
  duration: {
40
41
  name: "duration",
41
42
  primitive: true,
42
- prepareValue: value =>
43
- typeof value === "string" ? parseFloat(value) : value
43
+ prepareValue: value => parseTime(value) * 1000
44
44
  },
45
45
  url: {
46
46
  name: "url",
@@ -0,0 +1,6 @@
1
+ /**
2
+ *
3
+ * @param {number|string} value
4
+ * @returns {number}
5
+ */
6
+ export function parseTime(value: number | string): number;
package/types/types.d.mts CHANGED
@@ -30,7 +30,7 @@ export const types: {
30
30
  duration: {
31
31
  name: string;
32
32
  primitive: boolean;
33
- prepareValue: (value: any) => any;
33
+ prepareValue: (value: any) => number;
34
34
  };
35
35
  url: {
36
36
  name: string;