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 VueCore VDom 1 dependents 2 functions

Entity Profile

Dependency Diagram

graph LR
  e7aa288a_f5ad_28a9_75b4_4d0ad05fd70c["codeframe.ts"]
  fce21fb3_1100_1200_4d40_dbc0f8981911["to-function.ts"]
  fce21fb3_1100_1200_4d40_dbc0f8981911 --> e7aa288a_f5ad_28a9_75b4_4d0ad05fd70c
  style e7aa288a_f5ad_28a9_75b4_4d0ad05fd70c 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 VueCore domain, VDom 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: VueCore, subdomain: VDom, directory: src/compiler).

Analyze Your Own Codebase

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

Try Supermodel Free