# demo-1809a

> ```javascript const fs = require("fs"); class ReplaceHTML { constructor(opt) { Object.assign(this, opt);

Latest version **1.0.0** (published 2020-11-18) · ISC license · 0 weekly downloads

## Install

```sh
npm install demo-1809a
pnpm add demo-1809a
yarn add demo-1809a
bun add demo-1809a
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; large bundle.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2020-11-18 |
| First published | 2020-11-18 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 12.2 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | qwe896673315 |

## Links

- npm: https://www.npmjs.com/package/demo-1809a
- npm.io page: https://npm.io/package/demo-1809a

## Recent versions

- 1.0.0 (latest) — 2020-11-18

## README

# 替换
```javascript
const fs = require("fs");
class ReplaceHTML {
    constructor(opt) {
        Object.assign(this, opt);

        const htmlCon = fs.readFileSync(this.htmlsrc, "utf-8");
        const cssCon = fs.readFileSync(this.csssrc, "utf-8");
        const jsCon = fs.readFileSync(this.jssrc, "utf-8");
        const str = htmlCon.replace("<!-- 替换css -->", `<style>${cssCon}</style>`)
            .replace("<!-- 替换js -->", `<script>${jsCon}</script>`)

        fs.writeFileSync("src/demo.html", str)
    }
}

new ReplaceHTML({
    htmlsrc: "src/index.html",
    csssrc: "src/index.css",
    jssrc: "src/index.js",
})

```


# dir-to-json

```javascript
const fs = require("fs");
const path = require("path");

function dirToJson(dir) {
    // 完成代码
    const isFile = fs.statSync(dir).isFile();
    if (isFile) {
        return {
            name: path.basename(dir),
            pathname: dir,
            type: "file",
            size: fs.statSync(dir).size,
            content: fs.readFileSync(dir, "utf-8")
        }
    } else {
        return {
            name: path.basename(dir),
            pathname: dir,
            type: "dir",
            children: fs.readdirSync(dir).map(item => {
                const realPath = path.join(dir, item);
                return dirToJson(realPath)
            })
        }
    }
}


const o = dirToJson("node_modules");
fs.writeFileSync("data.json", JSON.stringify(o))

```


# json-to-dir
```javascript
const fs = require("fs");
const jsonToDir = (data) => {
    // 判断是不是文件
    if (data.type === "file") {
        // 生成文件
        fs.writeFileSync(data.pathname, data.content);
    } else {
        // 创建文件夹
        fs.mkdirSync(data.pathname);
        // 递归
        data.children.forEach(item => {
            jsonToDir(item)
        })
    }
}

const data = JSON.parse(fs.readFileSync("data.json"))
jsonToDir(data)
```

---
_Source: https://npm.io/package/demo-1809a · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
