All files / lib/packages/shared-utils regex.ts

100% Statements 24/24
90.47% Branches 19/21
75% Functions 3/4
100% Lines 19/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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    186x 371x 887x 887x   887x   31x   31x 856x   368x         371x     186x 9x 20x 20x   6x     6x           1x         9x     186x  
/* eslint no-prototype-builtins: 0 */ // --> OFF
 
export const convertRegexToString = (obj: any) => {
  for (const key in obj) {
    Eif (obj.hasOwnProperty(key)) {
      const value = obj[key];
 
      if (value instanceof RegExp) {
        // Convert RegExp to string
        const str = value.toString();
        // save it in this weird array thing
        obj[key] = /\/(.*)\/(.*)/.exec(str);
      } else if (typeof value === "object" && value !== null) {
        // Recursively process nested objects
        obj[key] = convertRegexToString(value);
      }
    }
  }
 
  return obj;
};
 
export const reInsertRegex = (obj: any) => {
  for (const key in obj) {
    Eif (obj.hasOwnProperty(key)) {
      if (typeof obj[key] === "object" && obj[key] !== null) {
        // If the current property is an object, recursively call the function
        obj[key] = reInsertRegex(obj[key]);
 
        // Check if the current object has a property "pattern" with a "value" key
        if (
          obj[key].hasOwnProperty("pattern") &&
          typeof obj[key].pattern === "object" &&
          obj[key].pattern.hasOwnProperty("value")
        ) {
          // if its a pattern.value replace the value's value with a regex from the weird array thing
          obj[key].pattern.value = new RegExp(obj[key].pattern.value[1], obj[key].pattern.value[2]);
        }
      }
    }
  }
  return obj;
};
 
export const noLeadingTrailingWhitespace = /^(?!\s)[\s\S]*\S$/;