pacc 5.1.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.1.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",
@@ -9,6 +9,7 @@ import { types } from "./types.mjs";
9
9
  * @property {boolean} mandatory
10
10
  * @property {boolean} collection
11
11
  * @property {boolean} [private] should the value be shown
12
+ * @property {boolean} [credential] any type of credential
12
13
  * @property {string} [depends] name of an attribute we depend on
13
14
  * @property {string} [description] human readable
14
15
  * @property {any} [default] the default value
@@ -31,6 +32,7 @@ export const default_attribute = {
31
32
  mandatory: false,
32
33
  collection: false,
33
34
  private: false,
35
+ credential: false,
34
36
  isKey: false
35
37
  };
36
38
 
@@ -185,7 +187,8 @@ export const uuid_attribute = {
185
187
  */
186
188
  export const secret_attribute = {
187
189
  ...default_attribute_writable,
188
- private: true
190
+ private: true,
191
+ credential: true
189
192
  };
190
193
 
191
194
  /**
@@ -214,7 +217,8 @@ export { secret_attribute as certificate_attribute };
214
217
  export const private_key_attribute = {
215
218
  ...default_attribute_writable,
216
219
  description: "private key",
217
- private: true
220
+ private: true,
221
+ credential: true
218
222
  };
219
223
 
220
224
  /**
@@ -223,7 +227,7 @@ export const private_key_attribute = {
223
227
  export const public_key_attribute = {
224
228
  ...default_attribute_writable,
225
229
  description: "public key",
226
- private: true
230
+ credential: true
227
231
  };
228
232
 
229
233
  /**
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,12 @@
1
1
  import { attributeIterator } from "./attributes.mjs";
2
+ import { parseTime } from "./time.mjs";
3
+
4
+ /**
5
+ * @typedef {Object} Type
6
+ * @property {string} name
7
+ * @property {boolean} [primitive]
8
+ * @property {Function} [prepareValue]
9
+ */
2
10
 
3
11
  const emptyStringIsUndefined = value =>
4
12
  typeof value === "string" && value.length === 0 ? undefined : value;
@@ -32,15 +40,14 @@ export const types = {
32
40
  duration: {
33
41
  name: "duration",
34
42
  primitive: true,
35
- prepareValue: value =>
36
- typeof value === "string" ? parseFloat(value) : value
43
+ prepareValue: value => parseTime(value) * 1000
37
44
  },
38
45
  url: {
39
46
  name: "url",
40
47
  prepareValue: emptyStringIsUndefined,
41
48
  primitive: true
42
49
  },
43
- object: { name: "object" }
50
+ object: { name: "object", primitive: false }
44
51
  };
45
52
 
46
53
  function error(message) {
@@ -7,6 +7,7 @@
7
7
  * @property {boolean} mandatory
8
8
  * @property {boolean} collection
9
9
  * @property {boolean} [private] should the value be shown
10
+ * @property {boolean} [credential] any type of credential
10
11
  * @property {string} [depends] name of an attribute we depend on
11
12
  * @property {string} [description] human readable
12
13
  * @property {any} [default] the default value
@@ -35,6 +36,7 @@ export namespace string_collection_attribute {
35
36
  export let mandatory: boolean;
36
37
  let _private: boolean;
37
38
  export { _private as private };
39
+ export let credential: boolean;
38
40
  export let depends: string;
39
41
  export let description: string;
40
42
  let _default: any;
@@ -182,6 +184,10 @@ export type AttributeDefinition = {
182
184
  * should the value be shown
183
185
  */
184
186
  private?: boolean;
187
+ /**
188
+ * any type of credential
189
+ */
190
+ credential?: boolean;
185
191
  /**
186
192
  * name of an attribute we depend on
187
193
  */
@@ -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;
@@ -39,5 +39,11 @@ export const types: {
39
39
  };
40
40
  object: {
41
41
  name: string;
42
+ primitive: boolean;
42
43
  };
43
44
  };
45
+ export type Type = {
46
+ name: string;
47
+ primitive?: boolean;
48
+ prepareValue?: Function;
49
+ };