pacc 3.6.4 → 3.6.6

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": "3.6.4",
3
+ "version": "3.6.6",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
package/src/multiple.mjs CHANGED
@@ -23,6 +23,7 @@ const types = {
23
23
  string: { name: "string" },
24
24
  number: { name: "number" },
25
25
  integer: { name: "integer" },
26
+ "unsigned-integer": { name: "unsigned-integer" },
26
27
  boolean: { name: "boolean" },
27
28
  object: { name: "object" }
28
29
  };
@@ -68,24 +69,37 @@ export function mergeAttributeDefinitions(dest, atts) {
68
69
  * @param {Object} source origin of the data to be copied
69
70
  * @param {Object} definitions attribute definitions to be used
70
71
  * @param {function?} cb callback to be executed for each copied value
72
+ * @param {string?} prefix name parefix
71
73
  */
72
- export function setAttributes(object, source, definitions, cb) {
73
- for (const [name, def] of Object.entries(definitions)) {
74
- const value = getAttribute(source, name) ?? def.default;
74
+ export function setAttributes(object, source, definitions, cb, prefix) {
75
+ for (let [name, def] of Object.entries(definitions)) {
76
+ if(prefix !== undefined) {
77
+ name = prefix + name;
78
+ }
79
+ let value = getAttribute(source, name);
80
+
75
81
  if (value === undefined) {
76
- if (def.attributes) {
77
- object[name] = {};
78
- }
79
- } else {
80
- if (def.set) {
81
- def.set.call(object, value, def);
82
+ if (def.default === undefined) {
83
+ if (def.attributes) {
84
+ setAttributes(object, source, def.attributes, cb, name + ".");
85
+ }
86
+ continue;
82
87
  } else {
83
- setAttribute(object, name, value);
84
- }
85
- if (cb) {
86
- cb(def, name, value);
88
+ if (getAttribute(object, name) !== undefined) {
89
+ continue;
90
+ }
91
+ value = def.default;
87
92
  }
88
93
  }
94
+
95
+ if (def.set) {
96
+ def.set.call(object, value, def);
97
+ } else {
98
+ setAttribute(object, name, value);
99
+ }
100
+ if (cb) {
101
+ cb(def, name, value);
102
+ }
89
103
  }
90
104
  }
91
105
 
@@ -17,8 +17,9 @@ export function mergeAttributeDefinitions(dest: any, atts: any): any;
17
17
  * @param {Object} source origin of the data to be copied
18
18
  * @param {Object} definitions attribute definitions to be used
19
19
  * @param {function?} cb callback to be executed for each copied value
20
+ * @param {string?} prefix name parefix
20
21
  */
21
- export function setAttributes(object: any, source: any, definitions: any, cb: Function | null): void;
22
+ export function setAttributes(object: any, source: any, definitions: any, cb: Function | null, prefix: string | null): void;
22
23
  /**
23
24
  * Retrive attribute values from an object.
24
25
  * @param {Object} object attribute value source