# @zzkit/html-s-expr

> This library provides function to convert HTML DOM nodes to S-expressions.

Latest version **1.1.0** (published 2025-03-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install @zzkit/html-s-expr
pnpm add @zzkit/html-s-expr
yarn add @zzkit/html-s-expr
bun add @zzkit/html-s-expr
```

## Health

**Score 40/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2025-03-15 |
| First published | 2024-01-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 54.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | zhzluke96 |
| Maintainers | luke_zhang |

## Links

- npm: https://www.npmjs.com/package/@zzkit/html-s-expr
- Repository: https://github.com/zhzLuke96/html-s-expr
- Homepage: https://github.com/zhzLuke96/html-s-expr#readme
- Issues: https://github.com/zhzLuke96/html-s-expr/issues
- npm.io page: https://npm.io/package/@zzkit/html-s-expr

## Dependencies (1)

- [got-cjs](https://npm.io/package/got-cjs.md) ^12.5.4

## Recent versions

- 1.1.0 (latest) — 2025-03-15
- 1.0.0 — 2024-01-15

## README

# @zzkit/html-s-expr

This library provides function to convert HTML DOM nodes to S-expressions.

## Features

- Supports browser and Node.js
- Generate compact S-expressions where possible
- Preserves element id and class attributes
- 
## Installation

```
npm install @zzkit/html-s-expr
```

## Usage 

In browser:

```js
import { nodeToSExpr } from "@zzkit/html-s-expr";

const sExpr = nodeToSExpr(document.body.parentElement);
```

In Node.js (requires jsdom):

```js 
import { JSDOM } from "jsdom";
import { nodeToSExpr } from "@zzkit/html-s-expr";

const dom = new JSDOM(`...html...`);
nodeToSExpr(dom.window.document.body.parentElement);
```

Full example:

```js
import { nodeToSExpr } from "@zzkit/html-s-expr";
import { JSDOM } from "jsdom";

const dom = new JSDOM(`
  <html>
    <head>
      <title>Test Page</title> 
    </head>
    <body>
      <div id="foo" class="bar baz"> 
        <img src="image.png">
        <a href="#">Link</a>   
      </div>
    </body>
  </html>
`);

const sExpr = nodeToSExpr(dom.window.document.body); 

console.log(sExpr);
// (html (head (title "Test Page"))(body (div#foo.bar.baz (img src="image.png")(a href="#/" "Link"))))  
```

The `nodeToSExpr` function takes two arguments:

- `node` - The DOM node to convert
- `indent` - Number of spaces to indent (default 0)

It will recursively traverse the DOM nodes to generate the S-expression.


## License

MIT

---
_Source: https://npm.io/package/@zzkit/html-s-expr · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
