(str: string, changes: StringChange[])
| 108 | * of the string does not break the indexes of the subsequent changes. |
| 109 | */ |
| 110 | export 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 | |
| 143 | export function bigSign(bigIntValue: bigint) { |
| 144 | return Number(bigIntValue > 0n) - Number(bigIntValue < 0n) |
no outgoing calls
no test coverage detected
searching dependent graphs…