# wools

> base tool...

Latest version **0.0.5** (published 2020-11-26) · ISC license · 0 weekly downloads

## Install

```sh
npm install wools
pnpm add wools
yarn add wools
bun add wools
```

## 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.5 |
| Published | 2020-11-26 |
| First published | 2020-08-18 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 11.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | syy |
| Maintainers | wkmyws |

## Links

- npm: https://www.npmjs.com/package/wools
- Repository: https://github.com/wkmyws/wools
- Homepage: https://github.com/wkmyws/wools#readme
- Issues: https://github.com/wkmyws/wools/issues
- npm.io page: https://npm.io/package/wools

## Recent versions

- 0.0.5 (latest) — 2020-11-26
- 0.0.4 — 2020-11-26
- 0.0.3 — 2020-08-25
- 0.0.2 — 2020-08-21
- 0.0.1 — 2020-08-18

## README

### 控制台输入输出

#### print( color , text )

向控制台输出一串字符串(默认不换行)

+ color: 可选，输出字符串的颜色

  ```javascript
  color = {
  	red, green, blue, white, black, yellow, reset
  }
  ```

+ text: 输出的文本

+ return: text

+ 示例

  ```javascript
  print("red","这是红色的信息")
  print("这是默认颜色的信息")
  print("这是换行的信息\n")
  ```

  ---

#### readLine ( color , text )

从控制台读取一行字符串

+ color: 可选,同`print()`的`color`参数

+ text: 提示文本
+ return: 读取的字符串(不含结尾的`\n`)

+ 示例

  ```javascript
  let name = await readLine("输入你的名字：")
  let stst = await readLine("red","确定退出吗？\n")
  await readLine()
  ```

  

---

### 文件操作

#### file.list( dir, deepth )

遍历path目录

+ dir: 遍历的目录
+ deepth: 递归遍历文件夹的深度，默认遍历所有子文件夹，为`1`时只遍历dir文件夹
+ return: 文件路径数组

+ 示例

  ```javascript
  file.list('./')
  file.list('./',2)
  ```



---

#### file.info ( filePath )

文件信息（选取于fs.stat）

+ filePath: 文件路径

+ return: 

  ```json
  {
  	size, 
  	baseName, extName, dirName, 
  	访问时间, 修改时间, 创建时间,
  }
  ```

  ~~<font color="red">注意，extName默认被转为小写字母格式</font>~~

+ 示例

  ```javascript
  file.info('./baseTool.js')
  ```

  结果：

  ```json
  {
    size: 3158,
    baseName: 'baseTool.js',
    extName: '.js',
    dirName: '.',
    '访问时间': 2020-08-12T08:06:49.695Z,
    '修改时间': 2020-08-12T08:06:49.480Z,
    '创建时间': 2020-08-12T04:16:35.553Z
  }
  ```

---

#### file.rename ( filePath , rename )

重命名文件

+ filePath: 文件路径
+ rename: 
  + ( fileName, filePath ) => newName
  + string: newName
+ return: 改名后的文件路径

+ 示例

  ```javascript
  file.rename('./a.txt','b.txt')
  file.rename('./a.txt',(v)=>'b.txt')
  
  //批量重命名当前文件夹的png图片
  file.list('./',1)
      .filter(v=>file.info(v).extName==".png")
  	.forEach((v,i)=>file.rename(v,i+".png"))
  ```

---

#### file.read ( file )

以utf8格式读取文件

+ file: 文件路径
+ return: 文件内容

#### file.write ( file )

以utf8重写文件

+ file: 文件路径
+ return: 写入内容

---

#### file.json( file )

创建file.json对象

+ file: 文件路径

+ return: Object

  + Object: 

    + set : (key,value)

      设置json[key]=value

    + get: (key)

      获取json[key]

    + clear: ()

      清除json

+ 示例

  ```javascript
  let a = file.json('./a.json')
  // set
  a.set({a:23,b:"hello"})
  a.set("c",23)
  
  // get
  a.get("c") // 23
  a.get(["a","b","c"]) // [23,"hello",23]
  json_a=a.get() // {a,b,c}
  
  // clear
  a.clear() // {}
  ```

---

#### execSync ( cmd )

执行cmd命令

+ cmd: 命令

+ return {stdout,stderr}

+ 示例

  ```javascript
  await execSync("echo | npm --version")
  ```

---

#### file.encrypt ( file, pwd, newFile=file )

用aes-192-cbc加密

+ data: 原始数据

+ key: 密码

+ newFile: 加密后的文件路径，默认覆盖原文件

+ 示例

  ```javascript
  await file.encrypt("1.txt","password")
  ```

---

#### file.decrypt ( file, pwd, newFile=file )

对应`file.encrypt`的解密函数

+ 示例

  ```
  await file.decrypt("1.txt","password")
  ```

---

### 字符串操作

#### encrypt(str, pwd)

字符串加密

---

#### decrypt(str, pwd)

字符串解密

---

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