MCPcopy
hub / github.com/tailwindlabs/prettier-plugin-tailwindcss / spliceChangesIntoString

Function spliceChangesIntoString

src/utils.ts:110–141  ·  view source on GitHub ↗
(str: string, changes: StringChange[])

Source from the content-addressed store, hash-verified

108 * of the string does not break the indexes of the subsequent changes.
109 */
110export function spliceChangesIntoString(str: string, changes: StringChange[]) {
111 // If there are no changes, return the original string
112 if (!changes[0]) return str
113
114 // Sort all changes in order to make it easier to apply them
115 changes.sort((a, b) => {
116 return a.end - b.end || a.start - b.start
117 })
118
119 // Append original string between each chunk, and then the chunk itself
120 // This is sort of a String Builder pattern, thus creating less memory pressure
121 let result = ''
122
123 let previous = changes[0]
124
125 result += str.slice(0, previous.start)
126 result += previous.after
127
128 for (let i = 1; i < changes.length; ++i) {
129 let change = changes[i]
130
131 result += str.slice(previous.end, change.start)
132 result += change.after
133
134 previous = change
135 }
136
137 // Add leftover string from last chunk to end
138 result += str.slice(previous.end)
139
140 return result
141}
142
143export function bigSign(bigIntValue: bigint) {
144 return Number(bigIntValue > 0n) - Number(bigIntValue < 0n)

Callers 6

utils.bench.tsFile · 0.90
utils.test.tsFile · 0.90
transformLiquidFunction · 0.85
reprintFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…