# sunduan-util

> sunduan-util

Latest version **1.0.18** (published 2018-06-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install sunduan-util
pnpm add sunduan-util
yarn add sunduan-util
bun add sunduan-util
```

## 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.18 |
| Published | 2018-06-01 |
| First published | 2018-05-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 57.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | 彭涧 |
| Maintainers | dajianjian |
| Keywords | util, function, browser |

## Links

- npm: https://www.npmjs.com/package/sunduan-util
- Repository: https://github.com/jamesjianpeng/sunduan-util
- Homepage: https://github.com/jamesjianpeng/sunduan-util#readme
- Issues: https://github.com/jamesjianpeng/sunduan-util/issues
- npm.io page: https://npm.io/package/sunduan-util

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 1.0.18 (latest) — 2018-06-01
- 1.0.6 (beta) — 2018-05-16
- 1.0.17 — 2018-05-31
- 1.0.16 — 2018-05-22
- 1.0.15 — 2018-05-21
- 1.0.14 — 2018-05-21
- 1.0.13 — 2018-05-20
- 1.0.12 — 2018-05-19
- 1.0.11 — 2018-05-19
- 1.0.10 — 2018-05-17
- 1.0.9 — 2018-05-17
- 1.0.8 — 2018-05-17
- 1.0.7 — 2018-05-16
- 1.0.5 — 2018-05-13
- 1.0.4 — 2018-05-13
- … 4 more at https://npm.io/package/sunduan-util/versions

## README

## sunduan-util

[![Build Status](https://travis-ci.org/jamesjianpeng/sunduan-util.svg?branch=master)](https://travis-ci.org/jamesjianpeng/sunduan-util)
[![codecov](https://codecov.io/gh/jamesjianpeng/sunduan-util/branch/master/graph/badge.svg)](https://codecov.io/gh/jamesjianpeng/sunduan-util)
--------
主要为前端提供常用的工具函数

### 特征
1. 常用的 array 方法
2. 对象的复制
3. 时间格式的转化
4. 函数节流

npm address: [https://www.npmjs.com/package/sunduan-util](https://www.npmjs.com/package/sunduan-util)

### Using NPM

  ```
  install:

  npm i sunduan-util -save

  use:

  import {
    hello,
    throttle, // 函数节流
    deepClone,
    // array function
    pop,
    forEach,
    FormatDate
  } from 'sunduan-util';

  ```
### Using CDN:

  ```

  <script src="https://unpkg.com/sunduan-util/dist/sunduan-util.js"></script>
  <script type="text/javascript">
    console.log(sunduanUtil)
  </script>
  ```

### test


  ```

	console.log(hello(), 'sunDuanUtil');

  ```

### throttle  
  - throttle(callback,time)

  | params    | type       | default  | require  |
  | :-------- |:---------: |:-------: |:--------:|
  | callback  | Function   | -        | true     |
  | time      | Number     | 500      | false    |
  | return    | -          | -        |  -       |

  ```

  var func = function() {
    console.log(window.innerWidth, window.innerHeight);
  }

  func = throttle(func, 2000);
  window.addEventListener('resize', func);

  ```

### pop
  - pop(list)

  |           | type       | default  | require  |
  | :-------- |:---------: |:-------: |:--------:|
  | list      | Object     | -        |  true    |
  | return    | Array      | -        |  -       |


  ```

  var list = [1, 2, 3, 4, 5, 6];

  var newList = pop(list);

  console.log(newList); // [1, 2, 3, 4, 5]
  console.log(list); // [1, 2, 3, 4, 5, 6]

  ```

### forEach
  - forEach(obj, callback)

  |           | type       | default  | require  |
  | :--------- |:---------: | :-------:|:--------:|
  | obj       | Object     | -        |  true    |
  | callback  | Function   | -        |  true    |
  | return    | -          | -        |  -       |

  ```

  var obj = { a: 10, b: 20, c: 30 }
  forEach(obj, function(value, index, obj) {
    console.log(value, index, obj);
  })

  var list = [1, 2, 3, 4]
  forEach(list, function(value, index, obj) {
    console.log(value, index, obj);
  })

  ```

### buildURL
  - buildURL(url, params)

  |           | type       | default  | require  |
  | --------- |:---------: |:-------: |:--------:|
  | url       | String     | -        |  true    |
  | params    | Object     | null     |  false   |
  | return    | String     | -        |  true    |

  ```
  var url = 'https://testxxxx.com/comments';

  var params = {
    postId: 1,
    page: 1,
    pageSize: 10
  };

  var url = buildURL(url, params);

  console.log(url); // https://testxxxx.com/comments?postId=1&page=1&pageSize=10

  ```

### deepClone
  - deepClone(obj, type)

  type: default | JSON

  |           | type       | default  | require  |
  | :-------- |:----------:|:--------:|:--------:|
  | obj       | Object     | -        |  true    |
  | type      | String     | default  |  false   |
  | return    | String     | -        |  true    |

  ```
  var obj = {
    a: 'a',
    b: 'b',
    c: 'c',
    d: {
      one: 'd1',
      two: 'd2'
    },
    e: ['e1', 'e2', 'e3', 'e4']
  }
  var newObj = deepClone(obj)
  newObj.e.push('e5')
  console.log(newObj.e) // ['e1', 'e2', 'e3', 'e4', 'e5']
  console.log(obj.e) // ['e1', 'e2', 'e3', 'e4']

  var obj = {
    a: 'a1',
    b: 'b2',
    c: 'c3',
    d: {
      one: 'd1',
      two: 'd2'
    },
    e: ['e1', 'e2', 'e3', 'e4']
  }
  var newObj = deepClone(obj, 'JSON')
  newObj.d.one = 'd3'
  console.log(newObj.d) // { one: 'd3', two: 'd2' }
  console.log(obj.d) // { one: 'd1', two: 'd2' }

  ```

  ### FormatDate

   - formatDate.getDate(date, format)

    format type: YYYY-MM-DD HH:mm:ss , YYYY/MM/DD HH:mm , YYYY/MM/DD HH , YYYY/MM/DD , YYYY/MM , YYYY ......
    format 年月日中间使用非字母的字符代替

  |           | type        | default              | require  |
  | :-------- |:----------: |:--------------------:|:---------:|
  | date      | Date|Number | -                    |  true    |
  | format    | String      | YYYY/MM/DD HH:mm:ss  |  false   |


   ```
   var formatDate = new FormatDate()
   var time = formatDate.getDate(+new Date())
   console.log(time.date) // 2018/05/19 15:35:38

   var formatDate = new FormatDate()
   var timeTwo = formatDate.getDate(+new Date('2018/05/19 15:27:51'), 'YYYY-MM-DD HH:mm:ss')
   console.log(timeTwo.date) // 2018-05-19 15:27:51

   setTimeout(function () {
     var timeTwo = formatDate.getDate(+new Date('2018/05/19 15:27:53'))
     console.log(timeTwo.date) // 2018|05|19
   }, 2000)

   var timeTwo = formatDate.getDate(+new Date('2018/05/19 15:27:51'), 'YYYY-MM-DD HH:mm')
   console.log(timeTwo.date) // 2018-05-19 15:27

   var timeTwo = formatDate.getDate(+new Date('2018/05/19 15:27:51'), 'YYYY-MM-DD HH')
   console.log(timeTwo.date) // 2018-05-19 15

   var timeTwo = formatDate.getDate(+new Date('2018/05/19 15:27:51'), 'YYYY-MM-DD')
   console.log(timeTwo.date) // 2018-05-19

   var timeTwo = formatDate.getDate(+new Date('2018/05/19 15:27:51'), 'YYYY|MM|DD')
   console.log(timeTwo.date) // 2018|05|19

   var timeTwo = formatDate.getDate(+new Date('2018/05/19 15:27:51'), 'YYYY&MM&DD')
   console.log(timeTwo.date) // 2018&05&19

   ```

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