• Version 4.0.0
  • Published
  • 33.6 kB
  • No dependencies
  • MIT license


npm i character-parser
yarn add character-parser
pnpm add character-parser


Parse JavaScript one character at a time to look for snippets in Templates. This is not a validator, it's just designed to allow you to have sections of JavaScript delimited by brackets robustly.



function defaultState

defaultState: () => State;

    function isKeyword

    isKeyword: (id: string) => boolean;

      function isPunctuator

      isPunctuator: (c: string) => boolean;

        function parse

        parse: (
        src: string,
        state?: State,
        options?: { readonly start?: number; readonly end?: number }
        ) => State;

          function parseChar

          parseChar: (character: string, state?: State) => State;

            function parseUntil

            parseUntil: (
            src: string,
            delimiter: string | RegExp,
            options?: {
            readonly start?: number;
            readonly end?: number;
            readonly ignoreLineComment?: boolean;
            readonly ignoreNesting?: boolean;
            ) => { start: number; end: number; src: string };


              class State

              class State {}

                property escaped

                escaped: boolean;

                  property hasDollar

                  hasDollar: boolean;

                    property history

                    history: string;

                      property lastChar

                      lastChar: string;

                        property regexpStart

                        regexpStart: boolean;

                          property src

                          src: string;

                            property stack

                            stack: TOKEN_TYPES[];

                              method current

                              current: () => TOKEN_TYPES;

                                method isComment

                                isComment: () => boolean;

                                  method isNesting

                                  isNesting: (opts?: { readonly ignoreLineComment?: boolean }) => boolean;

                                    method isString

                                    isString: () => boolean;


                                      enum TOKEN_TYPES

                                      enum TOKEN_TYPES {
                                      LINE_COMMENT = 'LINE_COMMENT',
                                      BLOCK_COMMENT = 'BLOCK_COMMENT',
                                      SINGLE_QUOTE = 'SINGLE_QUOTE',
                                      DOUBLE_QUOTE = 'DOUBLE_QUOTE',
                                      TEMPLATE_QUOTE = 'TEMPLATE_QUOTE',
                                      REGEXP = 'REGEXP',
                                      ROUND_BRACKET = 'ROUND_BRACKET',
                                      CURLY_BRACKET = 'CURLY_BRACKET',
                                      SQUARE_BRACKET = 'SQUARE_BRACKET',

                                        member BLOCK_COMMENT

                                        BLOCK_COMMENT = 'BLOCK_COMMENT'

                                          member CURLY_BRACKET

                                          CURLY_BRACKET = 'CURLY_BRACKET'

                                            member DOUBLE_QUOTE

                                            DOUBLE_QUOTE = 'DOUBLE_QUOTE'

                                              member LINE_COMMENT

                                              LINE_COMMENT = 'LINE_COMMENT'

                                                member REGEXP

                                                REGEXP = 'REGEXP'

                                                  member ROUND_BRACKET

                                                  ROUND_BRACKET = 'ROUND_BRACKET'

                                                    member SINGLE_QUOTE

                                                    SINGLE_QUOTE = 'SINGLE_QUOTE'

                                                      member SQUARE_BRACKET

                                                      SQUARE_BRACKET = 'SQUARE_BRACKET'

                                                        member TEMPLATE_QUOTE

                                                        TEMPLATE_QUOTE = 'TEMPLATE_QUOTE'

                                                          Package Files (1)

                                                          Dependencies (0)

                                                          No dependencies.

                                                          Dev Dependencies (3)

                                                          Peer Dependencies (0)

                                                          No peer dependencies.


                                                          To add a badge like this badgeto your package's README, use the codes available below.

                                                          You may also use to create a custom badge linking to

                                                          • Markdown
                                                          • HTML
                                                            <a href=""><img src="" alt=""></a>