# @lsky/preset-data

> > 在编译期，在项目中，预设数据。

Latest version **0.0.1** (published 2021-09-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install @lsky/preset-data
pnpm add @lsky/preset-data
yarn add @lsky/preset-data
bun add @lsky/preset-data
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2021-09-18 |
| First published | 2021-09-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 9.4 KB |
| Known vulnerabilities | 0 (+23 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | lsky-walt |
| Maintainers | lsky_walt |
| Keywords | preset data in compiler, preset data, better seo |

## Links

- npm: https://www.npmjs.com/package/@lsky/preset-data
- Repository: https://github.com/lsky-walt/preset-data
- Homepage: https://github.com/lsky-walt/preset-data#readme
- Issues: https://github.com/lsky-walt/preset-data/issues
- npm.io page: https://npm.io/package/@lsky/preset-data

## Dependencies (2)

- [axios](https://npm.io/package/axios.md) ^0.21.4
- [chalk](https://npm.io/package/chalk.md) ^4.1.2

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.0.1 (latest) — 2021-09-18

## README

# @lsky/preset-data

> 在编译期，在项目中，预设数据。

## 使用方法

### 安装

```shell
$ yarn add @lsky/preset-data
```

### 添加 `loader`

> 在`babel-loader`处增加`PresetDataLoader`

```javascript
{
  test: /\.(js|jsx)$/,
  exclude: /node_modules/,
  use: [
    "babel-loader",
    {
      loader: "@lsky/preset-data/loader",
    },
  ],
},
```

### 添加 `plugin`

```javascript
const PresetDataPlugin = require("@lsky/preset-data/plugin")
plugins: [
  new PresetDataPlugin([
    {
      name: "jobs", // 必须参数
      // -------
      // fetch 请求参数请参照 axios 配置
      url: "http://localhost:8030/test",  // required
      method: "get",
      //-------
      cb: (data) => {
        // axios response data
        // must return data
        return data.data
      },
    },
  ]),
  new HtmlWebPackPlugin({
    template: path.resolve(__dirname, "../index.ejs"),
    filename: path.resolve(__dirname, "../dist/index.html"),
  }),
],
```

#### `PresetDataPlugin` 使用说明

```typescript
interface Option extends axios.AxiosRequestConfig {
  name: string;
  cb?: (responseData: any) => data:any;
  raw?: any;
}
new PresetDataPlugin(options: (Option | Option[]))
```

| Name | Type     | Default | Description                                                   |
| :--- | :------- | :------ | :------------------------------------------------------------ |
| name | string   | null    | 预设数据名称，用于项目中取值。注意，该字段必填。              |
| cb   | function | null    | 处理数据                                                      |
| raw  | any      | null    | 如设置了 raw，将不通过 request 获取数据。注意，该优先级较高。 |

### 项目中使用预设数据

```javascript
import presetDataFunc from "@lsky/preset-data"

console.log(presetDataFunc("jobs")) // 参数是 plugin 的 name
console.log(presetDataFunc())
```

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