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

cafe-utils

v1.0.25

Published

一个简单的函数库

Downloads

8

Readme

Cafe-Utils

build NPM version Coverage Status last commit license

使用

NPM

npm i cafe-utils

在项目中引用:

// 单独引用
import { uuid } from 'cafe-utils';
uuid();

// 整体引用
import * as cafeUtils from 'cafe-utils';
cafeUtils.uuid();

CDN

<script src="https://unpkg.com/cafe-utils/lib/utils.umd.min.js"></script>
<!-- 或者 -->
<script src="https://cdn.jsdelivr.net/npm/cafe-utils/lib/utils.umd.min.js"></script>

在项目中使用:

cafeUtils.uuid()

Jest功能覆盖

File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
--------------------|---------|----------|---------|---------|---------------------- All files | 94.88 | 83.33 | 88.17 | 94.12 |
depend | 100 | 100 | 100 | 100 |
numToString.ts | 100 | 100 | 100 | 100 |
modules | 94.86 | 83.2 | 88.11 | 94.08 |
array.ts | 100 | 100 | 100 | 100 |
cookies.ts | 100 | 80 | 100 | 100 | 46-57 date.ts | 100 | 100 | 100 | 100 | dom.ts | 40 | 0 | 0 | 28.57 | 15-17,27,37-39,50-53 event.ts | 30.77 | 7.69 | 22.22 | 28 | 16-27,42-49,64-71
floatCalculate.ts | 100 | 100 | 100 | 100 | index.ts | 100 | 100 | 86.25 | 100 | money.ts | 98.51 | 94.59 | 100 | 98.36 | 115 number.ts | 100 | 100 | 100 | 100 | storage.ts | 100 | 100 | 100 | 100 | string.ts | 100 | 94.29 | 100 | 100 | 71-90 tools.ts | 100 | 97.5 | 100 | 100 | 90 type.ts | 100 | 100 | 100 | 100 | validator.ts | 100 | 100 | 100 | 100 |

现有方法

类型判断

  1. isObject:判断对象类型
  2. isArray:判断数组类型
  3. isDate:判断日期类型
  4. isNumber:判断数字类型
  5. isString:判断字符串类型
  6. isBoolean:判断布尔类型
  7. isFunction:判断函数类型
  8. isNull:判断空类型

表单验证

  1. isPhone:判断手机号
  2. isTel:判断固定电话
  3. isZIPCode:判断邮政编码
  4. isEmail:判断邮箱
  5. isIDCard:判断身份证
  6. isURL:判断URL
  7. isImg:判断图片格式
  8. isCar:判断车牌号码
  9. isIPV4/isIPV6:判断IP地址

字符串类

  1. formatStr:格式化字符串
  2. toCamelCase:字符串转换为驼峰
  3. fromCamelCase:驼峰转字符串
  4. trim:去除空格
  5. escapeHTML:转义HTML字符串
  6. unescapeHTML:反转义HTML
  7. stripHTMLTags:过滤HTML代码
  8. subGbString:截取字符,区分中英文
  9. getGbLen:判断字符长度,区分中英文
  10. changeCase:字符串写法转换

数组类

  1. arrayMax:返回数组中的最大值
  2. arrayMin:返回数组中的最小值
  3. arrayChunk:切割数组
  4. flatten:指定扁平化数组
  5. deepFlatten:深度扁平化数组
  6. union:数组并集
  7. intersection:数组交集
  8. difference:数组差集
  9. initArrayFillValues:初始化并填充具有指定值的数组
  10. sample:返回数组中的随机元素

数字类

  1. toFixed:浮点数保留格式
  2. randomIntegerInRange:返回指定范围内的随机整数
  3. randomNumberInRange:返回指定范围内的随机数

金额类

  1. formatMoney:金额格式化
  2. convertMoney:金额转大写

日期类

  1. formatDate:日期格式化
  2. isWeekend:判断是否为周末
  3. isWeekday:判断是否为工作日
  4. dayName:日期转名称
  5. getTimestamp:日期转时间戳
  6. fromTimestamp:时间戳转日期
  7. roundDate:日期转换为零点

浮点计算类

  1. addExact:两个数相加
  2. subExact:两个数相减
  3. mulExact:两个数相乘
  4. divExact:两个数相除

工具类

  1. clone:浅拷贝
  2. deepClone:深拷贝
  3. debounce:防抖
  4. throttle:节流
  5. randomId:生成随机id
  6. uuid:生成uuid
  7. hexToRGB:16进制转RGB
  8. rgbToHex:RGB转16进制

存储类

cookie

  1. getCookie:获取cookie
  2. setCookie:设置cookie
  3. delCookie:删除cookie
  4. clearCookie:清空cookie

localStorage

  1. setLStorage:存储localStorage
  2. getLStorage:取出localStorage
  3. delLStorage:删除localStorage
  4. clearLStorage:清空localStorage

sessionStorage

  1. setSStorage:存储sessionStorage
  2. getSStorage:取出sessionStorage
  3. delSStorage:删除sessionStorage
  4. clearSStorage:清空sessionStorage

DOM类操作

  1. hasClass:判断元素是否包含类名
  2. addClass:添加class类名
  3. removeClass:移除class类名
  4. toggleClass:切换class类名

事件处理相关函数

  1. listener:事件监听器
  2. on:绑定事件
  3. off:解绑事件

使用文档

https://docs.const.team/utils