Example #1
0
        public StaticState(string input, TsBeautifyOptions options)
        {
            Input = input;
            var indentString  = "";
            var optIndentSize = options.IndentSize ?? 4;
            var optIndentChar = options.IndentChar ?? ' ';

            while (optIndentSize > 0)
            {
                indentString  += optIndentChar;
                optIndentSize -= 1;
            }

            IndentString = indentString;
            var whitespace = ToLookup(Constants.WhitespaceChars);

            WhitespaceChars = ToCharLookup(whitespace);
            var wordChars        = ToLookup(Constants.WordChars);
            var digits           = ToLookup(Constants.Chars);
            var genericsBrackets = ToLookup(Constants.GenericsChars);
            var generics         = ToLookup($"{Constants.WhitespaceChars}{Constants.WordChars},{Constants.GenericsChars}");

            DigitsChars           = ToCharLookup(digits);
            WordCharChars         = ToCharLookup(wordChars);
            GenericsChars         = ToCharLookup(generics);
            GenericsBracketsChars = ToCharLookup(genericsBrackets);
            // <!-- is a special case (ok, it's a minor hack actually)
            Punctuation = ArrayToLookup(
                "=> + - * / % & ++ -- = += -= *= /= %= == === != !== > < >= <= >> << >>> >>>= >>= <<= && &= | || ?? ! !! , : ? ^ ^= |= ::"
                .Split(' '));

            // words which should always start on new line.
            LineStarters = ArrayToLookup(
                "@test,import,let,continue,try,throw,return,var,if,switch,case,default,for,while,break,function"
                .Split(','));
            Options          = options;
            PreserveNewlines = options.PreserveNewlines ?? true;
        }
Example #2
0
 public TsBeautifier(TsBeautifyOptions options = null)
 {
     Options = options ?? new TsBeautifyOptions();
 }