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

es-common-fn

v1.1.7

Published

``` npm install es-common-fn ```

Downloads

14

Readme

安装

npm install es-common-fn

导入

const esCommonFn = require('es-common-fn')
or
import esCommonFn from 'es-common-fn'

格式相关

首字母大写

const res = esCommonFn.capitalize('str')

单个单词首字母大写

const res = esCommonFn.capitalizeEveryWord('hello world!'); // 'Hello World!'

删除字符串中的 HTMl 标签

const res = esCommonFn.stripHTMLTags('<p><em>Hello</em> <strong>World</strong></p>'); // 'Hello World!'

驼峰转下划线

const res = esCommonFn.hump2Line('strExample')

下划线转驼峰

const res = esCommonFn.line2Hump('str_example')

格式化金钱

// 格式化金钱,每千分位加逗号
const res = esCommonFn.moneyThousands("1234567")
// res='1,234,567'

文件大小的单位转换

const res = esCommonFn.convertFileSize(1, 'MB', 'KB', 2)
// res = 1024.00 KB

RGB 转 Hex

const res = esCommonFn.rgb2Hex(255, 255, 255) // '#ffffff'

Hex 转 RGB

const res = esCommonFn.hex2Rgb(#ffffff) // '#ffffff'

数组相关

二维数组去重

const res = esCommonFn.DeduplicateArr2([[1,2],[1,2]]) // [1,2]

根据数组某个属性去重

const res = esCommonFn.uniqueBy(arr, propName)

全排列

const res = esCommonFn.getFullPerm([1,2,3]) // 省略第二个参数默认从index为0开始全排列 [[ 1, 2, 3 ],[ 1, 3, 2 ],[ 2, 1, 3 ],[ 2, 3, 1 ],[ 3, 2, 1 ],[ 3, 1, 2 ]]
const res = esCommonFn.getFullPerm([1,2,3],1) // [ [ 1, 2, 3 ], [ 1, 3, 2 ] ]

对象相关

判断对象是否为空

const res = esCommonFn.isEmptyObj(obj) // true / false

深拷贝

const res = esCommonFn.deepCopy(obj)

浏览器相关

检查是否为浏览器环境

esCommonFn.isBrowser(); // true (browser) / false (Node)

检查浏览器联网状态

esCommonFn.isBrowserOnline(); // true / false

监听&移除浏览器联网状态

// 定义联网和断网时执行的函数
const onlineFn = () => {}
const offlineFn = () => {}
// 添加监听
esCommonFn.watchOnlineStatus(onlineFn, offlineFn)
// 移除监听
esCommonFn.removeOnlineStatus(onlineFn, offlineFn)

判断手机类型

esCommonFn.getMobileType() // "Android" / "iOS"

获取任一元素的任意属性

esCommonFn.getStyle(elem, prop)

判断元素有没有子元素

esCommonFn.hasChildrenEle(elem)

带参数跳转到对应页面并打开新窗口

esCommonFn.openNewWindow(Router, routerName, query)

函数相关

防抖

esCommonFn.debounce(fn, delay)

节流

esCommonFn.throttle(fn, delay)

复制文本到粘贴板

esCommonFn.copyToClipboard('this is a test')

生成随机字符串(英文字母大小写+数字)

const res = esCommonFn.generateRandomString(8)

生成随机颜色(16进制)

const res = esCommonFn.getRandomColor()

UUID 生成 - 版本号 4

const res = esCommonFn.generateUUID()

正则表达式

是否带有小数

esCommonFn.isDecimal('12.1') // true

校验是否中文名称组成

esCommonFn.isChineseText('你好') // true

校验电话码格式

esCommonFn.isPhoneNum('13912345678') // true

校验邮件地址是否合法

esCommonFn.IsEmail('[email protected]') // true

替换特殊字符为自定义字符,默认为空

const res = esCommonFn.speCharRep("@12#", 'A') // A12A