https://github.com/kiralt/isomorphic-htmlparser
HTML parser that works both in JavaScript and NodeJS with TypeScript support
https://github.com/kiralt/isomorphic-htmlparser
cheerio htmlparser javascript nodejs
Last synced: 4 months ago
JSON representation
HTML parser that works both in JavaScript and NodeJS with TypeScript support
- Host: GitHub
- URL: https://github.com/kiralt/isomorphic-htmlparser
- Owner: KiraLT
- License: mit
- Created: 2023-01-08T17:37:20.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-01-23T14:28:48.000Z (about 2 years ago)
- Last Synced: 2024-05-02T06:56:12.473Z (almost 2 years ago)
- Topics: cheerio, htmlparser, javascript, nodejs
- Language: TypeScript
- Homepage: https://kiralt.github.io/isomorphic-htmlparser/
- Size: 426 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
README
# Isomorphic HTMLParser
[](https://github.com/KiraLT/isomorphic-htmlparser/actions/workflows/codeql-analysis.yml)
[](https://codecov.io/gh/KiraLT/isomorphic-htmlparser)
[](https://github.com/semantic-release/semantic-release)
[](https://github.com/prettier/prettier)
HTML parser that works both in JavaScript and NodeJS with TypeScript support.
Missing something? Create [feature request](https://github.com/KiraLT/isomorphic-htmlparser/issues/new?assignees=&labels=enhancement&template=feature_request.md&title=)!
Read [Documentation 📘](https://kiralt.github.io/isomorphic-htmlparser/)
Check [Demo 🎁](https://kiralt.github.io/isomorphic-htmlparser/demo/)
## Installation
[](https://www.npmjs.com/package/isomorphic-htmlparser)
[](https://www.npmjs.com/package/isomorphic-htmlparser)
### Install with NPM/yarn:
```bash
# NPM
npm install isomorphic-htmlparser
# Yarn
yarn add isomorphic-htmlparser
```
Import what you need:
```typescript
import { parseHTML } from 'isomorphic-htmlparser'
const el = parseHTML(html).find('.my-class > a.title')
const text = parseHTML(html).extract('.my-class > a.title @ text | trim')
console.log(el.text.trim() === text)
// true
```
> Always import only what is necessary to take full advantage of [tree shaking](https://developers.google.com/web/fundamentals/performance/optimizing-javascript/tree-shaking).
## Load directly in the browser
### Include UMD bundle
Include script from CDN and use `isomorphicHtmlparser` global variable:
```html
const { parseHTML } = window.isomorphicHtmlparser
const el = parseHTML(html).find('.my-class > a.title')
const text = parseHTML(html).extract('.my-class > a.title @ text | trim')
console.log(el.text.trim() === text)
// true
```