# ypf-methods

> 常用基础工具方法

Latest version **1.4.2** (published 2021-08-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install ypf-methods
pnpm add ypf-methods
yarn add ypf-methods
bun add ypf-methods
```

## 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.4.2 |
| Published | 2021-08-13 |
| First published | 2020-01-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | ypf |
| Maintainers | yinpengfei |
| Keywords | ypf, ypf-methods |

## Links

- npm: https://www.npmjs.com/package/ypf-methods
- npm.io page: https://npm.io/package/ypf-methods

## Recent versions

- 1.4.2 (latest) — 2021-08-13
- 1.4.1 — 2021-08-04
- 1.4.0 — 2021-08-04
- 1.3.21 — 2020-11-27
- 1.3.20 — 2020-11-26
- 1.3.19 — 2020-11-26
- 1.3.18 — 2020-11-26
- 1.3.17 — 2020-11-26
- 1.3.15 — 2020-11-26
- 1.3.14 — 2020-11-26
- 1.3.13 — 2020-11-26
- 1.3.12 — 2020-11-26
- 1.3.11 — 2020-11-26
- 1.3.10 — 2020-11-26
- 1.3.9 — 2020-11-26
- … 26 more at https://npm.io/package/ypf-methods/versions

## README

<!--
 * @author: yinpengfei
 * @Date: 2020-01-10 10:27:25
 * @information: readme
 -->

# ypf-methods

> 使用方式

```00
  01. 安装此包

    npm i ypf-methods

  02. 在 main.js 中 引入

    import ypfMethods form 'ypf-methods'

  03. 绑定至原型链使用

    vue 2.x ->  Vue.prototype.$ypfMethods = ypfMethods

    vue 3.x ->  app.config.globalProperties.$ypfMethods = ypfMethods
```

> 方法说明：

### 1. \_deepClone // 深拷贝

参数：字符串或引用类型

返回值：新的对象

```01
  深拷贝：改变对象或数组或字符串的地址

  let obj = {
    aa: undefined,
    name: 'xm',
    birth: new Date,
    desc: null,
    reg: /^123$/,
    ss: [1,2,3],
    fn: function() {
      console.log('123')
    },
  }

  let obj2 = _deepClone(obj)

  //输出结果：
  obj2: {
    aa: undefined,
    name: 'xm',
    birth: new Date,
    desc: null,
    reg: /^123$/,
    ss: [1,2,3],
    fn: function() {
      console.log('123')
    },
  }
```

### 2. \_encryStr // 字符串加星号（\*）展示

```02
  _encryStr(str, start, end)

  参数：str：string 字符串，start：起始下标，end：结束下标（可以是负数，从末尾起始是 -1，以此类推）

  返回值：返回带 \* 的字符串


  let str = '15631171756'

  _encryStr(str, 3, 7)   // 156****1756
  _encryStr(str, 3, -4)   // 156****1756
```

### 3. \_getUrlQuery // 获取地址栏上拼接的参数

```03
  _getUrlQuery(key)

  参数：key: string 字符串

  返回值：key 的 value 值

  // 若当前地址栏 url = http://localhost:8080/detail/2784?code=123&name=yyy

  _getUrlQuery('code') // 123
  _getUrlQuery('name') // yyy
```

### 4. \_moneyBigFormat // 金额转大写

```04
  _moneyBigFormat(val)

  参数：val: string 字符串 或 number 的金额数字

  返回值：大写的数字

  _moneyBigFormat(123456.78)   // 壹拾贰万叁仟肆佰伍拾陆元柒角捌分
  _moneyBigFormat('123456.78') // 壹拾贰万叁仟肆佰伍拾陆元柒角捌分
```

### 5. \_moneyReplace // 金额格式限制

> 适合于 input 输入框变化时的 input 事件

```05
  _moneyReplace(val)

  参数：val: string 字符串 或 number 的金额数字

  返回值：过滤之后的合法的金额字符串


  _moneyReplace(9.1512)    // 9.15
  _moneyReplace('9.1512')  // 9.15
  _moneyReplace('a')  // 0
```

### 6. \_moneyThousandFormat // 金额添加千分符

```06
  _moneyThousandFormat(val)

  参数：val: string 字符串 或 number 的金额数字

  返回值：过滤之后的带千分符的金额字符串

  _moneyThousandFormat(12345678)    // 12,345,678.00
  _moneyThousandFormat('123456.78')    // 123,456.78
```

### 7. \_CookieUtil // cookie 操作方法

> \_CookieUtil 是一个封装好操作方法的对象，内有 setCookie、getCookie、removeCookie 三个方法

```07
（1）setCookie(key, val, timeStamp)

参数: key 键值, val 值, timeStamp 有效时长，时间戳格式(不传默认为当天23:59:59过期)

返回值：无返回值

_CookieUtil.setCookie('name', 'yyy', 1 * 24 * 60 * 60 * 1000)

（2）getCookie(key)

参数: key 键值

返回值：key 的 value 值

_CookieUtil.getCookie('name') // yyy


（3）removeCookie(key)

参数: key 键值

返回值：无返回值

_CookieUtil.getCookie('name')

```

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