export function findIndentation(input) { let pos = 0; const stack = [0]; const topOfStack = () => stack[stack.length - 1];
const result = {};
const regex = /( *).*(?:$|\r?\n|\r)/g; let match; while ((match = regex.exec(input)) != null) { const [line, indent] = match;
if (line.length === 0) break;
const indentSize = indent.length; const prevSize = topOfStack();
const indentPos = pos + indentSize;
if (indentSize > prevSize) { stack.push(indentSize); result[indentPos] = 1; } else if (indentSize < prevSize) { const prevLength = stack.length; while (topOfStack() !== indentSize) { stack.pop(); } result[indentPos] = -1 * (prevLength - stack.length); } pos += line.length; } if (stack.length > 1) { result[pos] = 1 - stack.length; } return result;}