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

cus-utils

v1.0.12

Published

custom utils

Downloads

9

Readme

util 所有函数 单元测试覆盖率 100%

行覆盖率、函数覆盖率、分支覆盖率、语句覆盖率居均达到 100%

前端公用 util (内置 awaitWrap clearTimeId compose curry getTypeFn lowerCase toFixedNumber parseUrlQuery 前端常用的 util 方法)

awaitWrap 包装 promise 的高阶函数,返回值永远是一个数组 [err, data]

let [err, data] = await awaitWrap(Promise.resolve('1'));
if (err) {
    console.log(err);
}
console.log(data);

clearTimeId 用于在页面使用 setTimeout setInterval API 是忘记清理 id 存在,暴露方法统一清理 id

const { clearSetIntervalFn, setTimeoutIdToList, clearTimeoutFn, timersArr, setTimersListToNull } = clearTimeId();

let id = window.setTimeout(() => {}, 0);
setTimeoutIdToList(id);

clearSetIntervalFn();
clearTimeoutFn();
setTimersListToNull();

compose 用于在页面聚合多个方法

let a = (x: string) => `a${x}`;
let b = (x: string) => `b${x}`;
let c = (x: string) => `c${x}`;

let composeFn = compose(a, b, c);
const result = composeFn('1'); // abc1

curry 用于 科里化 传参

let fn = (a: string, b: string, c: string) => `${a}${b}${c}`;
let curryFn = curry(fn, 'a');
const result = curryFn('b', 'c'); // abc

getTypeFn 用于获取传入的变量的类型, getTypeFn 运行返回一个函数

const isBoolean = getTypeFn('Boolean');
const result = isBoolean(false); // true

const result1 = isObject({}); // true
const result2 = isArray('1'); // false

lowerCase 拿到小写的 str

const val = 'ABC';
const result = getLowerCase(val); // 'abc'

toFixedNumber 四舍五入

const result = toFixedNumber(0.1 + 0.6789, 5); // 0.7789

const result1 = toFixedNumber(1.335); // 1.34

const result2 = toFixedNumber(1.334); // 1.33

parseUrlQuery 解析字符串变成对象

const result = parseUrlQuery('a=1&b=2&c=3&a=4&a=5'); // {a: ['1', '4', '5'], b: '2', c: '3'}

const result1 = parseUrlQuery('?a=1&b=2&c=3'); // {a: '1', b: '2', c: '3'}

const result2 = parseUrlQuery(''); // {}