# coa-helper

> helper component for coa

Latest version **1.2.1** (published 2021-05-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install coa-helper
pnpm add coa-helper
yarn add coa-helper
bun add coa-helper
```

## 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.2.1 |
| Published | 2021-05-29 |
| First published | 2020-05-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 12.2 KB |
| Known vulnerabilities | 0 (+23 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Aex |
| Maintainers | adaex |
| Keywords | coajs, coa, helper |

## Links

- npm: https://www.npmjs.com/package/coa-helper
- Repository: https://github.com/coajs/coa-helper
- npm.io page: https://npm.io/package/coa-helper

## Dependencies (5)

- [axios](https://npm.io/package/axios.md) ^0.21.1
- [dayjs](https://npm.io/package/dayjs.md) ^1.10.5
- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [hashids](https://npm.io/package/hashids.md) ^2.2.8
- [@types/lodash](https://npm.io/package/@types/lodash.md) ^4.14.170

## Alternatives

- [lodash.assign](https://npm.io/package/lodash.assign.md) — 2.3M weekly downloads
- [lodash.chunk](https://npm.io/package/lodash.chunk.md) — 1.8M weekly downloads
- [react-native-ios-utilities](https://npm.io/package/react-native-ios-utilities.md) — 138.5K weekly downloads
- [@technically/lodash](https://npm.io/package/@technically/lodash.md) — 50.9K weekly downloads
- [@fluid-topics/ft-icon](https://npm.io/package/@fluid-topics/ft-icon.md) — 20.6K weekly downloads

## Recent versions

- 1.2.1 (latest) — 2021-05-29
- 1.2.0 — 2021-05-29
- 1.1.1 — 2021-03-12
- 1.0.6 — 2020-06-01
- 1.0.5 — 2020-05-23
- 1.0.4 — 2020-05-22
- 1.0.3 — 2020-05-22
- 1.0.2 — 2020-05-22
- 1.0.1 — 2020-05-22

## README

# coa-helper

[![GitHub license](https://img.shields.io/badge/license-MIT-green.svg?style=flat-square)](LICENSE)
[![npm version](https://img.shields.io/npm/v/coa-helper.svg?style=flat-square)](https://www.npmjs.org/package/coa-helper)
[![npm downloads](https://img.shields.io/npm/dm/coa-helper.svg?style=flat-square)](http://npm-stat.com/charts.html?package=coa-helper)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://github.com/coajs/coa-helper/pulls)

COA 基础工具库，包含常用方法、必要的第三方类库

## 使用说明

### 安装

```shell
yarn add coa-helper
```

### 导入

```typescript
// 导入 helper
import { helper } from 'coa-helper'

// 也可以导入为短字符 $
import { $ } from 'coa-helper'

// $ 是 helper 的别名，两者完全相同的，都可以正常使用，下文均以 $ 为例
$ === helper // true
```

### 常用方法

```typescript
// 异步休眠，代码暂停指定毫秒（注意：必须在async函数下运行，前面要加await）
await $.timeout(1000)

// 解析成数组，如果已经是数组则直接返回，不是数组则将值放在数组中，如果为空则返回空数组
$.parseArray([1, 2, 3]) // [1, 2, 3]
$.parseArray(1) // [1]
$.parseArray('A') // ['A']
$.parseArray(undefined) // []
$.parseArray(null) // []

// 将对象数组转成键值对的对象形式
const list1 = [
  { id: 'a', name: 'A' },
  { id: 'b', name: 'B' },
  { id: 'c', name: 'C' },
]
$.list2object(list1, 'id') // { a: { id: 'a', name: 'AA' }, b: { id: 'b', name: 'BB' },c: { id: 'c', name: 'BB' }}

// 将所有键转换为snakeCase风格
const object1 = { userId: '1', userName: 'A', extendData: { userAge: 25, userAvatar: '' } }
const object2 = $.snakeCaseKeys(object1) // { user_id: '1', user_name: 'A', extend_data: { user_age: 25, user_avatar: '' }}

// 将所有键转换为camelCase风格
$.camelCaseKeys(object2) // { userId: '1', userName: 'A', extendData: { userAge: 25, userAvatar: '' } }
```

### 第三方库

包含以下第三方库

- [dayjs](https://day.js.org/zh-CN)
- [axios](https://github.com/axios/axios)
- [hashids](https://hashids.org)
- [lodash](https://lodash.com)

```typescript
// 获取 dayjs 对象，dayjs的使用详见 https://day.js.org/zh-CN
import { dayjs } from 'coa-helper'

// 获取 axios 对象，axios的使用详见 https://github.com/axios/axios
import { axios } from 'coa-helper'

// 获取 hashids 对象，hashids的使用详见 https://hashids.org
import { HashIds } from 'coa-helper'

// 获取 lodash 对象，lodash的使用详见 https://lodash.com
import { lodash } from 'coa-helper'

// lodash 存在别名 _ ，也可以直接导入
import { _ } from 'coa-helper'
```

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