New:Socket for Asana Is Now Available.Learn more
Get Started

html-parse-string

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

html-parse-string

Utils for parsing and stringify html strings

latest
Source
npmnpm
Version
0.0.9
Version published
Weekly downloads
16K
-10.13%
Maintainers
1
Weekly downloads
 
Created
Source

html-parse-string

HTML parse and stringify utils

Installation

npm install html-parse-string

IDom

basic data structure

export interface IDom {
  type: string;
  content ? : string;
  voidElement: boolean;
  name: string;
  attrs: { [key: string]: any };
  children: IDom[];
}

parse

parse html to idom array

const { parse, stringify } = require('html-parse-string');
const t = `<div>this is div</div>`;
console.log(parse(t));

get idom array

[
  {
    type: "tag",
    name: "div",
    voidElement: false,
    attrs: {},
    children: [
      {
        type: "text",
        content: "this is div",
      },
    ],
  },
];

stringify

stringify idom array to html

const { parse, stringify } = require('html-parse-string');
const t = `<div>this is div</div>`;
const ast = parse(t);
console.log(stringify(ast));

get html string

<div>this is div</div>

FAQs

Package last updated on 04 Apr 2023

Related posts