MCPcopy Create free account
hub / github.com/APIs-guru/aws2openapi / convertRegex

Function convertRegex

index.js:213–243  ·  view source on GitHub ↗
(pattern)

Source from the content-addressed store, hash-verified

211}
212
213function convertRegex(pattern) {
214
215/* converted from coffeescript function https://raw.githubusercontent.com/drj11/posixbre/master/code/main.coffee */
216
217 var bre1token;
218 bre1token = function(tok) {
219 // In POSIX RE in a bracket expression \ matches itself.
220 if (/^\[/.test(tok)) {
221 tok = tok.replace(/\\/, '\\\\');
222 }
223 // In POSIX RE in a bracket expression an initial ] or initial ^] is allowed.
224 if (/^\[\^?\]/.test(tok)) {
225 return tok.replace(/]/, '\\]');
226 }
227 // Tokens for which we have to remove a leading backslash.
228 if (/^\\[(){}]$/.test(tok)) {
229 return tok[1];
230 }
231 // Tokens for which we have to add a leading backslash.
232 if (/^[+?|(){}]$/.test(tok)) {
233 return '\\' + tok;
234 }
235 // Everything else is unchanged
236 return tok;
237 };
238 // In POSIX RE, (?<!) is a negative lookbehind, which isn't supported in JS.
239 // We strip the negative lookbehind, creating a more permissive regex.
240 pattern = pattern.replace(/\(\?\<\![^)]*\)/g, '');
241
242 return pattern.replace(/\[\^?\]?[^]]*\]|\\.|./g, bre1token);
243}
244
245function transformShape(openapi,shape){
246 shape = _.cloneDeep(shape);

Callers 1

transformShapeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected