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

ysx-utils

v1.0.1

Published

常用方法

Readme

单一工具函数导出

  • 验证类型函数
    validate 函数使用object.prototype.toString.call()进行类型判断更为准
    返回值为object, Array,String,Number,Boolean,Function,Undefined,Null,Symbol等类型
    import { validate } from 'ysx-utils'
    validate(0) // Number
  • 对象类型判断
    import { isObject } from 'ysx-utils'
    isObject({}) // true
  • 数组判断
    import { isArray } from 'ysx-utils'
    isArray([]) // true
  • safari 浏览器下日期格式兼容
    import { iosDateFormat } from 'ysx-utils'
    iosDateFormat('2021-05-29') // 2021/05/29
  • 字符串类型判断
    import { isString } from 'ysx-utils'
    isString('isString') // true

utils工具类方法

  • 文件下载创建a标签(downloadFile)
    import YsxUtils from 'ysx-utils'
    YsxUtils.downloadFile('文件名称','文件数据')
  • 时间大小比较 (compareDate)
    介绍:接收两个参数 currentDate 与 compareDate 比较currentDate是否小于等于compareDate,
    currentDate与compareDate为对象类型{value,utc,format} utc(传入时间是否是utc格式) 默认值为true,format(默认值YYYY-MM-DD HH:mm:ss)日期格式
    import YsxUtils from 'ysx-utils'
    YsxUtils.compareDate({ value:  new Date(), utc: false, format: 'YYYY-MM-DD HH:mm:ss' },{ value:  new Date(), utc: false, format: 'YYYY-MM-DD HH:mm:ss' }) // true
  • 时间格式处理 (setTimeFormat)
    import YsxUtils from 'ysx-utils'
    /**
    * @description: 时间格式处理,默认转换为utc格式
    * @param {String} time -- 待处理的时间
    * @param {String} tiemFormat -- 时间格式
    * YYYY	2015	4 digit year
      M MM	0..12	Month number
      D DD	0..31	Day of month
      H HH	0..23	24 hour time
      h hh	1..12	12 hour time used with a A.
      a A	am pm	Post or ante meridiem
      m mm	0..59	Minutes
      s ss	0..59	Seconds
      @param {Boolean} utc -- 待处理的时间
    */
    YsxUtils.setTimeFormat(new Date(),'YYYY-MM-DD', true ) '2020-05-29'
  • utc时间转本地时间 (formatUtc)
    import YsxUtils from 'ysx-utils'
    /**
    * @description: utc时间转本地时间
    * @param {String} time -- 待处理的时间
    * @param {String} tiemFormat -- 时间格式
    * YYYY	2015	4 digit year
      M MM	0..12	Month number
      D DD	0..31	Day of month
      H HH	0..23	24 hour time
      h hh	1..12	12 hour time used with a A.
      a A	am pm	Post or ante meridiem
      m mm	0..59	Minutes
      s ss	0..59	Seconds
    */
    YsxUtils.formatUtc(new Date(),'YYYY-MM-DD')
  • 本地上传图片获取base64(getLocalFileBase64)
      import YsxUtils from 'ysx-utils'
      /**
     * @description: 获取本地图片base64
      * @param {Object} file blob [input:file].files[0]
      * @return { String }  base64
      */
      YsxUtils.getLocalFileBase64(file) // base64
  • 获取图片对象 (getImageMsg)
      import YsxUtils from 'ysx-utils'
      /**
       * @description: 获取图片对象
       * @param { String } url -- 图片地址
       * @param { String } crossOrigin -- 图片请求跨域设置 anonymous  use-credentials(加了cros的验证)
       * @return { Object } -- Image 对象
       */
      YsxUtils.getImageMsg(url, crossOrigin) // base64
  • canvas方式获取网络图片base64 (getBase64Image)
      /**
       * @description: canvas方式获取网络图片base64
       * @param {*} img 图片对象 即  ImageMsg
       * @param {*} width 图片宽
       * @param {*} height 图片高
       */
      YsxUtils.getBase64Image(img, width, height) // base64
  • 对象,数组 判空 (isEmpty)
      /**
       * @description: 判空
       * @param {any} params 需要判空的数据
       * @return {Boolean} 结果
       */
      YsxUtils.isEmpty([]) // true
  • 数组对象去重(arrayReport)
      /**
       * @description: 数组对象去重
       * @param {Array} obj 需要去重的数组对象
       * @param { String } key 对象去重的依靠值 数据格式为对象时,必须
       * @return {Array} 去重后的数组
       */
      YsxUtils.arrayReport([])
  • 数组 || 或者数组对象判断重复 (isReport)
  /**
   * @description: 数组 || 或者数组对象判断重复 
   * @param {Array} obj 需要去重的数组对象
   * @param { String } key 去重的依靠值
   * @return {Array} 去重后的数组
   */
  YsxUtils.isReport([])
  • 获取url参数(getQueryString)
  /**
   * 获取url参数
   * @param       {string}     name[key]
   * @return      {string}     name->value
   * */
  YsxUtils.getQueryString(需要获取的参数名称)
  • 数组扁平化 arr 多维数组(Arrayflat)
  /**
   * 数组扁平化 arr 多维数组
   * @param  {Array}     [[],[[],[]]]
   * */
  YsxUtils.Arrayflat([[],[[],[]]])
  • 深拷贝(cloneObject)
  /**
   * 数组扁平化 arr 多维数组
   * @param  {Array || Object} [],{}
   * */
  YsxUtils.cloneObject(param)
  • 单位转换 'b', KB, M, G(unitFormat)
  /**
   * @description: 单位转换 'b', KB, M, G
   * @param { Number} data - 文件大小 字节
   * @param {Boolean } toUpperCase  - 大小写转换
   */
  YsxUtils.unitFormat(data, toUpperCase = true)