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

jx-util

v2.4.12

Published

JavaScript utility functions

Downloads

55

Readme

JavaScript工具函数库

TODO

  • [ ] 测试覆盖率 100%
  • [x] need core: https://github.com/findhit/util
  • [x] js beautify 打印 obj中嵌套 json string,被嵌套的部分没有格式化
  • [ ] Scoped packages, https://www.npmjs.cn/misc/scope/
  • [ ] 启动不再造轮子原则!!明细文档!!!
  • [ ] kind-of 库

更新/发布/分发

// 主版本号/次版本号/修订版本号
main.minor.patch

// 第一次发布
npm adduser
npm publish

// 第n+1次发布
npm login
npm publish

// 查看包的版本
npm view jx-util version
@alisports/jx-util

npm publish --access=public

npm库版本

  • 通过prefix控制
^1.5.1 【限制主版本号】允许安装版本号大于 1.5.1 但小于 2.0.0 版本的模块
npm默认采用这种方式

~1.5.1 【限制次要版本】 允许安装版本号大于 1.5.1 但小于 1.6.0 版本的模块
可通过 npm config set save-prefix="~"将默认的^修改为~

1.5.1 【精确控制】允许安装版本号大于 1.5.1
可通过npm config set save-exact true 将默认的^取除掉
  • 通过package-lock.json控制
npm 5.0.x版本
不管package.json怎么变化,npm  install 都会根据package-lock.json 文件下载;

npm 5.1.0+版本
npm  install会无视package-lock.json, 根据package.json下载,也就是package.json的权限会高于package-lock.json;

npm 5.4.2+版本
npm  install时 如果package.json与package-lock.json不一致,则根据package.json的语法规则进行下载;如果一致时,则都会根据package-lock.json下载;

单元测试

Mocha测试异步代码, 在Nodejs中贯彻单元测试

// 安装依赖
npm install es6-promise --save --verbose
npm install -g mocha --verbose // 测试框架
npm install --save-dev chai --verbose // 断言库

npm install --save-dev mocha --verbose
npm install --save-dev mochawesome --verbose

npm install -g istanbul --verbose

// 单次测试
mocha tests/test-regex.js

// 持续测试
mocha --watch tests

// 生成测试结果html报表
mocha --reporter mochawesome tests

// 测试覆盖率
istanbul cover ./node_modules/mocha/bin/_mocha -- -t 2000 --recursive -R spec tests/

core

| 函数名 | 功能 | | ------ | ------ | | uniqId | 唯一ID码 | | uuid | '8-4-4-4-12' 字符串 | | timing | 测量函数执行时间 | | forEach | 遍历数组、字典 | | map | 映射函数 | | filter | 过滤函数 | | clone | 克隆函数 | | extend | 对象扩展函数 | | slice | 片取函数 | | stamp | 邮戳函数 |

from

| 函数名 | 功能 | | ------ | ------ | | string | 从string转换为本有类型 |

function

| 函数名 | 功能 | | ------ | ------ | | bind | 上下文绑定 | | return | immutable 值 | | falsify | immutable 假 | | truthify | immutable 真 | | nullify | immutable 空 | | undefinify | immutable 为定义 | | always | immutable 值 | | args | 获取实参名称数组 | | chain | 链异步函数 | | compose | 执行从右向左的函数组合 | | curry | 函数柯里化 | | allPass | 条件判断 | | anyPass | 条件判断 | | tryCatch | 异常捕获封装 | | pipes | 执行从左向右的函数组合 | | promisify | 转换异步 | | runPromisesInSeries | 异步串行 | | sleep | 延迟异步执行 | | throttle | 函数节流 | | debounce | 函数防抖 |

is

| 函数名 | 功能 | | ------ | ------ | | instanceof | ------ | | function | ------ | | array | ------ | | object | ------ | | string | ------ | | error | ------ | | regexp | ------ | | HTMLelement | ------ | | number | ------ | | undefined | ------ | | true | ------ | | false | ------ | | null | ------ | | json | json 字符串,不为字符串,则返回false | | bool | ------ | | symbol | ------ | | date | ------ | | promise | ------ | | not | ------ | | ok | ------ | | plain | ------ | | empty | ------ | | equal | ------ |

object

| 函数名 | 功能 | | ------ | ------ | | forEach, each | ------ | | map | ------ | | filter | ------ | | clone | ------ | | isEmpty | ------ | | clean | ------ | | fromPairs | ------ | | toPairs | ------ | | shallowClone | ------ | | has | ------ | | merge | ------ | | mergeDeep | ------ | | mergeWith | ------ | | keys | ------ | | values | ------ | | entries | ------ | | pick | ------ | | omit | ------ | | prop | ------ | | propApply | ------ | | propEq | ------ | | size | ------ |

to

| 函数名 | 功能 | | ------ | ------ | | string | ------ |

array

| 函数名 | 功能 | | ------ | ------ | | head/first | 首位元素 | | tail/last | 末尾元素 | | disorder/shuffle | 打乱 | | equal | 等价 | | contains | 包含 | | flatten | 扁平化 | | randomOne | 随机选取 | | countOccurrences | 计算元素数目 | | unique | 去重 | | sum | 求和(数值型数组) | | maxify | 求最大值(数值型数组) | | minify | 求最小值(数值型数组) | | forEach/each | 遍历 | | clone | 克隆 | | map | 映射 | | filter | 过滤 | | del/rm/remove | 移除 | | randomFilter | 指定元素数目,随机过滤 | | empty | 清空 | | union/merge | 求并集 | | intersect | 求交集 | | adjust | 对指定元素加值 | | allPass | 全量判定 | | anyPass | 选择判定 | | append | 追加元素 | | concat | 拼接数组 | | diff | 求差集 | | slice | 片取 |

date

| 函数名 | 功能 | | ------ | ------ | | head/first | 首位元素 |

number

regex

string

timer

url