1.0.1 • Published 6 years ago

tag-name-parser v1.0.1

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

tag-name-parser

A tag parser that does not support attributes. Lightweight and fast.

npm

Install

npm i tag-name-parser

Usage

const parse = require('tag-name-parser')

parse(`hello <a>world<b>~</b><c/>!</a>`)

output:

[
    'hello ',
    {
        name: 'a',
        single: false,
        children: [
            'world',
            {
                name: 'b',
                single: false,
                children: [
                    '~'
                ]
            },
            {
                name: 'c',
                single: true
            },
            '!'
        ]
    }
]

Non-strict mode

If strict is false, the result is returned without error.

parse('<a>invalid<b>', {strict: false})

output:

[
    {
        name: 'a',
        single: false,
        children: [
            'invalid',
            {
                name: 'b',
                single: false,
                children: []
            }
        ]
    }
]

Change tag brackets.

parse('hello [a]world[/a]', {tag: ['[', ']']})

output:

{
    'hello ',
    {
        name: 'a',
        single: false,
        children: [
            'world'
        ]
    }
}

Benchmark

Each test 10,000 times. (bench-example.txt)

tag-name-parserhtmlparser2parse5saxhtml-parse-stringify2fast-xml-parser
~184 ms~609 ms~2.67 s~1.41 s~910 ms~529 ms

It is fast because it does not provide much. 😜

License

MIT

1.0.1

6 years ago

1.0.0

6 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago