You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: lib/util/reach.js
+30-7
Original file line number
Diff line number
Diff line change
@@ -4,19 +4,42 @@ var _require = require('property-expr');
4
4
5
5
varforEach=_require.forEach;
6
6
7
+
var_require2=require('./_');
8
+
9
+
varhas=_require2.has;
10
+
7
11
vartrim=functiontrim(part){
8
12
returnpart.substr(0,part.length-1).substr(1);
9
13
};
10
14
11
-
module.exports=function(obj,path){
12
-
forEach(path,function(part,isBracket,isArray){
13
-
if(isArray)obj=obj._subType;else{
14
-
if(obj._subType)// we skipped an array
15
-
obj=obj._subType;
15
+
module.exports=function(obj,path,value,context){
16
+
varparent=undefined,
17
+
lastPart=undefined;
18
+
19
+
// if only one "value" arg then use it for both
20
+
context=context||value;
21
+
22
+
forEach(path,function(_part,isBracket,isArray){
23
+
varpart=isBracket ? trim(_part) : _part;
24
+
25
+
if(isArray||has(obj,'_subType')){
26
+
// we skipped an array
27
+
obj=obj._resolve(context,parent)._subType;
28
+
value=value&&value[0];
29
+
}
30
+
31
+
if(!isArray){
32
+
obj=obj._resolve(context,parent);
33
+
34
+
if(!has(obj,'fields')||!has(obj.fields,part))thrownewError('The schema does not contain the path: '+path+'. '+('(failed at: '+lastPart+' which is a type: "'+obj._type+'") '));
0 commit comments