repository-provider 32.2.3 → 32.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.
Files changed (2) hide show
  1. package/package.json +3 -3
  2. package/src/attribute.mjs +42 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "repository-provider",
3
- "version": "32.2.3",
3
+ "version": "32.3.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -35,10 +35,10 @@
35
35
  },
36
36
  "devDependencies": {
37
37
  "ava": "^5.1.0",
38
- "browser-ava": "^1.3.5",
38
+ "browser-ava": "^1.3.7",
39
39
  "c8": "^7.12.0",
40
40
  "documentation": "^14.0.0",
41
- "repository-provider-test-support": "^2.2.19",
41
+ "repository-provider-test-support": "^2.2.20",
42
42
  "semantic-release": "^19.0.5",
43
43
  "typescript": "^4.8.4"
44
44
  },
package/src/attribute.mjs CHANGED
@@ -156,6 +156,35 @@ export function setAttribute(object, name, value) {
156
156
  object[last] = value;
157
157
  }
158
158
 
159
+ /**
160
+ * Split property path into tokens
161
+ * @param {string} string
162
+ * @return {Iterator<string>}
163
+ */
164
+ function* tokens(string) {
165
+ let identifier = "";
166
+
167
+ for (const c of string) {
168
+ switch (c) {
169
+ case ".":
170
+ case "[":
171
+ case "]":
172
+ if (identifier.length) {
173
+ yield identifier;
174
+ identifier = "";
175
+ }
176
+ yield c;
177
+ break;
178
+ default:
179
+ identifier += c;
180
+ }
181
+ }
182
+
183
+ if (identifier.length) {
184
+ yield identifier;
185
+ }
186
+ }
187
+
159
188
  /**
160
189
  * Deliver attribute value.
161
190
  * The name may be a property path like 'a.b.c'.
@@ -168,11 +197,20 @@ export function getAttribute(object, name) {
168
197
  return object[name];
169
198
  }
170
199
 
171
- for (const p of name.split(/\./)) {
172
- if (object === undefined) {
173
- break;
200
+ for (const token of tokens(name)) {
201
+ switch (token) {
202
+ case ".":
203
+ case "[":
204
+ case "]":
205
+ break;
206
+
207
+ default:
208
+ if (object === undefined) {
209
+ break;
210
+ }
211
+
212
+ object = object[token];
174
213
  }
175
- object = object[p];
176
214
  }
177
215
 
178
216
  return object;