# uojo-kit

> 实用工具库

Latest version **0.3.0** (published 2017-09-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install uojo-kit
pnpm add uojo-kit
yarn add uojo-kit
bun add uojo-kit
```

## 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.3.0 |
| Published | 2017-09-30 |
| First published | 2017-08-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | uojonet@163.com |
| Maintainers | uojo |
| Keywords | uojo, kit, log, console |

## Links

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

## Dependencies (3)

- [chalk](https://npm.io/package/chalk.md) 2.1.0
- [colors](https://npm.io/package/colors.md) 1.1.2
- [chokidar](https://npm.io/package/chokidar.md) 1.6.1

## Alternatives

- [cli-color](https://npm.io/package/cli-color.md) — 3.4M weekly downloads
- [log](https://npm.io/package/log.md) — 1.3M weekly downloads
- [logstash-client](https://npm.io/package/logstash-client.md) — 4.5K weekly downloads
- [@nocobase/plugin-logger](https://npm.io/package/@nocobase/plugin-logger.md) — 2.0K weekly downloads
- [child-process-debug](https://npm.io/package/child-process-debug.md) — 695 weekly downloads

## Recent versions

- 0.3.0 (latest) — 2017-09-30
- 0.2.0 — 2017-09-27
- 0.1.3 — 2017-09-06
- 0.1.2 — 2017-08-22
- 0.1.1 — 2017-08-21
- 0.1.0 — 2017-08-21
- 0.0.3 — 2017-08-17
- 0.0.2 — 2017-08-17
- 0.0.1 — 2017-08-17

## README

# uojo-kit

> 常用 node 模块集合

## 使用

安装

```
npm install uojo-kit
```

代码中引入

```
const uojoKit = require("uojo-kit")

```

## 方法

### log
对 console.log 进行分装，实现：log 输出的颜色定制、log 显示的代码行号

方法 | 功能
:---|:---
clog | log 输出的颜色定制
eclog | 显示代码执行行号

示例：
```
uojoKit.clog('red','content')
uojoKit.red('content') // 支持颜色：'black','red','green','yellow','blue','magenta','cyan','white','gray'
uojoKit.elog('content')
```

### BufferExec(options)
对单任务队列执行进行缓冲执行。简单的说，这个类可以收集需要执行的任务，按顺序执行。

options 参数：

字段 | 默认值 | 作用
:---|:-------|:---
nextPoint | first |下一个执行的任务是取队列中新（last）旧（first）
speedTaskEnter | 0 |任务进入队列的最小时间间隔
runBy | timeline |队列执行方式。`timeline`：时间轴，即当前任务执行完后取下一个任务后，在下一个任务执行前将当前队列中所有任务清空。`queue`：按队列顺序执行

方法：
名称 | 作用
:---|:-----
trigger | 将任务推入执行队列，并触发该任务执行
receipt | 回执当前任务执行完毕


示例：
```
const bufferQueue = new uojoKit.BufferExec({
    runBy:'queue',
    speedTaskEnter:0
})

for(let i=0;i<5;i++){
    bufferQueue.trigger((next)=>{
        setTimeout(()=>{
            console.log(i)
            next(); //执行下一个任务
        })
        
    })
}
```

### DelayExec(times)
对需要密集执行的任务，进行一定的过滤。即起到防火墙的效果

参数

参数 | 默认值 | 作用
:---|:---|:---
times | 0 | 任务最小间隔时间

方法

名称 | 作用
:---|:---
hit(recordName) | 需要执行的任务名，当recordName不传时，默认为 `匿名记录`

示例：
```
const fireWall = new uojoKit.DelayExec()
let count = 10;
let tid=setInterval(()=>{
    if(count<1){
        clearInterval(tid);
        return;
    }
    count--;
    if( fireWall.hit('fire') ){
        console.log('中弹')
    
    }else{
        console.log('阻挡')
    
    }
},30)
```

## changeLog
### 0.3.0
- LOG_LEVEL 替换为 LOG_ENV，且值为 debug 时才会执行 elog
### 0.2.0
- elog 显示事件触发的完整路径
### 0.1.3
- 修复 elog 显示行号的bug
### 0.1.2
- 修复显示 Error 对象
- 方法 clog 新增快捷调用方式：clog.red('...') 等于 clog('red','...')
### 0.1.1
- 文档补充
### 0.1.0
- 初始化。提供方法：log 模块、BufferExec 类、DelayExec 类

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