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

axzo-util

v1.3.2-beta

Published

>为提高开发效率,提供了一些公用方法,方便快速开发,同时避免在项目中重复代码编写。umd格式 ### 一、使用方式

Downloads

32

Readme

axzo-util 通用库

为提高开发效率,提供了一些公用方法,方便快速开发,同时避免在项目中重复代码编写。umd格式

一、使用方式

  • 1、通过命令行引入
yarn add axzo-util
  • 2、使用方法
import { deepClone } from "axzo-util";
deepClone('copy')

二、具体方法

1、数组

主要包含一些数组常用的方法

1. 数组最大值: arrayMaxMum

| 名称 | 参数 | 返回值 | | ----------- | ------- | ------ | | arrayMaxMum | array[] | Number |

2. 数组最小值: arrayMinMum

| 名称 | 参数 | 返回值 | | ----------- | ------- | ------ | | arrayMinMum | array[] | Number |

3. 数组求和: arraySum

| 名称 | 参数 | 返回值 | | -------- | ------- | ------ | | arraySum | array[] | Number |

4. 数组对象去重: arrayDeduplication

| 名称 | 参数 | 返回值 |描述| | -------- |----------------------|---------|---| | arrayDeduplication | array[],key: 去重关键字名称 | array[] |通过for循环+filter方式实现|

5. 数组对象去重: uniqueDeduplication

| 名称 | 参数 | 返回值 | 描述 | | -------- |----------------------|---------|--------------| | uniqueDeduplication | array[],key: 去重关键字名称 | array[] | 通过reduce方式实现 |

6. 树形结构遍历查找所有父级元素id: findPatentValue

| 名称 | 参数 | 返回值 | 描述 | | -------- |--------------------------------------------------------------------------------------------|---------|-----| | findPatentValue | array[],targetId: 当前子节点ID,valueKey:可选(子节点目标标识名称。默认id),childrenKey:可选(子节点目标数组名称。默认children) | array[] | - |

7. 遍历树形结构: foreachTree

| 名称 | 参数 | 返回值 | 描述 | | -------- |-------------------------------------------------------------------|-----|-----| | foreachTree | array[],,childrenName:(子节点目标数组名称。默认children),callback: 回调Function | - | - |

8. 查找父级节点: TraceBackToParentNode

| 名称 | 参数 | 返回值 | 描述 | | -------- |-----------------------------------------------------------------------------------------------------------------------------------------|---------|-----| | TraceBackToParentNode | pid: 当前子节点ID,data:array[]当前数组,rootId:根节点id,,parentKey:可选(父节点标识名称。默认parentId),idKey:可选(子节点标识名称,默认id),childrenName:可选(子节点数组名称,默认children) | array[] | - |

9. 将数组转化为树形结构: treeDataTranslateTree

| 名称 | 参数 | 返回值 | 描述 | | -------- |-----------------------------------------------------------------------|---------|-----| | treeDataTranslateTree | array[]:源数组,id:可选(子节点唯一标识key的名称,默认id),pid: 可选(父节点标识key的名称,默认parentId) | array[] | - |

2、日期、时间

对日期时间常用处理

1. 日期时间格式化: formatToDateTime

| 名称 | 参数 | 返回值 |描述| | -------- |----------------------------------------------|-----------|---| | formatToDateTime | date: 需要格式化的日期时间,format:可选(参见dayjs格式化类型,默认:'YYYY-MM-DD HH:mm:ss') | 格式化后的日期时间 |

2. 返回指定时间戳之间的时间间隔: getTimeInterval

| 名称 | 参数 | 返回值 |描述| | -------- |----------------------------------------------|-----------|---| | getTimeInterval | startTime: 结束时间的时间戳 | 返回时间字符串 example: 10分钟前 |

3. 返回指定日期的时间戳: getTimeTamp

| 名称 | 参数 | 返回值 |描述| | -------- |---------------------------------------------|-----|---| | getTimeTamp | time: 指定日期 | 时间戳 |

4. 按不同类型格式化日期: getFormatDate

| 名称 | 参数 | 返回值 | 描述 | | -------- |-----------------------------------|---------|----------------------------------------------------------------------------------------------------------| | getFormatDate | date: 指定日期,dateType:可选(需要返回类型,默认XXXX年MM月DD日) | 具体格式化日期 | 具体支持类型:yyyy-mm-dd,yyyy.mm.dd,yyyy-mm-dd MM:mm:ss,yyyy-mm-dd MM:mm,yyyy年mm月dd日 MM:mm:ss,yyyy年mm月dd日 MM:mm |

5. 返回本周第一天的时间: getWeekFirstDay

| 名称 | 参数 | 返回值 |描述| | -------- |----------------------------------------|------|---| | getWeekFirstDay | dateType:可选 对应的格式化格式 见getFormatDate方法,默认XXXX年MM月DD日 | 具体日期 |

6. 返回本周最后一天的时间: getWeekLastDay

| 名称 | 参数 | 返回值 |描述| | -------- |----------------------------------------|------|---| | getWeekLastDay | dateType:可选 对应的格式化格式 见getFormatDate方法,默认XXXX年MM月DD日 | 具体日期 |

7. 返回本月第一天的时间: getMonthFirstDay

| 名称 | 参数 | 返回值 |描述| | -------- |----------------------------------------|------|---| | getMonthFirstDay | dateType:可选 对应的格式化格式 见getFormatDate方法,默认XXXX年MM月DD日 | 具体日期 |

8. 返回本月最后一天的时间: getMonthLastDay

| 名称 | 参数 | 返回值 |描述| | -------- |----------------------------------------|------|---| | getMonthLastDay | dateType:可选 对应的格式化格式 见getFormatDate方法,默认XXXX年MM月DD日 | 具体日期 |

9. 获取指定月份第一天和最后一天的日期: getMonthFirstAndLastDate

| 名称 | 参数 | 返回值 |描述| | -------- |-------------------------------------------------------------------------|----------------------------|---| | getMonthFirstAndLastDate | timeStamp: 指定日期时间戳, dateType:可选 对应的格式化格式 见getFormatDate方法,默认XXXX年MM月DD日 | object:{startTime,entTime} |

10. 获取日期范围类的每一天: getDayAll

| 名称 | 参数 | 返回值 |描述| | -------- |----------------------------|---------|---| | getDayAll | starDay: 开始日期, endDay:结束日期 | array[] |

11. 返回间隔时间的天数: getDateRange

| 名称 | 参数 | 返回值 |描述| | -------- |--------------------------------------------------------------------------------------|---------|---| | getDateRange | intervalDays: 间隔天数,例如:30天, bolPastTime:判断在参数date之前,还是之后,默认false,dateNow:可选,日期时间,默认当前 | array[] |

12. 返回指定时间之前一年的月份: getPassYearFormatDate

| 名称 | 参数 | 返回值 |描述| | -------- |---------------------------|------------------|---| | getPassYearFormatDate | time: 可选,默认当前时间 | array[start,end] |

13. 当天之后的不可选,不包括当天,用于日期时间选择器: disabledDate

| 名称 | 参数 | 返回值 |描述| | -------- |-------------------------------------------|---------|---| | disabledDate | time: 日期 | Boolean ||

14. 当天之后的不可选,包括当天,用于日期时间选择器: disabledDateToday

| 名称 | 参数 | 返回值 |描述| | -------- |-------------------------------------------|---------|---| | disabledDateToday | time: 日期 | Boolean ||

15. 当天之前的时间不可选,包含当天,用于日期时间选择器: disabledBeforeDayDate

| 名称 | 参数 | 返回值 |描述| | -------- |-------------------------------------------|---------|---| | disabledBeforeDayDate | time: 日期 | Boolean ||

16. 当天之前的时间不可选,不包含当天,用于日期时间选择器: disabledBeforeToDate

| 名称 | 参数 | 返回值 |描述| | -------- |-------------------------------------------|---------|---| | disabledBeforeToDate | time: 日期 | Boolean ||

3、格式化

数据格式化

1. 金额格式化,三位加逗号分割:formatMoney

| 名称 | 参数 | 返回值 | 描述 | | -------- |---------|--------|-------------| | formatMoney | num: 金额 | 格式化后的值 | num不存在时,返回- |

2. 账号脱敏:accountDesensitization

| 名称 | 参数 | 返回值 | 描述 | | -------- |---------------------------------------------------------------------|--------|-------------| | accountDesensitization | str: 需要脱敏的字符串,startLength:可选(开始脱敏的位置,默认4),endLength:可选(最后展示的位数,默认3) | 格式化后的值 | |

3. 金额转化为大写:amountConversion

| 名称 | 参数 | 返回值 | 描述 | | -------- |------------|-------|-----| | amountConversion | n: 需要转换的金额 | 转换后的值 | |

4. 截取字符串并加省略号:truncateStringAddEllipsis

| 名称 | 参数 | 返回值 | 描述 | | -------- |----------------------------|-------|-----| | truncateStringAddEllipsis | str: 需要截取的字符串,length:截取长度。 | 转换后的值 | |

5. 大小写转换:turnCase

| 名称 | 参数 | 返回值 | 描述 | | -------- |----------------------------|-------|-----| | turnCase | str: 待转换的字符串,type:类型(见描述)。 | 转换后的值 | 1-全大写 2-全小写 3-首字母大写 其他-不转换|

6. 数字超过规定大小加上加号“+”:outOfNum

| 名称 | 参数 | 返回值 | 描述 | | -------- |-------------------------|-------|-----| | outOfNum | val: 输入的数字,maxNum:数字规定界限。 | 转换后的值 | 如数字超过99显示99+ |

7. 根据阿拉伯数字,转中文大写数字:upDigit

| 名称 | 参数 | 返回值 | 描述 | | -------- |----------------------|-------|-----| | upDigit | number: 需要转换的数字(默认0) | 转换后的值 | |

8. 去除空格:trim

| 名称 | 参数 | 返回值 | 描述 | | -------- |------------------------|-------|-----| | trim | str: 原字符串,type:去除空格的位置 | 处理之后的字符串 |type 1-所有空格 2-前后空格 3-前空格 4-后空格 |

4、common,公共分类

公共分类

1. 返回文件后缀名:getSuffixName

| 名称 | 参数 | 返回值 | 描述 | | -------- |------------------|-------|-----| | getSuffixName | fileName: 传入文件名称 | 文件后缀名 | |

2. 深拷贝,支持常见类型:deepClone

| 名称 | 参数 | 返回值 | 描述 | | -------- |---------------|--------|------------------| | deepClone | values: 深拷贝的值 | 拷贝之后的值 | 支持:数组、对象、日期、基本类型 |

3. 乘法函数 防止精度丢失:multiplication

| 名称 | 参数 | 返回值 | 描述 | | -------- |------------------------|-----|-----| | multiplication | num1: 第一个数值,num2:第二个数值 | 结果 | |

4. 除法 防止精度丢失:division

| 名称 | 参数 | 返回值 | 描述 | | -------- |------------------------|-----|-----| | division | num1: 第一个数值,num2:第二个数值 | 结果 | |

5. 加法 防止精度丢失:addition

| 名称 | 参数 | 返回值 | 描述 | | -------- |------------------------|-----|-----| | addition | num1: 第一个数值,num2:第二个数值 | 结果 | |

6. 减法 防止精度丢失:subtraction

| 名称 | 参数 | 返回值 | 描述 | | -------- |------------------------|-----|-----| | subtraction | num1: 第一个数值,num2:第二个数值 | 结果 | |

5、常用类型判断

常用类型

1. 获取数据类型:typeOf

| 名称 | 参数 | 返回值 | 描述 | | -------- |-------------|---------|-----| | typeOf | target: 数据值 | 数值对应的类型 | |

2. 判断是否是object:isObject

| 名称 | 参数 | 返回值 | 描述 | | -------- |-------------|---------|-----| | isObject | target: 数据值 | Boolean | |

3. 判断是否是类对象:isObjectLike

| 名称 | 参数 | 返回值 | 描述 | | -------- |-------------|---------|-----| | isObjectLike | target: 数据值 | Boolean | |

4. 判断是否是数组:isArray

| 名称 | 参数 | 返回值 | 描述 | | -------- |-------------|---------|-----| | isArray | target: 数据值 | Boolean | |

5. 判断是否是类数组对象:isArrayLike

| 名称 | 参数 | 返回值 | 描述 | | -------- |-------------|---------|-----| | isArrayLike | target: 数据值 | Boolean | |

6. 判断是否是字符串:isString

| 名称 | 参数 | 返回值 | 描述 | | -------- |-------------|---------|-----| | isString | target: 数据值 | Boolean | |

7. 判断是否是Number:isNumber

| 名称 | 参数 | 返回值 | 描述 | | -------- |-------------|---------|-----| | isNumber | target: 数据值 | Boolean | |

8. 判断是否是Function:isFunction

| 名称 | 参数 | 返回值 | 描述 | | -------- |-------------|---------|-----| | isFunction | target: 数据值 | Boolean | |

6、本地存储

封装本地存储,localStorage,sessionStorage,通过传入配置项来判断使用哪种存储方式,如果不传入配置项,则默认使用localStorage,过期时间7天,前缀axzo

使用方式
import {useStorage} from 'axzo-utils'
const {setStorage} = useStorage({
  type: 'localStorage', // 存储类型
  prefix: 'axzo', // 前缀
  expire: 7 * 24 * 60 * 60 // 过期时间,单位秒
})
1. 判断是否支持本地存储:isSupStorage

| 名称 | 参数 | 返回值 | 描述 | | -------- |-------------|---------|-----| | isSupStorage | | Boolean | |

2. 设置本地存储:setStorage

| 名称 | 参数 | 返回值 | 描述 | | -------- |-------------------------------------|---------|-----| | setStorage | 三个参数:存储的key,存储的value,过期时间expire(可选) | | |

3. 获取本地存储:getStorage

| 名称 | 参数 | 返回值 | 描述 | | -------- |--------|------------|-----| | getStorage | 存储的key | 当前key对应的数据 | |

4. 是否存在storage:hasStorage

| 名称 | 参数 | 返回值 | 描述 | | -------- |--------|---------|-----| | hasStorage | 存储的key | boolean | |

5. 获取存储所有的key:getStorageKeys

| 名称 | 参数 | 返回值 | 描述 | | -------- |--------|-------|-----| | getStorageKeys | | array | |

6. 根据索引获取key:getStorageForIndex

| 名称 | 参数 | 返回值 | 描述 | | -------- |-----------|------------|-----| | getStorageForIndex | 索引下标index | index对应的数据 | |

7. 获取Storage长度:getStorageLength

| 名称 | 参数 | 返回值 | 描述 | | -------- |-----------|--------|-----| | getStorageLength | | number | |

8. 获取全部storage:getStorageAll

| 名称 | 参数 | 返回值 | 描述 | | -------- |-----------|-------|-----------| | getStorageAll | | array | 当前所有的本地存储 |

9. 移除本地存储:removeStorage

| 名称 | 参数 | 返回值 | 描述 | | -------- |---------------|-------|-----------| | removeStorage | 需要移除的本地存储的key | | |

10. 清空本地存储:clearStorage

| 名称 | 参数 | 返回值 | 描述 | | -------- |---------------|-------|-----------| | clearStorage | | | 清空所有的本地存储 |

11. 判断是否可用:JSON.parse

| 名称 | 参数 | 返回值 | 描述 | | -------- |-----------|---------|------------------------| | isJson | 存储的value值 | Boolean | 判断当前的值是否可用JSON.parse解析 |

12. 名称前自动添加前缀:autoAddPrefix

| 名称 | 参数 | 返回值 | 描述 | | -------- |------------|------------|-----------| | autoAddPrefix | 需要添加前缀的key | 已经添加前缀的key | |

13. 移除已添加的前缀:autoRemovePrefix

| 名称 | 参数 | 返回值 | 描述 | | -------- |------------|------------|-----------| | autoRemovePrefix | 需要移除前缀的key | 已经已经前缀的key | |

持续更新中。。。。