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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@luomuxiaoxiao/common-methods

v1.0.31

Published

编写一些简单的常用方法,方便后期直接拉取使用。

Downloads

4

Readme

common-methods

编写一些简单的常用方法,方便后期直接拉取使用。

deepClone

函数说明

深拷贝数据,支持:对象、数组、函数、Date、正则、Set、Map、循环引用

入参

| 参数名称 | 参数类型 | 是否必填 | 参数说明 | | -------- | -------- | -------- | ---------- | | target | any | 是 | 被拷贝的数据 | | hash | WeakMap | 否 | WeakMap,用于存储循环引用数据的关联性 |

示例

let oraginData = { a: {name:'aaa'}, b: ["b","bb",["bbb"],{bb:"bbbb"}] }
let newData = toLowerCase(oraginData)

getTimeRange

函数说明

获取从n天前到m天前的时间范围,可为负数

入参

| 参数名称 | 参数类型 | 是否必填 | 参数说明 | | -------- | -------- | -------- | ---------- | | dataStart| number | 是 | 从dataStart天前开始 | | dataEnd | number | 否 | 到dataEnd天前结束。可选,默认0 | | format | string | 否 | 自定义格式 。可选 默认YYYY-MM-DD HH:mm:ss |

示例

getTimeRange(10);  // 10天前到今天的时间范围
getTimeRange(10, 2, 'YYYY-MM-DD HH:mm:ss');  // 10天前到2天前的时间范围
getTimeRange(10, 2, 'YY-MM-DD');             // 10天前到2天前的简化时间范围
getTimeRange(10, 2, 'MMM D, YYYY');          // 10天前到2天前的详细时间范围

formatDate

函数说明

格式化时间

入参

| 参数名称 | 参数类型 | 是否必填 | 参数说明 | | -------- | -------- | -------- | ---------- | | date | Date 、 string 、 number | 是 | 需要格式化的时间 | | format | string | 否 | 自定义格式 。可选 默认YYYY-MM-DD HH:mm:ss |

示例

formatDate(new Date());  // 2020-06-23 15:30:00
formatDate(new Date(), 'YYYY-MM-DD HH:mm:ss');  // 2020-06-23 15:30:00
formatDate(new Date(), 'YY-MM-DD');             // 20-06-23
formatDate(new Date(), 'MMM D, YYYY');          // Jun 23, 2020
formatDate(1722050240622);  // 2024-07-27 11:17:20


formatDate('2020-06-23');  // 2020-06-23 08:00:00

selectFile

函数说明

选择文件,拉起文件选择器,选择文件,可指定文件类型和是否允许多选;

选择文件后,FileList类型数据 如果取消选择,返回null

入参options

| 参数名称 | 参数类型 | 是否必填 | 参数说明 | | -------- | -------- | -------- | ---------- | | accept | string | 否 | 指定文件类型 直接指定文件类型:'.jpg,.xls,.txt',所有图像文件:'image/* 、PDF文件:'application/pdf'... | | multiple | boolean | 否 | 是否允许多选,默认为true |

示例

async function gotoSelectFile() {
  //  获取图片类型文件,允许多选
  let res = await selectFile({
    accept: 'image/*',
    multiple: true,
  })
  console.log(res)
}

copyText

函数说明

复制文本内容,异步方法,返回布尔值,表示是否复制成功。

入参options

| 参数名称 | 参数类型 | 是否必填 | 参数说明 | | -------- | -------- | --------| ---------- | | text | string | 是 | 需要复制的文本内容 |

示例

  let isCopyOK = await copyText('1233211234567')
  if(isCopyOK) {
    console.log('复制成功')
  }