pacc 3.4.7 → 3.5.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
@@ -103,7 +103,7 @@ Split property path into tokens
103
103
 
104
104
  ## setAttribute
105
105
 
106
- Set Object attribute.
106
+ Set object attribute.
107
107
  The name may be a property path like 'a.b.c'.
108
108
 
109
109
  ### Parameters
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "pacc",
3
- "version": "3.4.7",
3
+ "version": "3.5.0",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
7
7
  },
8
- "types": "./types/attribute.d.mts",
8
+ "types": "./types/module.d.mts",
9
9
  "exports": {
10
10
  ".": {
11
- "types": "./types/attribute.d.mts",
12
- "default": "./src/attribute.mjs"
11
+ "types": "./types/module.d.mts",
12
+ "default": "./src/module.mjs"
13
13
  }
14
14
  },
15
15
  "description": "property path utils",
@@ -36,15 +36,15 @@
36
36
  "npm-pkgbuild": "^18.1.1"
37
37
  },
38
38
  "devDependencies": {
39
- "ava": "^6.4.0",
39
+ "ava": "^6.4.1",
40
40
  "browser-ava": "^2.3.31",
41
41
  "c8": "^10.1.3",
42
42
  "documentation": "^14.0.3",
43
- "semantic-release": "^24.2.5",
43
+ "semantic-release": "^24.2.7",
44
44
  "typescript": "^5.8.3"
45
45
  },
46
46
  "engines": {
47
- "node": ">=22.16.0"
47
+ "node": ">=22.17.1"
48
48
  },
49
49
  "repository": {
50
50
  "type": "git",
package/src/attribute.mjs CHANGED
@@ -1,19 +1,3 @@
1
- /**
2
- * @typedef {Object} AttributeDefinition
3
- *
4
- * @property {string} type
5
- * @property {boolean} isKey
6
- * @property {boolean} writable
7
- * @property {boolean} mandatory
8
- * @property {boolean} [private] should the value be shown
9
- * @property {string} [depends] name of an attribute we depend on
10
- * @property {string[]} additionalAttributes extra attributes that are present in case our attribute is set
11
- * @property {string} [description] human readable
12
- * @property {any} [default] the default value
13
- * @property {Function} [set] set the value
14
- * @property {Function} [get] get the value can be used to calculate default values
15
- * @property {string[]|string} [env] environment variable(s) used to provide the value
16
- */
17
1
 
18
2
  /**
19
3
  * @typedef {import('./tokens.mjs').Token} Token
@@ -32,11 +16,9 @@ import {
32
16
  GREATER_EQUAL,
33
17
  STAR
34
18
  } from "./tokens.mjs";
35
- export * from "./tokens.mjs";
36
- export * from "./filter.mjs";
37
19
 
38
20
  /**
39
- * Set Object attribute.
21
+ * Set object attribute.
40
22
  * The name may be a property path like 'a.b.c'.
41
23
  * @param {Object} object
42
24
  * @param {string} expression
package/src/module.mjs ADDED
@@ -0,0 +1,8 @@
1
+ export * from "./tokens.mjs";
2
+ export * from "./filter.mjs";
3
+ export * from "./multiple.mjs";
4
+ export {
5
+ setAttribute,
6
+ getAttribute,
7
+ getAttributeAndOperator
8
+ } from "./attribute.mjs";
@@ -0,0 +1,55 @@
1
+ import { setAttribute, getAttribute } from "./attribute.mjs";
2
+
3
+ /**
4
+ * @typedef {Object} AttributeDefinition
5
+ *
6
+ * @property {string} name
7
+ * @property {string} type
8
+ * @property {boolean} isKey
9
+ * @property {boolean} writable
10
+ * @property {boolean} mandatory
11
+ * @property {boolean} [private] should the value be shown
12
+ * @property {string} [depends] name of an attribute we depend on
13
+ * @property {string[]} additionalAttributes extra attributes that are present in case our attribute is set
14
+ * @property {string} [description] human readable
15
+ * @property {any} [default] the default value
16
+ * @property {Function} [set] set the value
17
+ * @property {Function} [get] get the value can be used to calculate default values
18
+ * @property {string[]|string} [env] environment variable(s) used to provide the value
19
+ */
20
+
21
+ /**
22
+ * Copies attribute values from a source object into a destination object.
23
+ * @param {Object} object target object to be modified
24
+ * @param {Object} source origin of the data to be copied
25
+ * @param {Object} definitions attribute definitions to be used
26
+ * @param {function} cb callback to be executed for each copied value
27
+ */
28
+ export function setAttributes(object, source, definitions, cb) {
29
+ for (const [name, def] of Object.entries(definitions)) {
30
+ const value = getAttribute(source, name);
31
+ setAttribute(object, name, value);
32
+ if (cb) {
33
+ cb(def, name, value);
34
+ }
35
+ }
36
+ }
37
+
38
+ /**
39
+ * Retrive attribute values from an object.
40
+ * @param {Object} object attribute value source
41
+ * @param {Object} definitions
42
+ * @return {Object} values
43
+ */
44
+ export function getAttributes(object, definitions) {
45
+ const result = {};
46
+
47
+ Object.keys(definitions).forEach(name => {
48
+ const value = getAttribute(object, name);
49
+ if (value !== undefined) {
50
+ result[name] = value;
51
+ }
52
+ });
53
+
54
+ return result;
55
+ }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Set Object attribute.
2
+ * Set object attribute.
3
3
  * The name may be a property path like 'a.b.c'.
4
4
  * @param {Object} object
5
5
  * @param {string} expression
@@ -22,44 +22,4 @@ export function getAttribute(object: any, expression: string): any;
22
22
  * @returns {[any,Token]} value associated with the given property name
23
23
  */
24
24
  export function getAttributeAndOperator(object: any, expression: string): [any, Token];
25
- export * from "./tokens.mjs";
26
- export * from "./filter.mjs";
27
- export type AttributeDefinition = {
28
- type: string;
29
- isKey: boolean;
30
- writable: boolean;
31
- mandatory: boolean;
32
- /**
33
- * should the value be shown
34
- */
35
- private?: boolean;
36
- /**
37
- * name of an attribute we depend on
38
- */
39
- depends?: string;
40
- /**
41
- * extra attributes that are present in case our attribute is set
42
- */
43
- additionalAttributes: string[];
44
- /**
45
- * human readable
46
- */
47
- description?: string;
48
- /**
49
- * the default value
50
- */
51
- default?: any;
52
- /**
53
- * set the value
54
- */
55
- set?: Function;
56
- /**
57
- * get the value can be used to calculate default values
58
- */
59
- get?: Function;
60
- /**
61
- * environment variable(s) used to provide the value
62
- */
63
- env?: string[] | string;
64
- };
65
25
  export type Token = import("./tokens.mjs").Token;
@@ -0,0 +1,4 @@
1
+ export * from "./tokens.mjs";
2
+ export * from "./filter.mjs";
3
+ export * from "./multiple.mjs";
4
+ export { setAttribute, getAttribute, getAttributeAndOperator } from "./attribute.mjs";
@@ -0,0 +1,71 @@
1
+ /**
2
+ * @typedef {Object} AttributeDefinition
3
+ *
4
+ * @property {string} name
5
+ * @property {string} type
6
+ * @property {boolean} isKey
7
+ * @property {boolean} writable
8
+ * @property {boolean} mandatory
9
+ * @property {boolean} [private] should the value be shown
10
+ * @property {string} [depends] name of an attribute we depend on
11
+ * @property {string[]} additionalAttributes extra attributes that are present in case our attribute is set
12
+ * @property {string} [description] human readable
13
+ * @property {any} [default] the default value
14
+ * @property {Function} [set] set the value
15
+ * @property {Function} [get] get the value can be used to calculate default values
16
+ * @property {string[]|string} [env] environment variable(s) used to provide the value
17
+ */
18
+ /**
19
+ * Copies attribute values from a source object into a destination object.
20
+ * @param {Object} object target object to be modified
21
+ * @param {Object} source origin of the data to be copied
22
+ * @param {Object} definitions attribute definitions to be used
23
+ * @param {function} cb callback to be executed for each copied value
24
+ */
25
+ export function setAttributes(object: any, source: any, definitions: any, cb: Function): void;
26
+ /**
27
+ * Retrive attribute values from an object.
28
+ * @param {Object} object attribute value source
29
+ * @param {Object} definitions
30
+ * @return {Object} values
31
+ */
32
+ export function getAttributes(object: any, definitions: any): any;
33
+ export type AttributeDefinition = {
34
+ name: string;
35
+ type: string;
36
+ isKey: boolean;
37
+ writable: boolean;
38
+ mandatory: boolean;
39
+ /**
40
+ * should the value be shown
41
+ */
42
+ private?: boolean;
43
+ /**
44
+ * name of an attribute we depend on
45
+ */
46
+ depends?: string;
47
+ /**
48
+ * extra attributes that are present in case our attribute is set
49
+ */
50
+ additionalAttributes: string[];
51
+ /**
52
+ * human readable
53
+ */
54
+ description?: string;
55
+ /**
56
+ * the default value
57
+ */
58
+ default?: any;
59
+ /**
60
+ * set the value
61
+ */
62
+ set?: Function;
63
+ /**
64
+ * get the value can be used to calculate default values
65
+ */
66
+ get?: Function;
67
+ /**
68
+ * environment variable(s) used to provide the value
69
+ */
70
+ env?: string[] | string;
71
+ };