File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -2,20 +2,29 @@ import walkObject from './walkObject';
22
33const SRC_ATTR_PATTERN = / s r c $ / ;
44
5- export default function dereference ( container , dataSources ) {
5+ export default function dereference (
6+ container ,
7+ dataSources ,
8+ config = { deleteKeys : false }
9+ ) {
610 const replacer = ( key , parent ) => {
711 if ( ! SRC_ATTR_PATTERN . test ( key ) ) {
812 return ;
913 }
1014
1115 const srcRef = parent [ key ] ;
1216 const data = dataSources [ srcRef ] ;
17+ const dataKey = key . replace ( SRC_ATTR_PATTERN , '' ) ;
18+
19+ if ( config . deleteKeys && ! ( srcRef in dataSources ) ) {
20+ delete parent [ dataKey ] ;
21+ return ;
22+ }
1323
1424 if ( ! Array . isArray ( data ) ) {
1525 return ;
1626 }
1727
18- const dataKey = key . replace ( SRC_ATTR_PATTERN , '' ) ;
1928 parent [ dataKey ] = data ;
2029 } ;
2130
You can’t perform that action at this time.
0 commit comments