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

@car_han/utils

v1.1.11

Published

JS开发工具包

Downloads

9

Readme

Usage

Try it in the example directory.

LOG

import { Console } from "@car_han/utils";
Console.DIR = process.cwd(); //Set the root directory path of your project

Console.log(123);
// res => at ${FnName} (/examples/test.ts:4:9)

Console.table(["foo", "bar"]);
// ┌─────────┬────────┐
// │ (index) │ Values │
// ├─────────┼────────┤
// │    0    │ 'foo'  │
// │    1    │ 'bar'  │
// └─────────┴────────┘
// at ${FnName} (/examples/test.ts:4:9)

TYPE_TEST

is*

Determine the type of determination

// _ TYPE_TEST
const fn = () => {};
const a = 1;
const b = {};
const c = [];
const d = [1];
const e = { foo: "bar" };
const f = "";
const g = "123";
Console.log(T.isFn(fn));
Console.log(T.isNum(a));
Console.log(T.isObj(b));
Console.log(T.isArray(c));
Console.log(T.isValidArray(d));
Console.log(T.isValidObj(e));
Console.log(T.isStr(f));
Console.log(T.isValidStr(g));
// true at Object.<anonymous> (/examples/test.ts:23:9)
// true at Object.<anonymous> (/examples/test.ts:24:9)
// true at Object.<anonymous> (/examples/test.ts:25:9)
// true at Object.<anonymous> (/examples/test.ts:26:9)
// true at Object.<anonymous> (/examples/test.ts:27:9)
// true at Object.<anonymous> (/examples/test.ts:28:9)
// true at Object.<anonymous> (/examples/test.ts:29:9)
// true at Object.<anonymous> (/examples/test.ts:30:9)

typeOf

When you are not sure about the type, determine the type it belongs to includes

  • string
  • object
  • array
  • number
  • null
  • undefined
  • regex
  • date
// typeOf
Console.log(T.typeOf(Symbol("a")));
Console.log(T.typeOf(new Date()));
Console.log(T.typeOf(undefined));
Console.log(T.typeOf(null));
// symbol at Object.<anonymous> (/examples/test.ts:39:9)
// date at Object.<anonymous> (/examples/test.ts:40:9)
// undefined at Object.<anonymous> (/examples/test.ts:41:9)
// null at Object.<anonymous> (/examples/test.ts:42:9)

Time

Y => Year, M => Month, D => Date, h => hour, m: minutes, s: seconds.

console.log(Time.datefmt(new Date())); // default
// 2022/11/14 15:42:20
console.log(Time.datefmt(new Date(), "D-m")); // change fmtPattern
// 14/45
console.log(Time.datefmt(new Date(), undefined, ":*")); // change fmt modifer
// 2022:11:14 15*47*13

Timer

let bubbleCount = 0;
const timerFn = (...args) => {
    Console.log("bubble count", ++bubbleCount);
    Console.log("params", args);
};

let testTimer: undefined | NodeJS.Timer;
const NOW = Date.now();
const debounceImplFn = Timer.debounce(timerFn, 1000);
const throttleImplFn = Timer.throttle(timerFn, 600);
testTimer = setInterval(() => {
    if (Date.now() - NOW > 3000) {
        clearInterval(testTimer);
        testTimer = undefined;
    }
    debounceImplFn("debounce", "foo");
    throttleImplFn("throttle", "bar");
}, 16);

// bubble count 1 at timerFn (/examples/test.ts:41:10)
// params [ 'throttle', 'bar' ] at timerFn (/examples/test.ts:42:10)
// bubble count 2 at timerFn (/examples/test.ts:41:10)
// params [ 'throttle', 'bar' ] at timerFn (/examples/test.ts:42:10)
// bubble count 3 at timerFn (/examples/test.ts:41:10)
// params [ 'throttle', 'bar' ] at timerFn (/examples/test.ts:42:10)
// bubble count 4 at timerFn (/examples/test.ts:41:10)
// params [ 'throttle', 'bar' ] at timerFn (/examples/test.ts:42:10)
// bubble count 5 at timerFn (/examples/test.ts:41:10)
// params [ 'throttle', 'bar' ] at timerFn (/examples/test.ts:42:10)
// bubble count 6 at timerFn (/examples/test.ts:41:10)
// params [ 'debounce', 'foo' ] at timerFn (/examples/test.ts:42:10)

DataUtils

  • String generate random string, default len: 16
Console.log(Str.rollingRandomString(32));
// bbplbmjpdzmnlujnfvdpufdnhthewkzz at Object.<anonymous> (/examples/test.ts:68:9)

HttpHelper

  • uri
    • obj2query
const res = HttpHelper.obj2Query({
    test: 13,
    hh: "tt",
});

Console.log(res);
//?test=13&hh=tt at Object.<anonymous> (/src/dev/HttpHelper.ts:27:9)

ProjectHelper

Use the publish-subscribe model to publish and subscribe to the message bus

const emitter = new EventBus();
emitter.on("foo", (payload) => {
    Console.log(payload);
});
emitter.fire("foo", 123);
emitter.fire("foo", 321);
// 123 at /src/dev/ProjectUtils/EventBus.ts:38:13
// 321 at /src/dev/ProjectUtils/EventBus.ts:38:13

Reg

Some commonly used regular matches.

  • isPhone
  • isEmail
  • isIdCard
  • isPassword
  • isUrl
  • isIp
  • isPostalCode
  • isChinese