MCPcopy
hub / github.com/YMFE/yapi / handleParamsValue

Function handleParamsValue

common/utils.js:103–123  ·  view source on GitHub ↗
(val, context = {})

Source from the content-addressed store, hash-verified

101}
102
103function handleParamsValue(val, context = {}) {
104 const variableRegexp = /\{\{\s*([^}]+?)\}\}/g;
105 if (!val || typeof val !== 'string') {
106 return val;
107 }
108 val = val.trim();
109
110 let match = val.match(/^\{\{([^\}]+)\}\}$/);
111 if (!match) {
112 // val ==> @name 或者 $.body
113 if (val[0] === '@' || val[0] === '$') {
114 return handleFilter(val, val, context);
115 }
116 } else {
117 return handleFilter(val, match[1], context);
118 }
119
120 return val.replace(variableRegexp, (str, match) => {
121 return handleFilter(str, match, context);
122 });
123}
124
125exports.handleJson = handleJson;
126exports.handleParamsValue = handleParamsValue;

Callers 4

common.test.jsFile · 0.90
handleValueFunction · 0.50
handleValueFunction · 0.50

Calls 1

handleFilterFunction · 0.85

Tested by

no test coverage detected