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

qc-toolkit

v1.0.17

Published

用于常用方法收集和调用

Downloads

4

Readme

常用 utils 方法记录和调用

下载

npm i qc-toolkit

使用方法

import {
    delay,
    dateFormatting,
    set16ToRgb,
    setRgbTo16,
    arrGroup,
    arrFlatten,
    arrArchive,
    debounce,
    throttle,
    deepCloneObj,
    numTs,
    storage,
    showTime,
    checkType,
    UppercaseNum,
} from "qc-toolkit";

方法阐述详解

1、延时调用

/**
 * @description: 延时调用函数
 * @param {*} time 毫秒
 * @param {*} callback 回调方法
 * @return {*}
 */
export delay(time, callback)

2、时间格式处理

/**
 * @description:时间格式转换
 * @param {*} format 格式 示例 'Y-m-d' 为空时返回本方法支持的参数,
 * "ymd"可参考无值时返回的对象的key
 * @param {*} timestamp 时间戳 为空时默认当前时间戳
 * @return {*} 当format参数有值时,返回string 有格式的时间
 * 当format参数无值时,返回object 例如
 * {
    "d": "04",
    "D": "Wed",
    "j": 4,
    "l": "Wednesday",
    "N": 4,
    "S": "th",
    "w": 3,
    "z": 123,
    "W": 18,
    "F": "May",
    "m": "05",
    "M": "May",
    "n": 5,
    "t": 31,
    "L": 0,
    "Y": 2022,
    "y": "22",
    "a": "am",
    "A": "AM",
    "B": 179,
    "g": 11,
    "G": 11,
    "h": "11",
    "H": "11",
    "i": "18",
    "s": "54",
    "O": "+0800",
    "P": "+08:00",
    "c": "2022-05-04T11:18:54+08:00",
    "U": 1651634334
}
 */
export dateFormatting(format, timestamp)

3、颜色格式转换

a.16 进制转换成 rgb

/**
 * @description:颜色16进制转换rgb
 * @param {*} str 颜色16进制 String "#ffffff"
 * @return {*} String   rgb(255,255,255)
 */
export function set16ToRgb(str)

b. rdb 转换成 16 进制

/**
 * @description:颜色rgb转换16进制
 * @param {*} str 颜色rgb String "rgb(255,255,255)"
 * @return {*} String  颜色16进制  #ffffff
 */
export function setRgbTo16(str)

4、一维数组转 2 维数组 (分组)

/**
 * @description: 一维数组转2维数组 (分组)
 * @param {Array} arr:源数组
 * @param {Number} num: 基数 默认为2
 * @return {*}
 */
export function arrGroup (arr, num)

5、数组扁平化

/**
 * @description: 数组扁平化
 * @param {*} arr 源数组
 * @param {*} depth 扁平化深度 默认为1
 * @return {*}
 */
export  function arrFlatten(arr, depth)

6、对一维数组进行分组(根据 key)

/**
 * @description:对一维数组进行分组(根据 key)
 * @param {*} arr 源一维数组
 * @param {*} key String
 * @return {*}
 */
export function arrArchive (arr, key)

7、防抖

/**
 * @description: 防抖(事件绑定需要直接绑定返回值)
 * @param {*} callback 回调函数
 * @param {*} delay 防抖时间(毫秒)
 * @return {*} function
 */
export function debounce(callback, delay)

8、节流

/**
 * @description: 节流(事件绑定需要直接绑定返回值)
 * @param {*} callback 回调函数
 * @param {*} delay 节流时间
 * @return {*} function
 */
export function throttle(callback, delay)

9、深拷贝

/**
 * @description: 深拷贝(未处理原型链上的属性,只对对象本身的属性做拷贝)
 * @param {*} obj 源对象
 * @return {*} obj
 */
export function deepCloneObj(obj)

10、数字增加千分位分割符

/**
 * @description:数字增加千分位分割符(兼容小数)thousandSeparator
 * @param {Number,String} num
 * @param {*} points 是否强制加2位小数
 * @return {*}
 */
export function numTs(num, points)

11、localStorage 操作

storage 下有三个方法:存,取,移除
/**
 * @description:localStorage存储
 * @param {*} key 存储的key
 * @param {*} value 存储的的值
 * @return {*}
 */
const setItem = function(key, value)

/**
 * @description:localStorage获取
 * @param {*} key 存储的key
 * @return {*}
 */
const getItem = function(key)

/**
 * @description:localStorage移除
 * @param {*} key 存储的key
 * @return {*}
 */
const removeItem = function(key)

export const storage = { setItem, getItem, removeItem };

12、时间展示转化

/**
 * @description:时间展示转化,输入已过时间,输出x天前
 * @param { String } dateStr yyyy-MM-dd hh:mm:ss (2022-5-6 17:35:00)
 * 时间戳不支持
 * @return { String }
 */
export function showTime(dateStr)

13、值类型判断

/**
 * @description: 值类型判断
 * 可判断 {},[],"88",99,null,undefined,set,date,boolean,function,Symbol,Math
 * 内部使用Object.prototype.toString.call判断
 * @param {*} params
 * @return { String }
 */
export function checkType(params)

14、 数字转中文大写(金额)

/**
 * @description: 数字转中文大写(金额)
 * @param { Number,String } amount
 * @return { String }
 */
export function UppercaseNum(amount)

待补充...