Package Exports
- tag-name-parser
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (tag-name-parser) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
tag-name-parser
A tag parser that does not support attributes. Lightweight and fast.
Install
npm i tag-name-parserUsage
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-parser | htmlparser2 | parse5 | sax | html-parse-stringify2 | fast-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