lib/jspicl.js
function prettify (luaCode) {
  const lines = luaCode
    .split("\n")
    .map(line => line.trim());

  const { code } = lines.reduce((result, line) => {
    const { code, indentation } = result;
    let currentIndentation = indentation;
    let nextLineIndentation = indentation;

    if (indentIncrease.some(entry => entry(line))) {
      nextLineIndentation++;
    }

    if (indentDecrease.some(entry => entry(line))) {
      currentIndentation--;
      nextLineIndentation--;
    }

    code.push(line && line.padStart(line.length + currentIndentation * 2) || line);

    return {
      code,
      indentation: Math.max(0, nextLineIndentation)
    };
  }, {
    code: [],
    indentation: 0
  });

  return code.join("\n");
}
function prettify (luaCode) {
  const lines = luaCode
    .split("\n")
    .map(line => line.trim());

  const { code } = lines.reduce((result, line) => {
    const { code, indentation } = result;
    let currentIndentation = indentation;
    let nextLineIndentation = indentation;

    if (indentIncrease.some(entry => entry(line))) {
      nextLineIndentation++;
    }

    if (indentDecrease.some(entry => entry(line))) {
      currentIndentation--;
      nextLineIndentation--;
    }

    code.push(line && line.padStart(line.length + currentIndentation * 2) || line);

    return {
      code,
      indentation: Math.max(0, nextLineIndentation)
    };
  }, {
    code: [],
    indentation: 0
  });

  return code.join("\n");
}
function prettify ( luaCode ) { const lines = luaCode . split ( "\n" ) . map ( line => line . trim ( ) ) ; const { code } = lines . reduce ( ( result , line ) => { const { code , indentation } = result ; let currentIndentation = indentation ; let nextLineIndentation = indentation ; if ( indentIncrease . some ( entry => entry ( line ) ) ) { nextLineIndentation ++ ; } if ( indentDecrease . some ( entry => entry ( line ) ) ) { currentIndentation -- ; nextLineIndentation -- ; } code . push ( line && line . padStart ( line . length + currentIndentation * 2 ) || line ) ; return { code , indentation : Math . max ( 0 , nextLineIndentation ) } ; } , { code : [ ] , indentation : 0 } ) ; return code . join ( "\n" ) ; }
Fixes code indentation
@param {string} luaCode Original lua code
@returns {string} Formatted code
Fixes code indentation