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

@dusky/ts-common

v1.1.3

Published

typescript common tools and language extension

Downloads

25

Readme

#ts-common

项目作用

为typescript编程添加常用到的工具函数。 该工程用于编写、测试、文档和发布功能。

如何使用

  1. npm install -D @dusky/ts-common
  2. import "@dusky/ts-common"

项目结构

  • /docs/ 生成文档工程
  • /res/ API导图等资源
  • /src/ 源码...
  • /src_candidates/ 候选暂存...
  • /tests/ 测试用例合集
  • /dist/ 发布(index.js,index.d.ts)

api列表

全局函数扩展

  • isArr 判断目标是否为数组
  • isBool 判断目标是否为布尔值
  • isEmpty 判断目标是否为内容空值
  • isFunc 判断目标是否为函数
  • isNullish 判断目标是否为空值
  • isNum 判断目标是否为数值
  • isObject 判断目标是否为对象类型
  • isPrimitive 判断目标是否为原生类型
  • isRGB 判断目标是否为RGB颜色值
  • isRGBA 判断目标是否为RGBA颜色值
  • isStr 判断目标是否为字符串
  • isEqual 判断目标是否为内容上相等
  • notEmpty 判断目标是否非内容空值
  • notEmptyArr 判断目标是否为非空数组

对象类型扩展

对象类
  • Object.enumKeys 获得枚举对象的所有键名
  • Object.enumValues 获得枚举对象的所有取值
  • Object.deepGet 深度获取对象的属性值
  • Object.clean 清空对象的空值、空字符串的属性
  • Object.clone 浅克隆(复制)对象
  • Object.deepClone 深克隆(复制)对象
  • Object.set 为对象设置属性
  • assign 为对象(指定键)赋值
  • assignExcept 为对象(指定键以外)赋值
对象实例
  • obj.hasOwn 判断目标是否自身拥有某属性

数组类型扩展

数组类
  • Array.fill 生成一个新的填充数组
  • Array.nature 生成一个自然数序列数组
  • Array.flatten 扁平化数组
数组实例(返回类型非自身)
  • arr.head 获取数组首元素
  • arr.tail 获取数组末元素
  • arr.heads 返回数组前多个元素所组成的数组
  • arr.tails 返回数组末多个元素所组成的数组
  • arr.copy 拷贝原素组并返回新数组
  • arr.loopAt 循环获取下标值
  • arr.random 从数组随机取得值
  • arr.contains 判断数组是否包含某(些)值
  • arr.excludes 判断数组是否不包含某(些)值
  • arr.all 判断数组是否全部为某(些)值
  • arr.notAll 判断数组是否不全部为某(些)值
  • arr.containsInstance 判断数组是否包含某(些)类型实例(之一)
  • arr.allInstance 判断数组是否全部是某(些)类型实例
数组实例(返回自身)
  • arr.unique 去除数组中的重复元素
  • arr.clean 去除数组中的空值和空字符串元素
  • arr.insert 为数组插入某(些)值
  • arr.delete 删除数组指定数量的元素
  • arr.remove 移除数组中所有某(些)值
  • arr.exchange 交换数组指定下标值
  • arr.pushUnique 从头部加入某(些)值,数组含有的值不会重复添加
  • arr.unshiftUnique 从末尾加入某(些)值,数组含有的值不会重复添加
  • arr.descBy 按照数组内对象指定属性数值降序重排数组
  • arr.shuffle 数组洗牌
  • arr.swingCut 数组切牌
数组实例(数值数组)
  • arr.max 获取数组内最大值
  • arr.min 获取数组内最小值
  • arr.asc 数值升序重排数组
  • arr.desc 数值降序重排数组

函数类型扩展

  • Function.sleep 等待指定时间
  • Function.invoke 执行指定函数
  • Function.wait 等待指定时间执行指定函数

字符类型扩展

  • String.Length 计算字符串实际长度(中文为2,英文和数字符号为1)
  • String.ellipsis 截取字符串并补充省略号到指定长度
  • String.uuid 生成一个随机UUID
  • String.random (在指定范围内)生成随机字符串
  • String.reverse 反转字符串
  • String.isChinese 判断目标是否为纯中文字符串
  • String.isLetters 判断目标是否为纯英文字母
  • String.isNumeric 判断目标是否为纯数值字符串

集合工具扩展

  • Array.merge 求合集(不去重)
  • Array.union 求并集(去重)
  • Array.intersection 求交集(不去重)
  • Array.subtraction 求差集(不去重)
  • Array.symComplement 求对称补集(不去重)

数学工具扩展

  • Math.randomRange 在指定范围内随机数
  • Math.randomInt 在指定范围内随机整数
  • Math.randomBool (按指定比例)随机布尔值
  • Math.parseDegree 弧度转角度
  • Math.parseRadian 角度转弧度
  • Math.sum 求算数和
  • Math.sumSqr 求平方和
  • Math.avg 求算数平均数
  • Math.percentage 求百分比整数(0-100)
  • Math.lerp 在两个数值间按比例插值
  • Math.clamp 在范围内截断数值
  • Math.clamp01 在0-1内截断数值

数字工具扩展

  • Number.fix 保留指定位小数
  • Number.precise 保留指定有效位

API全景图

...

查看文档

打开docs/index.html即可。

测试用例

测试用例在/tests的对应文件夹下。 运行命令:npm run test