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 🙏

© 2025 – Pkg Stats / Ryan Hefner

in_common_use

v1.0.0

Published

这是一个包含多种实用JavaScript函数的库,涵盖了字符串操作、数组操作、对象操作等功能。

Readme

JavaScript 实用函数库

这是一个包含多种实用JavaScript函数的库,涵盖了字符串操作、数组操作、对象操作等功能。

安装

npm install in_common_use

导入

let icu = require('in_common_use')

函数列表

字符串操作

  • isStringEmpty(str)
    • 判断字符串是否为空。
  • reverseString(str)
    • 反转字符串。
  • capitalizeFirstLetter(str)
    • 首字母大写。
  • isNumeric(str)
    • 判断字符串是否为数字。
  • trimString(str)
    • 去除字符串首尾空格。
  • repeatString(str, num)
    • 重复字符串多次。
  • isEmail(str)
    • 判断字符串是否为电子邮件地址。
  • truncateString(str, num)
    • 截取字符串到指定长度并添加省略号。
  • toCamelCase(str)
    • 将字符串转换为驼峰命名法。

数组操作

  • containsElement(arr, element)
    • 检查数组中是否包含某个元素。
  • getMaxValue(arr)
    • 获取数组中的最大值。
  • getMinValue(arr)
    • 获取数组中的最小值。
  • removeDuplicates(arr)
    • 数组去重(不使用Set)。
  • flattenArray(arr)
    • 数组扁平化。
  • getUniqueValues(arr)
    • 获取数组中的唯一值。
  • arrayAverage(arr)
    • 数组求平均值。
  • removeFalsyValues(arr)
    • 移除数组中的假值(false, null, 0, "", undefined, NaN)。
  • sortByKey(arr, key)
    • 按指定键对数组进行排序。

对象操作

  • mergeObjects(obj1, obj2)
    • 合并两个对象。
  • isObjectEmpty(obj)
    • 检查对象是否为空。
  • shallowCopyObject(obj)
    • 复制对象(浅拷贝)。
  • hasKey(obj, key)
    • 检查对象是否包含某个键。
  • getObjectValues(obj)
    • 获取对象的值数组。
  • deepMerge(obj1, obj2)
    • 递归合并两个对象。

日期处理

  • getCurrentDate()
    • 获取当前日期。
  • addDaysToDate(date, days)
    • 添加天数到日期。
  • formatTimestamp(timestamp)
    • 格式化时间戳为日期字符串。
  • dateDifference(date1, date2)
    • 计算两个日期之间的天数差。
  • formatDateTime(date)
    • 将日期格式化为YYYY-MM-DD HH:MM:SS。
  • getCurrentTimestamp()
    • 获取当前时间戳。

浏览器操作

  • getQueryParams()
    • 获取URL中的查询参数对象。
  • isFeatureSupported(feature)
    • 检查浏览器是否支持某个特性。
  • isCSSPropertySupported(property)
    • 检查浏览器是否支持某个CSS属性。
  • getScrollPosition()
    • 获取滚动条位置。

数学计算

  • gcd(a, b)
    • 计算两个数的最大公约数。
  • lcm(a, b)
    • 计算两个数的最小公倍数。
  • isPrime(num)
    • 判断一个数是否为质数。
  • factorial(n)
    • 计算阶乘。

其他

  • getType(variable)
    • 检测变量类型。
  • getRandomInt(min, max)
    • 生成随机整数。
  • generateUUID()
    • 生成UUID。
  • delay(func, wait)
    • 延迟执行函数。
  • getObjectLength(obj)
    • 获取对象的长度(键的数量)。
  • deepCopyObject(obj)
    • 深拷贝对象(使用JSON.parse和JSON.stringify)。
    • 注意:此方法无法处理函数、undefined、循环引用等特殊情况。
  • getRandomColor()
    • 生成随机颜色。
  • throttle(func, wait)
    • 节流函数(改进版)。
  • debounce(func, wait)
    • 防抖函数(改进版)。
  • getElementDimensions(element)
    • 获取元素的宽度和高度。
  • generateRandomString(length)
    • 生成随机字符串。

贡献

如果你有任何改进或添加新函数的想法,请随时提交Pull Request。

开源协议

MIT