Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dbushell/hyperless
🧼 HTML parser and various utilities
https://github.com/dbushell/hyperless
bun deno html javascript nodejs typescript
Last synced: 23 days 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 (2 months ago)
- Default Branch: main
- Last Pushed: 2024-10-11T16:05:05.000Z (25 days ago)
- Last Synced: 2024-10-12T05:21:06.112Z (24 days ago)
- Topics: bun, deno, html, javascript, nodejs, typescript
- Language: TypeScript
- Homepage:
- Size: 102 KB
- Stars: 8
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 🧼 Hyperless
[![JSR](https://jsr.io/badges/@dbushell/hyperless?labelColor=98e6c8&color=333)](https://jsr.io/@dbushell/hyperless) [![NPM](https://img.shields.io/npm/v/@dbushell/hyperless?labelColor=98e6c8&color=333)](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)