open-index/open-npm huggingface dataset:
npm package: @pagoda-tools/api
Description: ## 示例代码
Latest version: 1.0.1

# PagodaCos

## 示例代码

```js
import { createApiService } from '@pagoda-tools/api';
import axios from 'axios';

const http = axios.create();

const createApi = createApiService(http);

createApi({
  url: 'xxx',
  method: 'get',
}).request({
  body: {},
});
```

## API

### createApiService

```ts
interface ApiConfig {
  url: string | ((path: ApiRequestConfig['path']) => string);
  method: Method;
  cache: boolean;
  cacheTime: number;
  headers: AxiosRequestConfig['headers'];
  axiosConfig: AxiosRequestConfig;
}

interface ApiRequestConfig<T = any> {
  headers?: AxiosRequestConfig<T>['headers'];
  path?: Record<string, string>;
  query?: Record<string, string>;
  body?: AxiosRequestConfig<T>['data'];
  axiosConfig?: AxiosRequestConfig<T>;
}

class Api {
  http: AxiosInstance;

  config: ApiConfig;

  cache: Record<
    string,
    {
      promise: Promise<any>;
      expireTime: number | null;
    }
  >;

  constructor(http: AxiosInstance, config: ApiConfig): Api;

  request<T = never, R = AxiosResponse<T>>(
    requestConfig?: ApiRequestConfig<T>
  ): Promise<R>;

  clearCache(): void;
}

function createApiService(http: AxiosInstance): (apiConfig: ApiConfig) => Api;
```
npm package: @pagoda-tools/auto-import-resolver
Description: ## 安装
Latest version: 1.0.3

# @pagoda-tools/auto-import-resolver

## 安装

```shell
# npm
npm install unplugin-vue-components @pagoda-tools/auto-import-resolver -D

# yarn
yarn add unplugin-vue-components @pagoda-tools/auto-import-resolver -D
```

## 用法

vite

```javascript
// vite.config.ts
import vue from '@vitejs/plugin-vue';
import Components from 'unplugin-vue-components/vite';
import { PagodaUiResolver } from '@pagoda-tools/auto-import-resolver' ;

export default defineConfig({
  plugins: [
    vue(),
    Components({
      resolvers: [PagodaUiResolver()],
    }),
  ],
})
```
npm package: @pagoda-tools/crypto
Description: crypto 工具扩展功能
Latest version: 1.0.1

# @pagoda-tools/crypto

客户端加解密工具

## 经测试的浏览器

任何支持文件和文件读取器的浏览器都应该可以工作。以下浏览器已经过测试并正常工作：

- IE10 (Windows 7)
- Chrome 42 (OS X 10.10.3)
- Firefox 38 (OS X 10.10.3)
- Safari 8.0.6 (OS X 10.10.3)
- Opera 29.0 (OS X 10.10.3)

请随时更新此列表或通过拉取请求提交特定浏览器的修复程序。

## 安装

`@pagoda-tools/crypto`可通过`npm`和`yarn`获得：

```shell
# install npm
npm install @pagoda-tools/crypto -S

# install yarn
yarn add @pagoda-tools/crypto -S
```

## 用法

引入

```javascript
// 本地路径水印
import PdBizDataCrypt from '@pagoda-tools/crypto';
```

### 初始化 `crypto.js`

```javascript
import axios from 'axios';

const crypto = new PdBizDataCrypt({
  // 客服端 保存的公钥
  public_key: '通过申请得来的公钥',
  // 获得授权
  async getAuthorization({ encryptedData }) {
    if (typeof encryptedData !== 'string') return;
    try {
      // 调用接口获取授权
      const { timestamp, encryptedData: encrypted_data } = axios.post(
        '/getAuthorization',
        {
          encryptedData,
        }
      );
      return {
        timestamp: timestamp,
        encryptedData: encrypted_data,
      };
    } catch (e) {
      console.log('getAuthorization:error');
      throw e;
    }
  },
});

export default crypto;
```

### 加密与解密

```javascript
import crypto from './crypto.js';

const data = { aaa: 123 };

// 数据加密
const { encryptedData, iv } = await crypto.encrypt(data);

// 数据解密
const { aaa: a1 } = await crypto.decrypt(encryptedData, iv);

// a1 === aaa ==> true
```
npm package: @pagoda-tools/crypto-node
Description: crypto-node 工具扩展功能
Latest version: 1.0.1

# @pagoda-tools/crypto-node

服务端加解密工具

## 安装

`@pagoda-tools/crypto-node`可通过`npm`和`yarn`获得：

```shell
# install npm
npm install @pagoda-tools/crypto-node -S

# install yarn
yarn add @pagoda-tools/crypto-node -S
```

## 用法

引入

```javascript
import { PdBizDataCryptNode } from '@pagoda-tools/crypto-node';
```

### 初始化 `pdBizDataCryptNode.js`

```javascript
import axios from 'axios';

// 服务端
const pdBizDataCryptNode = new PdBizDataCryptNode({
  private_key: '申请得来的私钥，',
  appId: '自定义应用ID，如：项目名 admin',
  sessionKey: '自定义或申请来的密钥',
});

export default pdBizDataCryptNode;
```

### 加密与解密

```javascript
import pdBizDataCryptNode from './pdBizDataCryptNode.js';

const data = { aaa: 123 };

// 数据加密
const { encryptedData, iv } = pdBizDataCryptNode.encrypt(data);

// 数据解密
const { aaa: a1 } = pdBizDataCryptNode.decrypt(encryptedData, iv);

// a1 === aaa ==> true
```