# oen-utils

> Common tools and methods Library

Latest version **1.0.10** (published 2022-03-25) · GPL-3.0 license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.10 |
| Published | 2022-03-25 |
| First published | 2021-05-21 |
| Weekly downloads | 0 |
| License | GPL-3.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 27.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Kevin.Xu |
| Maintainers | oen.im |
| Keywords | utils, oen |

## Links

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

## Recent versions

- 1.0.10 (latest) — 2022-03-25
- 1.0.9 — 2022-03-24
- 1.0.8 — 2022-03-11
- 1.0.7 — 2021-06-22
- 1.0.6 — 2021-06-22
- 1.0.5 — 2021-06-22
- 1.0.4 — 2021-06-22
- 1.0.3 — 2021-05-21
- 1.0.2 — 2021-05-21
- 1.0.1 — 2021-05-21
- 1.0.0 — 2021-05-21

## README

<div align="center">
	<br>
	<p>OEN 常用工具方法库</p>
	<a href="https://packagephobia.now.sh/result?p=oen-utils"><img src="https://badgen.net/packagephobia/install/oen-utils" alt="Current version"></a>
	<a href="https://www.npmjs.com/package/oen-utils"><img src="https://img.shields.io/npm/v/oen-utils" alt="Install size"></a><br/>
	<a href="https://www.npmjs.com/package/oen-utils"><img src="https://nodei.co/npm/oen-utils.png" alt="Base Info"></a>
	<br>
</div>

<!-- TOC -->
- [安装 (Introduction)](#Introduction)
- [加载此模块 (Loading the module)](#Loading)
- [常用APIs (Common Usage)](#Usage)
    - [安全运行 (safeRun)](#safeRun)
    - [阻塞睡眠 (sleep)](#sleep)
    - [阻塞睡眠 (isEmpty)](#isEmpty)
    - [字符串转数字 (parseInt)](#parseInt)
    - [替换所有 (replaceAll)](#replaceAll)
    - [移除字符串中所有的空格 (trimAll)](#trimAll)
    - [常用汉字 (cyHanzi)](#cyHanzi)
<!-- /TOC -->

## Introduction

安装 (Introduction)

```sh
npm install oen-utils
```

## Loading

加载此模块 (Loading the module)

```js
// CommonJS
const utils = require('oen-utils');

// ES Module
import utils from 'oen-utils';
```

如果你想在全局使用 (if you want to use the global)

```js
const utils = require('oen-utils');
if (!globalThis.utils) {
	globalThis.utils = utils;
}
```

## Usage

常用APIs (Common Usage)

### safeRun

```js
const utils = require('oen-utils');

let data = utils.safeRun(() => {
	return "this data";
});

console.log(data);
```

### sleep

```sh
Note: sleep 传入的阻塞时间内部使用的是setTimeout
```

```js
const utils = require('oen-utils');

await utils.sleep(2000);

console.log("run");
```

### isEmpty

```sh
Note: 判断传入进来的对象是否为空,如果是数字则是否为0
```

```js
const utils = require('oen-utils');

let res = utils.isEmpty("");

console.log(res);
```

### parseInt

```sh
Note: 提取传入的字符串中的数字并转化为数字类型，如果没有数字则返回null
```

```js
const utils = require('oen-utils');

let res = utils.parseInt("asdt7s7ad67a8da9");

console.log(res);
```

### replaceAll

```sh
Note: 替换所有指定的字符串
```

```js
const utils = require('oen-utils');

let str = "asdbada";

let newStr = utils.replaceAll("b","",str);

console.log(newStr);
```

### trimAll

```sh
Note: 移除字符串中所有的空字符串
```

```js
const utils = require('oen-utils');

let str = " sadas dsa dsadsadasd ";

let newStr = utils.trimAll(str);

console.log(newStr);
```

### cyHanzi

```sh
Note: 返回常用的中国汉字
```

```js
const utils = require('oen-utils');

let hanzi =  utils.cyHanzi();

console.log(hanzi);
```

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