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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@xw-ui/utils

v0.0.7

Published

工具库,日期,加解密,Session,通用等

Readme

安装

#npm
npm i @xw-ui/utils

# or yarn
yarn add @xw-ui/utils

# or pnpm
pnpm add @xw-ui/utils

使用

// 按需引入
import {addDate} from '@xw-ui/utils'

// 引入全部
import * as utils from '@xw-ui/utils'

函数介绍

日期函数

/**
 * 日期加减天数
 * @param date 日期 yyyy-MM-dd
 * @param days ± 值,例如 1 或 -1
 * @returns 返回加减之后的日期,格式 yyyy-MM-dd
 */
  addDate,
/**
 * 判断当前时间是否在startTime-endTime区间中
 * 使用 checkTime('08:00', '20:00')
 * @param startTime hh:mm,例 08:00
 * @param endTime hh:mm,例 20:00
 * @returns boolean
 */
  checkTime,
/**
 * 将yyyyMMdd(20180808)转yyyy-MM-dd(2018-08-08)
 * @param str 字符,例如 20180808
 * @returns 字符 2018-08-08
 */
  date8To12,
/**
 * 日期相减
 * @param {*} date1 yyyy-MM-dd
 * @param {*} date2 yyyy-MM-dd
 * @returns day 天数
 */
  dateDiff,
/**
 * 将日期转化为字符串
 * @param time 日期格式,例如 2024-08-08 08:12:25
 * @param format 转化格式 yyyy-MM-dd hh:mm:ss
 * @returns 返回日期字符传
 */
  dateFormat,
/**
 * 
 * @param {number} time
 * @param {string} option yyyy-MM-dd
 * @returns {string}
 */
  formatTime,
/**
 * 获取 时间戳或当前日期
 * @param type start或空
 * @returns 返回日期或时间戳
 */
  getTime,
/**
 *  将hhmmss(124508)转 hh:mm:ss(12:45:08)
 * @param str  hhmmss000
 * @returns hh:mm:ss
 */
  time6To8,
/**
 * yyyyMMddhhmmss 转为 yyyy-MM-dd hh:mm:ss
 * @param str  yyyyMMddhhmmss
 * @returns yyyy-MM-dd hh:mm:ss
 */
  timeFormat,

加解密

/**
 * 加密处理
 * @param params 参数={data,type,param,key},type=Base64 | null
 * @returns 
 */
  encryption,
/**
 * 解密处理
 * @param params 参数={type,param,key},type=Base64 | null
 * @returns 
 */
  decryption,

数据字典

/**
 * 将SYS_IF 转成 sysIf
 * @param str SYS_IF
 * @return sysIf
 */
  formatField,
/**
 * 获取字典label值
 * @param value 值
 * @param options 数组[{value,string}]
 * @returns label 值
 */
  getOptionLabel,
/**
 * 获取字典value 值
 * @param label 值
 * @param options 数组
 * @returns value值
 */
  getOptionValue,
/**
 * 字典 获取Item
 * @param value 值
 * @param options 字典Array
 * @param key 默认'value'
 * @returns 对象{value,label,...}
 */
  getOptionItem,

auth 工具库,处理cookie,session,localStorage

/**
 * env 配置 
 * VITE_ACCESS_TOKEN 默认 x-access-token 
 * VITE_SESSION_KEY 默认 va
 * 获取token x-access-token
 * @returns 
 */
  getToken,
/**
 * 获取localStorage
 * @param params {name}
 * @returns 对象
 */
  getStore,
/**
 * 删除localStorage
 * @param params {name}
 */
  removeStore,
/**
 * 移除token
 */
  removeToken,
/**
 * 存储 store
 * @param params {name,content,type,datetime}
 */
  setStore,
/**
 * 设置token
 * @param token 
 */
  setToken,

处理文件(Excel,下载)

/**
 * 下载文件流
 * @param {*} blob
 * @param {*} fileName
 * @returns
 */
  downloadBlob,
/**
 * 下载文件
 * @param url 
 * @param filename 
 */
  downloadFile,
/**
 * 下载txt
 * @param {*} url
 * @param {*} filename
 */
  downloadTxt,
/**
 *导入Excel解析
 * @param {*} obj this.$refs.imFile ,obj.range 默认0,跳过Excel行数
 * @param {*} callback 回调函数(list)
 * obj.jrjgbm = item['金融机构编码'] ? item['金融机构编码'] : ''
 */
  excelToJson,
/**
 * 导出Excel获取blob
 * @param {*} response
 * @param {*} callback({ blob, name, type })
 */
  getBlob,

校验

/**
 * 判断数组
 * @param {Array} arg 数组
 * @returns boolean
 */
  isArray,
/**
 * 判断地址是否有http,mailto,tel
 * @param path 地址字符串
 * @returns boolean
 */
  isExternal,
/**
 * 判断是否图片
 * @param {*} url 图片地址
 * @returns boolean
 */
  isImage,
/**
 * 判断是字符
 * @param str
 * @returns boolean
 */
  isString,
/**
 * 是否有效字母
 * @param str 字符串
 * @returns boolean
 */
  validAlphabets,
/**
 * 校验email地址
 * @param email
 * @returns boolean
 */
  validEmail,
/**
 * 是否有效小写
 * @param str 字符串
 * @returns boolean
 */
  validLowerCase,
/**
 * 校验http,https,ftp地址
 * @param  url http,ftp地址
 * @returns boolean
 */
  validURL,
/**
 * 是否有效大写
 * @param str 字符串
 * @returns boolean
 */
  validUpperCase,
/**
 *  判断是否为空
 * @param val 字符,数组,对象
 * @returns boolean
 */
  validateNull

通用

/**
 * Add class to element
 * @param {HTMLElement} elm
 * @param {string} cls
 */
addClass,
/**
 *  the byte length of an utf8 string
 * @param {string} input value
 * @returns {number} output value
 */  
  byteLength,
/**
 * 清空数组
 * @param actual 数组
 * @returns 数组
 */
  cleanArray,
/**
 * 生成唯一字符
 * @returns 字符串
 */
  createUniqueString,
/**
 * @param {Function} func
 * @param {number} wait
 * @param {boolean} immediate
 * @return {*}
 */  
  debounce,
/**
 * This is just a simple version of deep copy
 * Has a lot of edge cases bug
 * If you want to use a perfect deep copy, use lodash's _.cloneDeep
 * @deprecated 请使用deepCopy
 * @param {Object} source
 * @returns {Object}
 */
  deepClone,
/**
 * 深拷贝
 * @param data 对象或数组
 * @returns 对象或数组
 */
  deepCopy,
/**
 * 获取url地址参数
 * @param url地址
 * @returns 参数对象
 */
  getQueryObject,
/**
 * 传身份证,获取对应类型值
 * @param idCard
 * @param type age 年龄,date 出生日期,sex 性别
 * @returns 
 */
  getValueByCertId,
/**
 * Check if an element has a class
 * @param {HTMLElement} elm
 * @param {string} cls
 * @returns {boolean}
 */
  hasClass,
/**
 * html2Text
 * @param val
 * @returns 字符
 */
  html2Text,
/**
 * Number formatting
 * like 10000 => 10k
 * @param {number} num
 * @param {number} digits
 */
  numberFormatter,
/**
 * Merges two objects, giving the last one precedence
 * @param {Object} target
 * @param {(Object|Array)} source
 * @returns {Object}
 */
  objectMerge,
/**
 * 对象转&连接的字符
 * @param json 对象
 * @returns key1=v1&k2=v2
 */
  param,
/**
 * 字符url转对象
 * @param {string} url 字符
 * @returns 返回对象
 */
  param2Obj,
/**
 * Remove class from element
 * @param {HTMLElement} elm
 * @param {string} cls
 */
  removeClass,
/**
 * 替换字符
 * @param {*} str 字符串
 * @param {*} char 需替换字符
 * @param {*} nChar 新字符
 * @returns 新字符串
 */
  replaceChar,
/**
 * 10000 => "10,000"
 * @param {number} num
 */
  toThousandFilter,
/**
 * @param {HTMLElement} element
 * @param {string} className
 */
  toggleClass,
/**
 * 判断类型
 * @param {*} obj 传入的参数 any
 * @returns boolean | number | string | function | array | date | regExp | undefined | null | object
 */
  typeOf,
/**
 * 数组去重
 * @param arr 数组
 * @param isObject 是否[{k1:v},{k1:v}],默认 false
 * @returns 去重之后的数组
 */
  uniqueArr,
/**
 * Upper case first char
 * @param {String} string
 */
  uppercaseFirst,

页面拷贝(改变页面name值,props传递参数)

/**
 * 将指定组件设置自定义名称
 * @param {Object} params={name:string,props:any} 组件自定义名称
 * @param {AsyncComponent} asyncComponent 拷贝组件
 * @return {Component} 返回组件
 * 使用 例子:createCustomComponent({name:'logs'},import('./test.vue'))
 */
createCustomComponent,

更新日志

  • 0.0.4

加入页面拷贝

  • 0.0.3

补充文档

  • 0.0.2

加入“字典”和“加解密” 函数

  • 0.0.1

补充使用文档

  • 0.0.0

初始