pacc 4.11.0 → 4.11.1

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
@@ -31,6 +31,8 @@ const result = getAttribute({ a: [0,{ b: 4 }]}, "a[1].b");
31
31
  * [Parameters](#parameters)
32
32
  * [mergeAttributeDefinitions](#mergeattributedefinitions)
33
33
  * [Parameters](#parameters-1)
34
+ * [attributeIterator](#attributeiterator)
35
+ * [Parameters](#parameters-2)
34
36
  * [AttributeDefinition](#attributedefinition)
35
37
  * [Properties](#properties)
36
38
  * [default\_attribute](#default_attribute)
@@ -77,25 +79,25 @@ const result = getAttribute({ a: [0,{ b: 4 }]}, "a[1].b");
77
79
  * [timeout\_attribute](#timeout_attribute)
78
80
  * [language\_attribute](#language_attribute)
79
81
  * [filter](#filter)
80
- * [Parameters](#parameters-2)
81
- * [setAttributes](#setattributes)
82
82
  * [Parameters](#parameters-3)
83
- * [getAttributes](#getattributes)
83
+ * [setAttributes](#setattributes)
84
84
  * [Parameters](#parameters-4)
85
+ * [getAttributes](#getattributes)
86
+ * [Parameters](#parameters-5)
85
87
  * [tokens](#tokens)
86
88
  * [tokens](#tokens-1)
87
- * [Parameters](#parameters-5)
88
- * [setAttribute](#setattribute)
89
89
  * [Parameters](#parameters-6)
90
- * [getAttribute](#getattribute)
90
+ * [setAttribute](#setattribute)
91
91
  * [Parameters](#parameters-7)
92
- * [getAttributeAndOperator](#getattributeandoperator)
92
+ * [getAttribute](#getattribute)
93
93
  * [Parameters](#parameters-8)
94
+ * [getAttributeAndOperator](#getattributeandoperator)
95
+ * [Parameters](#parameters-9)
94
96
  * [lookup](#lookup)
95
97
  * [Token](#token)
96
98
  * [Properties](#properties-1)
97
99
  * [createToken](#createtoken)
98
- * [Parameters](#parameters-9)
100
+ * [Parameters](#parameters-10)
99
101
  * [PLUS](#plus)
100
102
  * [MINUS](#minus)
101
103
  * [STAR](#star)
@@ -146,6 +148,15 @@ Merge attribute definitions.
146
148
 
147
149
  Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** merged definitions (dest)
148
150
 
151
+ ## attributeIterator
152
+
153
+ iterate over all attributes.
154
+
155
+ ### Parameters
156
+
157
+ * `definition` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** 
158
+ * `path` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** (optional, default `[]`)
159
+
149
160
  ## AttributeDefinition
150
161
 
151
162
  Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)
@@ -370,7 +381,6 @@ Copies attribute values from a source object into a destination object.
370
381
  * `source` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** origin of the data to be copied
371
382
  * `definitions` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** attribute definitions to be used
372
383
  * `cb` **[function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)?** callback to be executed for each copied value
373
- * `prefix` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** name parefix
374
384
 
375
385
  ## getAttributes
376
386
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pacc",
3
- "version": "4.11.0",
3
+ "version": "4.11.1",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
@@ -4,7 +4,10 @@ const types = {
4
4
  number: { name: "number" },
5
5
  integer: { name: "integer" },
6
6
  "unsigned-integer": { name: "unsigned-integer" },
7
- boolean: { name: "boolean" },
7
+ boolean: {
8
+ name: "boolean",
9
+ from: value => (!value || value === "0" ? false : true)
10
+ },
8
11
  url: { name: "url" },
9
12
  object: { name: "object" }
10
13
  };
@@ -19,12 +22,8 @@ export function prepareAttributesDefinitions(
19
22
  newDefinitions,
20
23
  presentDefinitions
21
24
  ) {
22
- for (const [name, d] of Object.entries(newDefinitions)) {
23
- if (d.attributes === undefined) {
24
- d.type = types[d.type] || types.base;
25
- } else {
26
- prepareAttributesDefinitions(d.attributes);
27
- }
25
+ for (const [path, def] of attributeIterator(newDefinitions)) {
26
+ def.type = types[def.type] || types.base;
28
27
  }
29
28
 
30
29
  return mergeAttributeDefinitions(newDefinitions, presentDefinitions);
@@ -60,15 +59,17 @@ function mergeAttributeDefinitions(dest, atts) {
60
59
  * @param {string[]} path
61
60
  */
62
61
  export function* attributeIterator(definition, path = []) {
63
- for (const [name, def] of Object.entries(definition)) {
64
- path.push(name);
62
+ if (definition) {
63
+ for (const [name, def] of Object.entries(definition)) {
64
+ path.push(name);
65
65
 
66
- if (def.attributes) {
67
- yield* attributeIterator(def.attributes, path);
68
- }
66
+ if (def.attributes) {
67
+ yield* attributeIterator(def.attributes, path);
68
+ }
69
69
 
70
- yield [path, def];
70
+ yield [path, def];
71
71
 
72
- path.pop();
72
+ path.pop();
73
+ }
73
74
  }
74
75
  }
@@ -0,0 +1,10 @@
1
+ import { attributeIterator } from "./attributes.mjs";
2
+ import { getAttribute } from "./settergetter.mjs";
3
+
4
+ export function createPropertiesFromAttributes(object, attributes, values) {
5
+ for (const [path, def] of attributeIterator(attributes)) {
6
+ const name = path.join(".");
7
+
8
+ let value = getAttribute(values, name, def);
9
+ }
10
+ }
@@ -23,8 +23,9 @@ import { parse } from "./expression.mjs";
23
23
  * @param {Object} object
24
24
  * @param {string} expression
25
25
  * @param {any} value
26
+ * @param {Object} definition type def
26
27
  */
27
- export function setAttribute(object, expression, value) {
28
+ export function setAttribute(object, expression, value, definition) {
28
29
  const { path } = parse({ tokens: tokens(expression) });
29
30
 
30
31
  let anchor, anchorKey;
@@ -0,0 +1 @@
1
+ export function createPropertiesFromAttributes(object: any, attributes: any, values: any): void;
@@ -4,8 +4,9 @@
4
4
  * @param {Object} object
5
5
  * @param {string} expression
6
6
  * @param {any} value
7
+ * @param {Object} definition type def
7
8
  */
8
- export function setAttribute(object: any, expression: string, value: any): void;
9
+ export function setAttribute(object: any, expression: string, value: any, definition: any): void;
9
10
  /**
10
11
  * Deliver attribute value.
11
12
  * The name may be a property path like 'a.b.c' or a[2]