Home / File/ splice-changes-into-string.ts — tailwindcss Source File

splice-changes-into-string.ts — tailwindcss Source File

Architecture documentation for splice-changes-into-string.ts, a typescript file in the tailwindcss codebase. 0 imports, 2 dependents.

File typescript CommandLineInterface Renderer 2 dependents 1 functions

Entity Profile

Dependency Diagram

graph LR
  53e05093_45c6_ed5a_9c90_dcc94281fddf["splice-changes-into-string.ts"]
  bcb20eda_2bd7_ff25_6134_e91d834a79e1["candidates.test.ts"]
  bcb20eda_2bd7_ff25_6134_e91d834a79e1 --> 53e05093_45c6_ed5a_9c90_dcc94281fddf
  e39bed3f_bfbf_a8c6_90a0_aa2ce3be1ef4["migrate.ts"]
  e39bed3f_bfbf_a8c6_90a0_aa2ce3be1ef4 --> 53e05093_45c6_ed5a_9c90_dcc94281fddf
  style 53e05093_45c6_ed5a_9c90_dcc94281fddf fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

export interface StringChange {
  start: number
  end: number
  replacement: string
}

/**
 * Apply the changes to the string such that a change in the length
 * of the string does not break the indexes of the subsequent changes.
 */
export function spliceChangesIntoString(str: string, changes: StringChange[]) {
  // If there are no changes, return the original string
  if (!changes[0]) return str

  // Sort all changes in order to make it easier to apply them
  changes.sort((a, b) => {
    return a.end - b.end || a.start - b.start
  })

  // Append original string between each chunk, and then the chunk itself
  // This is sort of a String Builder pattern, thus creating less memory pressure
  let result = ''

  let previous = changes[0]

  result += str.slice(0, previous.start)
  result += previous.replacement

  for (let i = 1; i < changes.length; ++i) {
    let change = changes[i]

    result += str.slice(previous.end, change.start)
    result += change.replacement

    previous = change
  }

  // Add leftover string from last chunk to end
  result += str.slice(previous.end)

  return result
}

Subdomains

Types

Frequently Asked Questions

What does splice-changes-into-string.ts do?
splice-changes-into-string.ts is a source file in the tailwindcss codebase, written in typescript. It belongs to the CommandLineInterface domain, Renderer subdomain.
What functions are defined in splice-changes-into-string.ts?
splice-changes-into-string.ts defines 1 function(s): spliceChangesIntoString.
What files import splice-changes-into-string.ts?
splice-changes-into-string.ts is imported by 2 file(s): candidates.test.ts, migrate.ts.
Where is splice-changes-into-string.ts in the architecture?
splice-changes-into-string.ts is located at packages/@tailwindcss-upgrade/src/utils/splice-changes-into-string.ts (domain: CommandLineInterface, subdomain: Renderer, directory: packages/@tailwindcss-upgrade/src/utils).

Analyze Your Own Codebase

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

Try Supermodel Free