# c-js-utils

> 自用的js的方法库

Latest version **1.0.8** (published 2022-01-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install c-js-utils
pnpm add c-js-utils
yarn add c-js-utils
bun add c-js-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.8 |
| Published | 2022-01-06 |
| First published | 2021-12-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 13.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Cui MengChao |
| Maintainers | make_bugs |

## Links

- npm: https://www.npmjs.com/package/c-js-utils
- Repository: https://github.com/cmcQDGCS/c-func-lib
- Homepage: https://github.com/cmcQDGCS/c-func-lib#readme
- Issues: https://github.com/cmcQDGCS/c-func-lib/issues
- npm.io page: https://npm.io/package/c-js-utils

## Dependencies (1)

- [@babel/polyfill](https://npm.io/package/@babel/polyfill.md) ^7.12.1

## Recent versions

- 1.0.8 (latest) — 2022-01-06
- 1.0.7 — 2022-01-06
- 1.0.6 — 2021-12-23
- 1.0.5 — 2021-12-09
- 1.0.4 — 2021-12-07
- 1.0.3 — 2021-12-06
- 1.0.2 — 2021-12-06

## README

### 简介
在公司工作的过程中, 由于公司业务的问题, 出现了很多类似的逻辑功能, 由此出现了很多相似的方法, 于是把他封装出来供自己以后使用, 也方便公司代码的维护.  
目前封装出来的方法不多, 以后也会继续维护添加新的方法.

### 现有的方法
- 节流
- 防抖
- 深度拷贝
- 深度合并
- 数组洗牌
- 时间戳转时间格式
- 判断数据类型

### 如何使用
目前兼容了Vue2 与 Vue3

```js
// 首先安装
npm install --save c-js-utils 
or
cnpm install --save c-js-utils 

// Vue2 
    // main.js中添加代码
    import func from c-js-utils
    Vue.use(func)

    // 然后再页面中就可以使用了
    this.$debounce(func)

// Vue3
    // main.js中添加代码
    import func from c-js-utils

    const app = createApp()
    app.use(func).mount("#app")

    // 由于vue3 与 vue2 的方法不同, 这里只介绍 composition Api 的用法
    import { getCurrentInstance } from "vue"
    export default {
        setup(){
            const { proxy } = getCurrentInstance()  // 将proxy解构出来   关键代码!!!
            proxy.$debounce(func)  // 使用方法
        }
    }
```

### 方法文档
- 节流
```javascript
    this.$debounce(function, dalay)
    
    // function 是要执行的函数
    // dalay 是延时时间,默认500
```
- 防抖
```javascript
    this.$throttle(function, dalay, first)
    
    // function 是要执行的函数
    // dalay 是延时时间,默认500
    // first 是否一开始就执行一次, 默认 true
```
- 深度拷贝
```javascript
    let data = this.$deepClone(data)
    
    // data 是要克隆的数据
```
- 深度合并
```javascript
    let data = this.$deepMerge(target, source)
    
    // target 是目标数据
    // source 是要合并进去的数据
```
- 数组洗牌
```javascript
    let newArray = this.$arrayShuffle(array)
    
    // array 是处理的数组
```
- 时间戳转时间格式
```javascript
    let time = this.$timeFormat(timeDate, "yyyy-mm-dd")
    
    // timeDate 时间戳
    // "yyyy-mm-dd" 是转化的时间格式
    yyyy => 年
    mm => 月
    dd => 日
    hh => 时
    MM => 分
    ss => 秒
    // 可以自由组合
```
- 判断数据类型
```javascript
    let type = this.$checkType(obj)
    
    // obj 是要判断的数据
    /**
     * 可供判断的数据类型
     * 'boolean',
     * 'number',
     * 'string',
     * 'function',
     * 'array',
     * 'date',
     * 'regExp',
     * 'undefined',
     * 'null',
     * 'object'
     */ 
```

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