npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

fan-js

v1.0.7

Published

fan-js

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值