Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathcontainer_array_match.js
More file actions
Latest commit
47 lines (39 loc) · 1.58 KB
/
Copy pathcontainer_array_match.js
File metadata and controls
47 lines (39 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
'use strict';
varRegistry=require('../registry');
/*
* containerArrayMatch: does this attribute string point into a
* layout container array?
*
* @param {String} astr: an attribute string, like *annotations[2].text*
*
* @returns {Object | false} Returns false if `astr` doesn't match a container
* array. If it does, returns:
* {array: {String}, index: {Number}, property: {String}}
* ie the attribute string for the array, the index within the array (or ''
* if the whole array) and the property within that (or '' if the whole array
* or the whole object)
*/
module.exports=functioncontainerArrayMatch(astr){
varrootContainers=Registry.layoutArrayContainers;
varregexpContainers=Registry.layoutArrayRegexes;
varrootPart=astr.split('[')[0];
vararrayStr;
varmatch;
// look for regexp matches first, because they may be nested inside root matches
// eg updatemenus[i].buttons is nested inside updatemenus
for(vari=0;i<regexpContainers.length;i++){
match=astr.match(regexpContainers[i]);
if(match&&match.index===0){
arrayStr=match[0];
break;
}
}
// now look for root matches
if(!arrayStr)arrayStr=rootContainers[rootContainers.indexOf(rootPart)];
if(!arrayStr)returnfalse;
vartail=astr.slice(arrayStr.length);
if(!tail)return{array: arrayStr,index: '',property: ''};
match=tail.match(/^\[(0|[1-9][0-9]*)\](\.(.+))?$/);
if(!match)returnfalse;
return{array: arrayStr,index: Number(match[1]),property: match[3]||''};
};