# yuzhi-utils

> 禹治科技开发工具库，包含 OE1 参数格式化，JSON格式匹配，翻译工具及pdf转txt工具等。

Latest version **1.1.20** (published 2024-01-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install yuzhi-utils
pnpm add yuzhi-utils
yarn add yuzhi-utils
bun add yuzhi-utils
```

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.20 |
| Published | 2024-01-26 |
| First published | 2023-12-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 40.1 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | Yu Zhi |
| Maintainers | taoger |

## Links

- npm: https://www.npmjs.com/package/yuzhi-utils
- npm.io page: https://npm.io/package/yuzhi-utils

## Dependencies (4)

- [uuid](https://npm.io/package/uuid.md) ^9.0.1
- [axios](https://npm.io/package/axios.md) ^1.6.2
- [pegjs](https://npm.io/package/pegjs.md) ^0.10.0
- [deepl-node](https://npm.io/package/deepl-node.md) ^1.11.0

## Recent versions

- 1.1.20 (latest) — 2024-01-26
- 1.1.19 — 2024-01-24
- 1.1.18 — 2024-01-09
- 1.1.17 — 2024-01-09
- 1.1.16 — 2024-01-05
- 1.1.15 — 2024-01-05
- 1.1.14 — 2023-12-26
- 1.1.13 — 2023-12-22
- 1.1.12 — 2023-12-22
- 1.1.11 — 2023-12-21
- 1.1.10 — 2023-12-21
- 1.1.9 — 2023-12-21
- 1.1.8 — 2023-12-21
- 1.1.7 — 2023-12-20
- 1.1.6 — 2023-12-20
- … 16 more at https://npm.io/package/yuzhi-utils/versions

## README

# 禹治科技工具库

禹治科技开发工具库，包含 OE1 参数格式化，JSON格式匹配等。

## 1. OE1 参数格式化

返回值格式参考

```js
[
  {
    "value": "1W (USB powered, 5VDC, 200 mA)",
    "numVal": null,
    "unit": null,
    "type": 3,
    "maxValue": null,
    "minValue": null,
    "optionVal": null,
    "name": "电源",
    "cnName": "Power"
  },
  ...
]
```

### 示例

``` js
import { specFormat } from 'yuzhi-utils';
const specObj = {
  "分辨率[#$]Resolution": "256 px",
  "探测波段[#$]Band of detection": "MWIR (1 - 5 microns)",
  ...
}
// specObj 参数格式对象  [#$] 为中文与英文中间的分隔符
specFormat(specObj, '[#$]') 
```


## 2. JSON 格式匹配

### 示例
``` js
import { jsonMatch } from 'yuzhi-utils';
// str 为字符串
const jsonObj = jsonMatch(str) 
console.log(jsonObj); // 如果匹配成功，返回对象，匹配失败，返回空对象
```

## 3. 翻译API

### 示例
``` js
import { YoudaoTranslate, DeepLTranslate }  from '../index'
// 有道翻译
const translater = new YoudaoTranslate({
  appKey: 'appKey', 
  appSecret: 'appSecret'
})
async function run() {
  try {
    const texts = `I am a personal\nhello world`;
    const result = await translater.translate(texts);
    console.log('result=>', result)
  } catch (error) {
    console.log('Error:', error)
  }
}
run();

// DeepL翻译 默认英->中
const deepLTranslate = new DeepLTranslate({
  appKey: 'fd7ef643-2c38-8a55-0ad2-9a14961b420d'
})
async function run() {
  try {
    // 将文本翻译为中文
    const translateStr = `我需要一个苹果\nhello world`
    const deepRes = await deepLTranslate.translate(translateStr, 'en', 'zh');
    console.log('result=>', deepRes)
  } catch (error) {
    console.log('Error:', error)
  }
}
run();
```
## 4. PDF -> txt 工具

### 示例
``` js
import { Pdf2Txt } from '../index'
import path from 'path'

async function run() {
  try {
    
    const converter = new Pdf2Txt();
    // convert的output路径可选，生成的文本文件默认会放在与pdf来源路径下的text目录下
    const res = await converter.convert(path.join(__dirname, './pdf/6983713723465093121.pdf'))
    // 如果转换成功，返回对象中，data为Buffer
    if(res.msg === 'success') {
      console.log('文本内容：', Buffer.from(res.data || '').toString('utf-8'))
      console.log('转换成功')
    }
  } catch (error) {
    console.log(error)
  }
}

run();
```

## 5. PDF -> img 从PDF中提取图片

需要使用pip安装 `pymupdf` `pillow` 
``` bash
pip install pymupdf pillow
or
pip3 install pymupdf pillow
```

### 示例
``` js
import { Pdf2Img } from '../index'
import path from 'path'

async function start() {
  try {
    const converter = new Pdf2Img();
    // convert的output路径可选，提取的图片默认放在同目录的img文件夹下
    const res = await converter.convert(path.join(__dirname, './pdf/6983713723465093121.pdf'))
    if(res.msg === 'success') {
      console.log('图片路径信息：',res.data)
    }
  } catch (error) {
    console.log(error)
  }
}

start();
```

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