# fan-js

> fan-js

Latest version **1.0.7** (published 2022-10-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install fan-js
pnpm add fan-js
yarn add fan-js
bun add fan-js
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.7 |
| Published | 2022-10-28 |
| First published | 2022-10-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 13.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | FancyHao |
| Maintainers | fancy-hao |

## Links

- npm: https://www.npmjs.com/package/fan-js
- npm.io page: https://npm.io/package/fan-js

## Recent versions

- 1.0.7 (latest) — 2022-10-28
- 1.0.6 — 2022-10-18
- 1.0.5 — 2022-10-17
- 1.0.4 — 2022-10-09
- 1.0.3 — 2022-10-09
- 1.0.1 — 2022-10-08
- 1.0.0 — 2022-10-08

## README

# Fan-JS

---

**这是一个懒人 js，为了让你在开发中节省时间，包含一些常用的 JS 函数，例如时间转换，数组排序等...**

## 安装

    yarn add fan-js

## 引入方式

    import fan(这个可以自定义) from "fan-js";

### 全局引入

    Vue中的使用:
        在main.js中引入
        import fan(这个可以自定义) from "fan-js";
        Vue.prototype.fan = fan

        vue文件中使用: this.fan.函数() 例如: this.fan.isPhone()

---

## 注意

**注意,以下方法需要引入后才可使用**
_如果传参中使用[],则表示该参数为不必传_

---

## 验证

### 身份证验证

    函数名: isIdCard
    使用方式: fan.isIdCard('身份证号码')
    返回结果：布尔值（true || false）
    		 没有传参的情况下返回为:false

### 手机号码验证

    函数名: isPhone
    使用方式: fan.isPhone('手机号码')
    返回结果：布尔值（true || false）
    		 没有传参的情况下返回为:false

### 邮箱验证

    函数名: isEmail
    使用方式: fan.isEmail('邮箱')
    返回结果：布尔值（true || false）
    		 没有传参的情况下返回为:false

---

## 排序

### 简单数组排序(数字)

    函数名: sort
    使用方式: fan.sort(数组,[1 => 从小到大 | 2 => 从大到小 | 3 => 随机排序])
    传参:
        传参1:数组
        传参2:1 => 从小到大 | 2 => 从大到小 | 3 => 随机排序 (不传时,默认从小到大排序)
    返回结果：排序好的数组
    		 没有传参的情况下返回为:[]

### 对象数组排序(根据对象的某个值进行排序)

    函数名: sortObj
    使用方式: fan.sortObj(数组,对象中的键,[1 => 从小到大 | 2 => 从大到小])
     传参:
        传参1:数组
        传参2:对象中的键
        传参3:1 => 从小到大 | 2 => 从大到小 (不传时,默认从小到大排序)
    返回结果：排序好的数组
    		 没有传参的情况下返回为:[]

    例子:
      let arr = [
          {id: 0,name: 'Fancy',age: 18},
          {id: 1,name: 'Fancy2',age: 20},
          {id: 2,name: 'Fancy1',age: 19}
      ]
      sortObj(arr,'age',2)
     返回结果：
       [
        { id: 1, name: 'Fancy2', age: 20 },
        { id: 2, name: 'Fancy1', age: 19 },
        { id: 0, name: 'Fancy', age: 18 }
      ]

## 日期转换

### 年月日(符号间隔)

    函数名: formatDateOfYMD
        使用方式: fan.formatDateOfYMD(时间戳 || '2022-10-09' || new Date())
        传参:
            传参1:日期即可,
            传参2:分隔符(不必传) 默认: -  例如: fan.formatDateOfYMD(new Date(),'/') 返回 2022/10/09
        返回结果：
                没有传参的情况下返回为:false

### 年月日(中文间隔)

    函数名: formatDateOfYMD_C
        使用方式: fan.formatDateOfYMD_C(时间戳 || '2022-10-09' || new Date())
        传参:
            传参1:日期即可
        返回结果：
                2022年10月09日
                没有传参的情况下返回为:false

### 年月(符号间隔)

    函数名: formatDateOfYM
        使用方式: fan.formatDateOfYM(时间戳 || '2022-10-09' || new Date())
        传参:
            传参1:日期即可,
            传参2:分隔符(不必传) 默认: -  例如: fan.formatDateOfYM(new Date(),'/') 返回 2022/10/09
        返回结果：
                没有传参的情况下返回为:false

### 年月(中文间隔)

    函数名: formatDateOfYM_C
        使用方式: fan.formatDateOfYM_C(时间戳 || '2022-10-09' || new Date())
        传参:
            传参1:日期即可
        返回结果：
                2022年10月09日
                没有传参的情况下返回为:false

## 获取周月

### 通过当前时间获取本周开始和结束日期

    函数名: getStartAndEndOfWeek
        使用方式: fan.getStartAndEndOfWeek()
        返回结果：{
            startDate: '2022-10-17',
            endDate: '2022-10-23'
        }

### 通过当前时间获取上周开始和结束日期

    函数名: getStartAndEndOfLastWeek
        使用方式: fan.getStartAndEndOfLastWeek()
        返回结果：{
            startDate: '2022-10-10',
            endDate: '2022-10-16'
        }

### 通过当前时间获取本月开始和结束日期

    函数名: getStartAndEndOfMonth
        使用方式: fan.getStartAndEndOfMonth()
        返回结果：{
            startDate: '2022-10-01',
            endDate: '2022-10-31'
        }

### 通过当前时间获取上月开始和结束日期

    函数名: getStartAndEndOfLastMonth
        使用方式: fan.getStartAndEndOfLastMonth()
        返回结果：{
            startDate: '2022-09-01',
            endDate: '2022-09-30'
        }

### 获取近 N 月日期

    函数名: getMonthsAgo
        例如获取近20个月的时间段:
        fan.getMonthsAgo(20)
        返回结果：{
            pastTimet:"2021-02-24",
            presentTime:"2022-10-24"

}

## DOM

### 判断是否为移动端
    函数名: isMobile
    	使用方式: fan.isMobile()
        返回结果：Boolean值

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