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

xiaoyao-js-utils

v1.1.2

Published

* 存储localStorage setStore(name, val) * 获取localStorage getStore(name) * 移除localStorage removeStore(name)

Downloads

13

Readme

  • 此库为个人记录使用,原生js,无任何依赖,对常用方法的收集整理
  • 使用 npm i xiaoyao-js-utils

本地存储

  • 存储localStorage
    setStore(name, val)

  • 获取localStorage
    getStore(name)

  • 移除localStorage
    removeStore(name)

  • 存储SessionStore
    setStore(name, val)

  • 获取SessionStore
    getStore(name)

  • 移除SessionStore
    removeStore(name)

  • 存储cookie

/**设置cookie
 * @param {cookie名}
 * @param {cookie值}
 * @param {设置cookie域}
 * @param {过期时间(天)} [varname]
 */
setCookie(name, value, domain, day)
  • 获取cookie
/**
 * 获取cookie
 * @return {[type]} [description]
 */
getCookie(name)
  • 移除cookie
/**
 * 删除cookie
 * name: 删除cookie名
 * domain: 所在的域
 */
delCookie(name, domain)

xiaoyao

  • 中文转拼音
/**
 * pinyin.getFullChars('张三');ZhangSan 张三
 * pinyin.getCamelChars('张三'); ZS 张三
 */
  • 去除字符串两端空格
/**
 * 去除字符串两端空格
 * @param {*} str
 */
xiaoyao.trim('  xx   ')   // xx
  • vw vh 转px
xiaoyao.viewportToPixels('100vw') // 100px
  • px 转vw vh
/**
 * px 转vw vh 
 * @param {Number} value 要转换的px,px省略
 * @param {Number} comparison 对比值,设计图尺寸宽或者高
 * @param {Number} type 转换为vw还是vh 0:vw  1:vh
 */
xiaoyao.pixelsToViewport(100, 100, 0)
  • 当前dom是否在当前可视区域
/**
 * 当前dom是否在当前可视区域
 * @param {Document} el 要判断的dom
 * @param {Boolean} partiallyVisible  是否部分可见也算可见  默认为True 即部分可见也算可见
 * @returns {Boolean}  
 */
xiaoyao.elementIsVisibleInViewport(el)  // true 
  • 判断当前运行环境是否是移动端,ipad也算移动端
/**
 * 判断当前运行环境是否是移动端,ipad也算移动端
 * @returns 
 */
xiaoyao.isMobile()
  • 将金额字符串按指定位数使用逗号隔开
/**
 * 将金额字符串按指定位数使用逗号隔开 调用:moneySplit("12345.675910", 3),返回12,345.676
 * @param {String} s 要隔开的字符串
 * @param {Number} n 按此指定位数隔开字符串
 * @returns {String} 返回隔开的字符串
 */
 xiaoyao.moneySplit=function(s, n=3)
  • 将金额字符串按指定位数使用逗号隔开
/**
 * 让整数自动保留2位小数
 */
returnFloat(val)
  • 时间类型转换
/**
 * @param {date} 标准时间格式:Fri Nov 17 2017 09:26:23 GMT+0800 (中国标准时间)
 * @param {type} 类型
 *   type == 1 ---> "yyyy-mm-dd hh:MM:ss.fff"
 *   type == 2 ---> "yyyymmddhhMMss"
 *   type == '' ---> "yyyy-mm-dd hh:MM:ss"
 *   type == 4 ---> "2020年03月03日"
 *
 */
formatDate(date, type)
  • 时间戳转可视时间字符串
parseToDate(20150101010101)   // '2015-01-01 01:01:01'
  • 判断传入值是否为空等
isEmpty(a)   //  undfound null 空对象  空数组 空字符串 等都算空
  • 返回两位的小数的字符串
toFixedNum(val)
  • 读取base64
readFile(file)
  • 动态插入css
/**
 * 动态插入css
 * @param {url} 要引入的css地址
 * 
 */
loadStyle(url)
  • 设置浏览器头部标题
/**
 * 设置浏览器头部标题
 */
setTitle(text)
  • 取出指定url里参数 返回object
// 取出指定url里参数 返回object
param2Obj(url)
  • 是否为正整数
//是否为正整数
isInteger(s)
  • 获取地址栏中指定参数值
/**
 *
 * @param {*} name 指定参数名
 * @return {string} 返回指定参数值(字符串)
 */
getQueryString(name)
  • 获取所有地址栏参数
/**
 * @param {*} url 取参数的地址,默认为当前访问地址
 * @return {string} 返回所有地址栏参数,键值对(字符串)
 */
GetRequest()
  • s6如何创建一个包含当前URL参数的对象
/**
 * es6如何创建一个包含当前URL参数的对象?
 * @param {*} url
 * Example:
 * getURLParameters('http://url.com/page?n=Adam&s=Smith'); // {n: 'Adam', s: 'Smith'}
 * getURLParameters('google.com'); // {}
 */
getURLParameters(url = window.location.href)
  • date转指定格式日期字符串
/**
 * @param {*} date 具体日期变量
 * @param {string} dateType 需要返回类型
 * @return {string} dateText 返回为指定格式的日期字符串
 */
getFormatDate(date, dateType = "yyyy-mm-dd MM:mm:ss")
  • 图片地址是否存在
/**
 *
 * @param {*} pathImg 图片地址是否存在
 */
validateImage('http:baidu.com/22.png')
  • 要转换的时间戳
/**
 *
 * @param {*} time 要转换的时间戳 默认当前时间
 * @return {string} dateText 返回日期字符串 2020.03.09 23:59:59
 */
getTime(time = +new Date())
  • object转url参数
Obj_url = (parmes,isnull=true)
  • 页面重定向 用于将对象传入地址栏但不刷新页面
// 页面重定向  用于将对象传入地址栏但不刷新页面
// isnull 是否认可null? 传false则过滤所有为假的值
redirect = (parmes={},isnull=true)
  • 图片下载辅助函数
/**
 * 图片下载辅助函数
 * @param {string} url 下载图片链接地址
 * @param {string} name 保存的图片名
 */
downloadByBlob(url, name)
  • 将金额字符串按指定位数使用逗号隔开
/**
 * 将 array 分成多个数组,每个数组包含length 或更少的项。
 * @param {Array} array 原数组
 * @param {Number} count 拆解条数
 * var partners = _.chunk(_.shuffle(kindergarten), 2);
 *  => [["Tyrone", "Elie"], ["Aidan", "Sam"], ["Katrina", "Billie"], ["Little Timmy"]]
 */
_chunk([1,2,3,4,5,6,7...], 3) //[[1,2,3],[4,5,6],... ]
  • 根据字段筛选更加重复数据
// 根据字段筛选更加重复数据
// json :JSON对象
// field:字段名
// isnull true 包括空的,false 不包括空的
// 返回重复的field数据
CountJson(json, field, isnull = false)
  • base64转blob
base64ToBlob(base64Data)
  • blobToFile
/**
 * @param {blob} newBlob  blob对象
 * @param {String} fileName 文件名
 */
blobToFile (newBlob, fileName)
  • 对象数组根据指定属性去重,return回 去重后的数组
/**
 * 对象数组根据指定属性去重,return回 去重后的数组
 * @param {*} arr 原始数组
 * @param {*} key 去重的key值
 */
ArrdeWeight(arr, key) 
  • 数组随机乱序算法
/**
 * 数组随机乱序算法
 * @param {*} array 
 */
 shuffle(array)
  • vw vh转px
/**
 * vw vh转px
 * @param {Srring} value
 */
viewportToPixels(value)
  • 根据指定字段返回新json
/**
 * 根据指定字段返回新json
 * @param {*} val 指定的字段名key
 * @param {Array} data 要提取的json数组
 * @param {Boolean} isArray 一个数组或多个数组 默认返回多个数组
 * @returns {Array} 返回提取出的新数组
 */
 jsonKeyToVal(val, data, isArray=false)
  • 将金额字符串按指定位数使用逗号隔开
/**
 * 将指点节点缩放
 * @param {String} name 要缩放的dom  可传class id 标签等等  等同于document.querySelectorAll(name)
 * @param {Number} scale_check 缩放倍数 默认当前宽/1920
 */
 bodyScale(name='body',scale_check=null)
  • 传入json和名字,将json保存为文件下载到本地
/**
 * 传入json和名字,将json保存为文件下载到本地
 * @param {Json} data 
 * @param {String} filename 
 */
saveJSON(data, filename)
  • 传入json类型的文件.解析返回该json
/**
 * 传入json类型的文件.解析返回该json
 * @param {File[JSON]} file 
 * @returns Object
 */
getFileJson(file)
  • 过滤出json对象中指定具有指定键值的数据
/**
 * 过滤出json对象中指定具有指定键值的数据
 * @param {JSON Array} data 
 * @param {String} key 
 * @param {String} val 
 * @returns {JSON Array} 返回所有符合条件的数据
 */
filterKeyAndValToJson(data,key,val='')
  • 自动填充数组至指定长度,若初始长度够则截取,不够则复制当前数组
/**
 * 自动填充数组至指定长度,若初始长度够则截取,不够则复制当前数组
 * @param {Array} arr 
 * @param {Number} len 
 * @returns {Array} 处理后具有指定长度的数组
 */
fillArrayToLen(arr,len)
  • 多维数组解构为一维数组
/**
 * var arr1 = [[0, 1], [2, 3], [4, 5]];
 * var arr2 = flatten(arr1); // arr2 [0, 1, 2, 3, 4, 5]
 * 优点: 多维数组也可以
 * 比如:var arr = [[1,2],3,[[[4], 5]]]
 * @param {*} arr 
 * @returns arr[]
 */
fillArrayToLen(arr,len)