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

uvalid

v1.1.6

Published

**多位前端开发工程师多年积累的工具函数**

Downloads

19

Readme

多位前端开发工程师多年积累的工具函数

  1. 匹配正整数
console.log(isPositiveNum(9)) //true
console.log(isPositiveNum(2.2)) //false
  1. 匹配负整数
 console.log(isNegativeNum(-9)) //true
 console.log(isNegativeNum(2.2)) //false
  1. 匹配整数
console.log(isInteger(-9)) //true
console.log(isInteger(2.2)) //false
  1. 匹配非负浮点数
console.log(isNotNegativeFloatNum(-9)) //false
console.log(isNotNegativeFloatNum(2.2)) //true
  1. 匹配由 26 个英文字母组成的字符串
console.log(isAZaz('122a')) //false
console.log(isAZaz('abc')) //true
  1. 匹配由 26 个英文字母的大写组成的字符串
console.log(isAZ('Acs')) //false
console.log(isAZ('ABC')) //true
  1. 匹配由 26 个英文字母的小写组成的字符串
console.log(isaz('Acs')) //false
console.log(isaz('abc')) //true
  1. 匹配电子邮件地址
console.log(isEmailAddress('Acs')) //false
console.log(isEmailAddress('[email protected]')) //true
  1. 返回数组中的最大值
console.log(arrayMax(arr)) //5
  1. 返回数组中的最小值
console.log(arrayMin(arr)) //1
  1. 将数组块划分为指定大小的较小数组
let arr = [1, 2, 3, 5];
console.log(chunk(arr,2)) //0: Array [ 1, 2 ],1: Array [ 3, 5 ],
  1. 从数组中移除 false 值
let arr = [false,null,0,"",undefined,NaN,1]
console.log(compact(arr)) //[ 1 ]
  1. 计算数组中值的出现次数
let arr = [1,2,1,2,3,3,3,3];
console.log(countOccurrences(arr,3))//4
  1. 深拼合数组
let arr = [1, 2, [1, 2, [1, 2, [2, 3]]]];
console.log(deepFlatten(arr)) // [ 1, 2, 1, 2, 1, 2, 2, 3 ]
  1. 返回两个数组之间的差异
let arr = [1,2,3];
let arr2 = [2,3,4];
console.log(difference(arr,arr2))//[1]
console.log(difference(arr2,arr))//[4]
  1. 返回数组的所有不同值
let arr = [1, 2, 3, 1, 2];
console.log(distinctValuesOfArray(arr)) // [ 1, 2, 3 ]
  1. 返回数组中的每个第 n 个元素
let arr = [1,2,3,4,5]
console.log(everyNth(arr, 3))
  1. 筛选出数组中的非唯一值
let arr = [1,2,2,3,4,5]
console.log(filterNonUnique(arr))
  1. 拼合数组
ler arr = [1,[2,3,4], 4]
console.log(flatten(arr))
  1. 将数组向上拼合到指定深度
ler arr = [1,[2,3,4], 4]
console.log(flattfalttenDepthen(arr, 1))
  1. 根据给定函数对数组元素进行分组

groupBy(arr, func)

  1. 返回列表的头
console.log(head([1,2,3,4]))
  1. 返回除最后一个数组之外的所有元素
console.log(initial([1,2,3,4]))
  1. 初始化并填充具有指定值的数组
console.log(initializeArrayWithRange(0, 10))
  1. 初始化并填充具有指定值的数组
console.log(initializeArrayWithValues(10, 2))
  1. 返回两个数组中存在的元素的列表
console.log(intersection([1,2,3,4], [1,1,2,3]))
  1. 返回数组中的最后一个元素
console.log(last([1,2,3,4]))
  1. 使用函数将数组的值映射到对象, 其中键值对由原始值作为键和映射值组成
let arr = [1,10,3,4]
let res = mapObject(arr, (n) => {
    return n
})
console.log(res) // { '1': 1, '3': 3, '4': 4, '10': 10 }
  1. nthElement: 返回数组的第 n 个元素
console.log(nthElement([1,2,3,4], 2))
  1. 从对象中选取对应于给定键的键值对
pick({a:1, b:2}, ["a", "b"])
  1. 对原始数组进行变异, 以筛选出指定的值
let arr1 = [1,2,3,4,5]
pull(arr1, 1, 2)
console.log(arr1)
  1. 从数组中移除给定函数返回false的元素
remove(arr, func: Boolean)
  1. 返回数组中的随机元素
sample([1,2,3,4,5])
  1. 随机数组值的顺序
shuffle([1,2,3,4,5])
  1. 返回两个数组中都显示的元素的数组
similarity([1,2,3,4], [2,3,4,5])
  1. 返回两个数组之间的对称差
symmetricDifference([1,2,3,4], [1,2,5,4,6])
  1. 返回数组中的所有元素, 除第一个
console.log(tail([1,2,3,4]))
  1. 返回一个数组, 其中 n 个元素从开始处移除
console.log(take([1,2,3,4,5], 2))
  1. 返回一个数组, 其中 n 个元素从末尾移除
console.log(takeRight([1,2,3,4], 3))
  1. 返回在两个数组中的任意一个中存在的每个元素
console.log(union([1,2,3,4], [1,2,3,4,5]))
  1. 筛选出数组中具有指定值之一的元素
console.log([1,2,3,4,5], 2,3)
  1. 创建基于原始数组中的位置分组的元素数组
console.log(zip(...[1,2,3,4]))
  1. 从给定数组中移除一项
removeArrayItem([1,2,3,4], [2])
  1. 检查给定数组中是否包含某项
contains([1,2,3,4,5], 4)
  1. 验证不能包含字母
isNoWord("1234")
  1. 验证中文和数字
isCHNAndEN("你好世界123")
  1. 验证邮政编码(中国)
isPostcode("1234")
  1. 验证微信号,6至20位,以字母开头,字母,数字,减号,下划线
console.log(isWeChatNum("xfy196_11"))
  1. 验证16进制颜色
isColor16("#ffffff")
  1. 验证火车车次
isTrainNum("D1234")
  1. 验证手机机身码(IMEI)
isIMEI("123456")
  1. 验证必须带端口号的网址(或ip)
isHttpAndPort("https://www.baidu.com:8080")
  1. 验证统一社会信用代码
isCreditCode("1111")
  1. 验证迅雷链接
isThunderLink("dasd")
  1. 验证ed2k链接(宽松匹配)
ised2k("")
  1. 验证磁力链接(宽松匹配)
isMagnet("")
  1. 验证子网掩码
isSubnetMask("")
  1. 验证linux"文件夹"路径
isLinuxFolderPath("")
  1. 验证linux"文件"路径
isLinuxFilePath("")
  1. 验证window"文件夹"路径
isWindowsFolderPath("")
  1. 验证window下"文件"路径
isWindowsFilePath("")
  1. 验证股票代码(A股)
isAShare("")
  1. 验证版本号格式必须为X.Y.Z
isVersion("")
  1. 验证视频链接地址(视频格式可按需增删)
isVideoUrl("")
  1. 验证图片链接地址(图片格式可按需增删)
isImageUrl("")
  1. 验证银行卡号(10到30位, 覆盖对公/私账户, 参考微信支付)
isAccountNumber("")
  1. 验证中文姓名
isChineseName("")
  1. 验证英文姓名
isEnglishName("")
  1. 验证车牌号(新能源)
isLicensePlateNumberNER("")
  1. 验证车牌号(非新能源)
isLicensePlateNumberNNER("")
  1. 验证车牌号(新能源+非新能源)
isLicensePlateNumber("")
  1. 验证手机号中国(严谨), 根据工信部2019年最新公布的手机号段
isMPStrict("")
  1. 验证手机号中国(宽松), 只要是13,14,15,16,17,18,19开头即可
isMPRelaxed("")
  1. 验证email(邮箱)
isEmail("")
  1. 验证座机电话(国内),如: 0341-86091234
isLandlineTelephone("")
  1. 验证身份证号(1代,15位数字)
isIDCardOld("")
  1. 验证身份证号(2代,18位数字),最后一位是校验位,可能为数字或字符X
isIDCardNew("")
  1. 验证身份证号, 支持1/2代(15位/18位数字)
isIDCard("")
  1. 验证护照(包含香港、澳门)
isPassport("")
  1. 验证帐号是否合法(字母开头,允许5-16字节,允许字母数字下划线组合
isWebAccount("")
  1. 验证中文/汉字
isChineseCharacter("")
  1. 验证数字
isNumber(2)
  1. 验证qq号格式
isQQNum("")
  1. 验证数字和字母组成
isNumAndStr("")
  1. 验证英文字母
isEnglish("")
  1. 验证大写英文字母
isCapital("")
  1. 验证小写英文字母
isLowercase("")