JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 7
  • Score
    100M100P100Q41286F
  • License MIT

A tag name parser that does not support attributes. Lightweight and fast when only need tag names.

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

npm

A tag name parser that does not support attributes. Lightweight and fast when only need tag names.

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

If do not use strict option, it returns result without exception.

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

output:

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

Change tag bracket

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

output:

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

License

MIT