Home / Function/ numberToPos() — vite Function Reference

numberToPos() — vite Function Reference

Architecture documentation for the numberToPos() function in utils.ts from the vite codebase.

Entity Profile

Dependency Diagram

graph TD
  7e08b9a5_2650_5312_63d2_5971015349af["numberToPos()"]
  031bc221_67a8_c579_f2bf_bb30a08beeb2["utils.ts"]
  7e08b9a5_2650_5312_63d2_5971015349af -->|defined in| 031bc221_67a8_c579_f2bf_bb30a08beeb2
  6d315957_5b5c_845c_10c4_b8cb46bc58eb["buildImportAnalysisPlugin()"]
  6d315957_5b5c_845c_10c4_b8cb46bc58eb -->|calls| 7e08b9a5_2650_5312_63d2_5971015349af
  9282ac90_d29c_cf0b_bdf8_00ac31e9ba20["_formatLog()"]
  9282ac90_d29c_cf0b_bdf8_00ac31e9ba20 -->|calls| 7e08b9a5_2650_5312_63d2_5971015349af
  d5b72255_236c_e62d_9524_5d6892ba1d7f["ssrManifestPlugin()"]
  d5b72255_236c_e62d_9524_5d6892ba1d7f -->|calls| 7e08b9a5_2650_5312_63d2_5971015349af
  027164d9_0d90_6487_4866_e21cb9d3e6c1["ssrTransformScript()"]
  027164d9_0d90_6487_4866_e21cb9d3e6c1 -->|calls| 7e08b9a5_2650_5312_63d2_5971015349af
  310ed049_c1b4_c917_b399_81bab290e5a2["generateCodeFrame()"]
  310ed049_c1b4_c917_b399_81bab290e5a2 -->|calls| 7e08b9a5_2650_5312_63d2_5971015349af
  style 7e08b9a5_2650_5312_63d2_5971015349af fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/vite/src/node/utils.ts lines 470–483

export function numberToPos(source: string, offset: number | Pos): Pos {
  if (typeof offset !== 'number') return offset
  if (offset > source.length) {
    throw new Error(
      `offset is longer than source length! offset ${offset} > length ${source.length}`,
    )
  }

  const lines = source.slice(0, offset).split(splitRE)
  return {
    line: lines.length,
    column: lines[lines.length - 1].length,
  }
}

Domain

Subdomains

Frequently Asked Questions

What does numberToPos() do?
numberToPos() is a function in the vite codebase, defined in packages/vite/src/node/utils.ts.
Where is numberToPos() defined?
numberToPos() is defined in packages/vite/src/node/utils.ts at line 470.
What calls numberToPos()?
numberToPos() is called by 5 function(s): _formatLog, buildImportAnalysisPlugin, generateCodeFrame, ssrManifestPlugin, ssrTransformScript.

Analyze Your Own Codebase

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

Try Supermodel Free