Home / File/ codeframe.ts — vue Source File

codeframe.ts — vue Source File

Architecture documentation for codeframe.ts, a typescript file in the vue codebase. 0 imports, 1 dependents.

File typescript CompilerSFC ScriptAnalyzer 1 dependents 2 functions

Entity Profile

Dependency Diagram

graph LR
  8dfd476b_479e_3ce1_9cb2_3ae3930648d1["codeframe.ts"]
  cf353af6_04db_f570_4b3b_5a4df92dabc9["to-function.ts"]
  cf353af6_04db_f570_4b3b_5a4df92dabc9 --> 8dfd476b_479e_3ce1_9cb2_3ae3930648d1
  style 8dfd476b_479e_3ce1_9cb2_3ae3930648d1 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

const range = 2

export function generateCodeFrame(
  source: string,
  start: number = 0,
  end: number = source.length
): string {
  const lines = source.split(/\r?\n/)
  let count = 0
  const res: string[] = []
  for (let i = 0; i < lines.length; i++) {
    count += lines[i].length + 1
    if (count >= start) {
      for (let j = i - range; j <= i + range || end > count; j++) {
        if (j < 0 || j >= lines.length) continue
        res.push(
          `${j + 1}${repeat(` `, 3 - String(j + 1).length)}|  ${lines[j]}`
        )
        const lineLength = lines[j].length
        if (j === i) {
          // push underline
          const pad = start - (count - lineLength) + 1
          const length = end > count ? lineLength - pad : end - start
          res.push(`   |  ` + repeat(` `, pad) + repeat(`^`, length))
        } else if (j > i) {
          if (end > count) {
            const length = Math.min(end - count, lineLength)
            res.push(`   |  ` + repeat(`^`, length))
          }
          count += lineLength + 1
        }
      }
      break
    }
  }
  return res.join('\n')
}

function repeat(str: string, n: number) {
  let result = ''
  if (n > 0) {
    // eslint-disable-next-line no-constant-condition
    while (true) {
      // eslint-disable-line
      if (n & 1) result += str
      n >>>= 1
      if (n <= 0) break
      str += str
    }
  }
  return result
}

Domain

Subdomains

Frequently Asked Questions

What does codeframe.ts do?
codeframe.ts is a source file in the vue codebase, written in typescript. It belongs to the CompilerSFC domain, ScriptAnalyzer subdomain.
What functions are defined in codeframe.ts?
codeframe.ts defines 2 function(s): generateCodeFrame, repeat.
What files import codeframe.ts?
codeframe.ts is imported by 1 file(s): to-function.ts.
Where is codeframe.ts in the architecture?
codeframe.ts is located at src/compiler/codeframe.ts (domain: CompilerSFC, subdomain: ScriptAnalyzer, directory: src/compiler).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free