npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

yuzhi-utils

v1.1.20

Published

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

Downloads

67

Readme

禹治科技工具库

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

1. OE1 参数格式化

返回值格式参考

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

示例

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

2. JSON 格式匹配

示例

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

3. 翻译API

示例

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 工具

示例

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

pip install pymupdf pillow
or
pip3 install pymupdf pillow

示例

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();