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

cx-common-util

v1.0.7

Published

cx common util

Downloads

2

Readme

cx-common-utils

内部公共类库

目录介绍

src - 工具函数
test - 测试用例

安装

npm i cx-common-utils

使用

import { dateFormat } from "cx-common-utils"

本地开发调试

npm install

npm run dev

如提示 “Failed to load plugin @typescript-eslint declared in .eslintrc” 错误请将node升级到更高版本,比如 16.17.1。

打包

npm run build

工具函数

dateFormat - 获取指定格式日期
    @param {(number | object)} date - 可以传入毫秒数、new Date对象
    @param {string=} connector - 连接符,默认为 "-",可以传入 "." or "/"
    @returns {string} 返回yyyy-mm-dd/yyyy.mm.dd等自定义格式日期字符串

getDatePeriod - 获取基于当前时间的一段时间的数组
    @param {number} start - 当前日期的前N天,比如获取前10天,传-10,未来3天,传3,要求比end小,否则返回值为[]
    @param {number} end - 当前日期的后N天,比如获取后10天,传10,未来3天,传3,要求同上
    @param {string=} connector - 连接符,默认为 "-",可以传入 "." or "/"
    @returns {Array<string>} 返回范围内所有日期的数组

getDateRange - 获取基于指定时间(默认today)的两个具体时间点
    @param {(number | string)} type 传入需要获取的类型 1-本周 2-上周 3-本月 4-上月
    @param {(number | string | Object)} date 指定日期,支持毫秒数、yyyy-mm-dd字符串、Date对象
    @param {string=} connector - 连接符,默认为 "-",可以传入 "." or "/"
    @returns {Array<string>} 返回yyyy-mm-dd格式数组

moneyFormat - 对一串数字进行每三位添加分隔符
    @param {number} money 传入需要格式化的钱或数字,数字格式
    @param {number} n 包含小数时,需要保留的位数, money为整数时不传,小数时必传
    @returns {string} 返回格式化后的字符串

checkType - 判断并返回数据类型
    @param {any} target - 传入需要判断类型的
    @returns {string} 返回类型

fuzzyQuery - 模糊匹配
    @param {Array<any>} list - 需要过滤的数组
    @param {string} keyWord - 过滤关键词
    @param {string} attribute - 过滤的字段名
    @returns {Array<any>} 返回匹配的数组

scrollToTarget - 滚动到指定元素位置
    @param {string} element - 元素的class或id ('.test' / '#id')
    @returns {void} 滚动到指定位置。注意:方法会滚动元素的父容器,请正确使用,如果页面不存在滚动条则无效

uniqueArrayByKey - 根据指定字段去掉数组中重复数据
    @param {Array} arr - 需要去重的数组
    @param {string} key - 依据过滤条件的字段名
    @returns {Array<any>} 返回过滤后的数组数组

handlePhone - 手机号脱敏
    @param {string} phone - 手机号字符串,必传
    @param {boolean=} hide - 是否隐藏,可选,默认true
    @returns {string} 处理结果

forEachTree - 遍历树形数据
   @param {Array<any>} data - 数据树
   @param {callback} callback - 对遍历的每一项处理的回调,参数为遍历项
   @param {string=} childrenName - children字段名,不传默认为 children
   @returns {any} any:视自己需求而定