pacc 1.0.0 → 1.0.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
@@ -15,6 +15,82 @@ propetty path utils
15
15
 
16
16
  # API
17
17
 
18
+ <!-- Generated by documentation.js. Update this documentation by updating the source code. -->
19
+
20
+ ### Table of Contents
21
+
22
+ * [AttributeDefinition](#attributedefinition)
23
+ * [Properties](#properties)
24
+ * [tokens](#tokens)
25
+ * [Parameters](#parameters)
26
+ * [setAttribute](#setattribute)
27
+ * [Parameters](#parameters-1)
28
+ * [getAttribute](#getattribute)
29
+ * [Parameters](#parameters-2)
30
+ * [getAttributeAndOperator](#getattributeandoperator)
31
+ * [Parameters](#parameters-3)
32
+
33
+ ## AttributeDefinition
34
+
35
+ Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)
36
+
37
+ ### Properties
38
+
39
+ * `type` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**&#x20;
40
+ * `writable` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**&#x20;
41
+ * `private` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** should the value be shown
42
+ * `depends` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** name of an attribute we depend on
43
+ * `additionalAttributes` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** extra attributes that are present in case our attribute is set
44
+ * `description` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**&#x20;
45
+ * `default` **any?** the default value
46
+ * `set` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)?** set the value
47
+ * `get` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)?** get the value can be used to calculate default values
48
+ * `env` **([Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)> | [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String))?** environment variable use to provide the value
49
+
50
+ ## tokens
51
+
52
+ Split property path into tokens
53
+
54
+ ### Parameters
55
+
56
+ * `string` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**&#x20;
57
+
58
+ ## setAttribute
59
+
60
+ Set Object attribute.
61
+ The name may be a property path like 'a.b.c'.
62
+
63
+ ### Parameters
64
+
65
+ * `object` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**&#x20;
66
+ * `expression` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**&#x20;
67
+ * `value` **any**&#x20;
68
+
69
+ ## getAttribute
70
+
71
+ Deliver attribute value.
72
+ The name may be a property path like 'a.b.c' or a\[2]
73
+
74
+ ### Parameters
75
+
76
+ * `object` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**&#x20;
77
+ * `expression` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**&#x20;
78
+
79
+ Returns **any** value associated with the given property name
80
+
81
+ ## getAttributeAndOperator
82
+
83
+ Deliver attribute value and operator.
84
+ The name may be a property path like 'a.b.c <='.
85
+
86
+ ### Parameters
87
+
88
+ * `object` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**&#x20;
89
+ * `expression` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**&#x20;
90
+ * `getters` (optional, default `{}`)
91
+
92
+ Returns **\[any, [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)]** value associated with the given property name
93
+
18
94
  # install
19
95
 
20
96
  With [npm](http://npmjs.org) do:
package/package.json CHANGED
@@ -1,9 +1,12 @@
1
1
  {
2
2
  "name": "pacc",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
+ "exports": {
8
+ ".": "./src/attribute.mjs"
9
+ },
7
10
  "description": "property path utils",
8
11
  "contributors": [
9
12
  {
@@ -11,9 +14,6 @@
11
14
  "email": "markus.felten@gmx.de"
12
15
  }
13
16
  ],
14
- "exports": {
15
- ".": "./src/attribute.mjs"
16
- },
17
17
  "license": "BSD-2-Clause",
18
18
  "scripts": {
19
19
  "test": "npm run test:browser-ava && npm run test:ava",
package/src/attribute.mjs CHANGED
@@ -27,11 +27,11 @@ export function* tokens(string) {
27
27
  case "string-escaping":
28
28
  const esc = {
29
29
  "\\": "\\",
30
- t: "\t",
31
30
  b: "\b",
32
- r: "\r",
31
+ f: "\f",
33
32
  n: "\n",
34
- f: "\f"
33
+ r: "\r",
34
+ t: "\t"
35
35
  };
36
36
  buffer += esc[c];
37
37
  state = "string";
@@ -233,6 +233,10 @@ export function setAttribute(object, expression, value) {
233
233
  * @returns {any} value associated with the given property name
234
234
  */
235
235
  export function getAttribute(object, expression) {
236
+ if (object?.[expression] !== undefined) {
237
+ return object[expression];
238
+ }
239
+
236
240
  return getAttributeAndOperator(object, expression)[0];
237
241
  }
238
242