INNER CODE UNIT · TypeScript

expandPatternSyntax

scribbletune/scribbletune · src/cli.ts:136

const expandPatternSyntax = (pattern: string): string => {
  const jsRepeatQuoted = pattern.match(/^(['"])(.+)\1\.repeat\((\d+)\)$/);
  if (jsRepeatQuoted) {
    return jsRepeatQuoted[2].repeat(Number(jsRepeatQuoted[3]));
  }

  const jsRepeatUnquoted = pattern.match(/^(.+)\.repeat\((\d+)\)$/);
  if (jsRepeatUnquoted) {
    return jsRepeatUnquoted[1].repeat(Number(jsRepeatUnquoted[2]));
  }

  const prefixRepeat = pattern.match(/^(\d+)\((.+)\)$/);
  if (prefixRepeat) {
    return prefixRepeat[2].repeat(Number(prefixRepeat[1]));
  }

  const suffixRepeat = pattern.match(/^\((.+)\)(\d+)$/);
  if (suffixRepeat) {

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…