https://github.com/dbushell/hyperless
🧼 HTML parser and various utilities
https://github.com/dbushell/hyperless
bun deno html javascript nodejs typescript
Last synced: 11 months ago
JSON representation
🧼 HTML parser and various utilities
- Host: GitHub
- URL: https://github.com/dbushell/hyperless
- Owner: dbushell
- License: mit
- Created: 2024-08-30T05:45:40.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-23T07:27:44.000Z (over 1 year ago)
- Last Synced: 2025-04-10T22:53:47.025Z (11 months ago)
- Topics: bun, deno, html, javascript, nodejs, typescript
- Language: TypeScript
- Homepage:
- Size: 108 KB
- Stars: 9
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 🧼 Hyperless
[](https://jsr.io/@dbushell/hyperless) [](https://www.npmjs.com/package/@dbushell/hyperless)
HTML parser and various utilities.
## `parseHTML`
Parse an HTML document or fragment into a traversable node tree.
```javascript
import {parseHTML} from '@dbushell/hyperless';
const root = parseHTML('
Hello, World!
');
```
Node API subject to change.
## `parseAttributes`
Parse an HTML attribute string into a case-insensitive deduplicated key/value map.
```javascript
import {parseAttributes} from '@dbushell/hyperless';
const map = parseAttributes('a="1" b="2" c d="d" D="d" e=e');
```
HTML entity encoding is handled automatically by default.
## Utilities
### `stripTags`
Remove HTML and return text content with a few niceties.
```javascript
import {stripTags} from '@dbushell/hyperless';
// Pass a chunk of HTML
const text = stripTags('
Ceci n’est pas une paragraphe.
');
```
Text in `
` and `` are wrapped in quotation marks.
### `excerpt`
Generate a text excerpt from HTML content.
```javascript
import {excerpt} from '@dbushell/hyperless';
// Pass a chunk of HTML
const text = excerpt(html);
```
Output is context aware trimmed to the nearest sentence, or word, to fit the maximum length as close as possible.
An optional `maxLength` can be passed as the second argument (default: `300` characters).
* * *
[MIT License](/LICENSE) | Copyright © 2024 [David Bushell](https://dbushell.com)