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

@south-rd/south-rd-utils

v1.0.4

Published

web实用工具,包含url转换、日期格式处理、数学计算、常用正则等

Downloads

6

Readme

south-rd-utils web实用工具包

开始

安装 yarn add @south-rd/south-rd-utils

直接使用
import utils from '@south-rd/south-rd-utils'

按需使用 
import { arrays, dates, dicimals, regs, strings, urls } from '@south-rd/south-rd-utils'

数组类

// 将数组(array)拆分成多个 size 长度的区块
arrays.chunk([1,2,3], 2)
--> [ [1, 2], [3] ]

// 创建一个切片数组,去除array前面的n个元素
arrays.drop([1,2,3], 1)
--> [2, 3]

// 创建一个切片数组,去除array尾部的n个元素
arrays.dropRight([1,2,3], 2)
--> [1]

// 返回首次 value 在数组array中被找到的 索引值, 如果 fromIndex 为负值,将从数组array尾端索引进行匹配
arrays.indexOf([1,2,3,'i'], 'i1') --> -1
arrays.indexOf([1,2,3,'i'], 'i') --> 3

// 获取数组array中除了最后一个元素之外的所有元素(注:去除数组array中的最后一个元素)
arrays.initial([1,2,3,'i','w'])
--> [1, 2, 3, "i"]

日期类

时间戳转换,建议在main.js中执行

dates.format()

// 设置为当天00:00:00
dates.setAM(time<Date>)

// 设置为当天23:59:59
dates.setPM(time<Date>)

数学计算

dicimals.equals(x, y) 等于判断
dicimals.plus([x, y, ...]) 累加操作,入参类型 Array
dicimals.minus(x, y) 减法操作
dicimals.times([x, y, ...]) 累乘操作,入参类型 Array
dicimals.dividedBy(x, y) 除法操作

正则类

例子:regs.xxx.text(String)
{
  mobile: /^1\d{10}$/,
  email: /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/,
  telephone: /([0-9]{3,4}-)?[0-9]{7,8}/,
  zhCN: /^[\u4e00-\u9fa5]{0,}$/, // 汉字
  emoji: /\uD83C[\uDF00-\uDFFF]|\uD83D[\uDC00-\uDE4F]/g, // emoji表情符号
}

字符串

// 空格滤除
strings.trim('   222 666 8     ')

// 首字母大写
strings.capitalize('sakhajsdja')

// 字母小写
strings.toLower('GJHGJGJHGJGJG')

// 字母大写
strings.toUpper('sakhajsdja')

// 字符转为HTML实体字符
strings.escape('<sakhajsdja> "" \' & ')
--> &lt;sakhajsdja&gt; &quot;&quot; &#39; &amp;

url 链接参数类

获取url参数

urls.getUrlParam(name:'参数名称', path:'链接字符串(可选)', type:'截取位置:默认为hash,可传search')
--------------------------
  window.location[type]
是否为微信端
urls.isWechatBrowser() 

是否为手机端
urls.isMobileBrowser() 

encodeURIComponent URL编码
urls.encodeUrl(path<String>)

decodeURIComponent URL解码
urls.decodeUrl(path<String>)