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 🙏

© 2026 – Pkg Stats / Ryan Hefner

hongfangze-derive

v1.0.0

Published

comm.derive

Readme

获取一些资源数据

介绍

获取各种信息,包括但不限于:指定对象的类型、随机未使用的端口号、字符串字节长度、命令行参数、HTTP地址参数、HTTP请求的FormData数据、HTTP请求数据包、HTTP请求客户端的IP地址、服务器本地IP等。

// import * as derive from "hongfangze-derive";
// import { localIp } from "hongfangze-derive";

/**
 * 获取指定对象的类型
 * @param {*} obj 需要获取的对象
 * @param {boolean} [detailed=false] 是否显示详细的类型,比如number的float/integer;Array<T>等
 * @return {*}  {string} "boolean" | "number" | "string" | "function" | "array" | "date" | "regexp" | "object" | "error" | "number<integer>" | "number<float>" | "array<json>" | "array" | "json" | "object"
 */
export declare const type: (obj: any, detailed?: boolean) => string;
/**
 * 获取指定对象的数据类型
 * @param {*} obj 需要判断类型的对象
 * @return {*} 主要类型和子类型 {({
 *     maintype: "null" | "undefined" | "boolean" | "number" | "string" | "function" | "array" | "date" | "regexp" | "object" | "error" | "json",
 *     subtype: "" | "float" | "integer" | "json" | "boolean" | "number" | "string" | "function" | "date" | "regexp" | "error"
 * })}
 */
export declare const typev2: (obj: any) => {
    maintype: "null" | "undefined" | "boolean" | "number" | "string" | "function" | "array" | "date" | "regexp" | "object" | "error" | "json" | string;
    subtype?: "float" | "integer" | "json" | "boolean" | "number" | "string" | "function" | "date" | "regexp" | "error";
};
/**
 * 获取一个随机的未使用的端口号
 * @return {*}  {Promise<number>}
 */
export declare const port: () => Promise<number>;
/**
 * 获取字符串字节长度
 * @param {string} str 需要获取长度的字符串
 * @param {("C2**" | "Buf")} mode 获取模式,默认Buf模式
 * - "C2**" 将中文字符转换成2个*号后(中文占2个直接),取length属性
 * - "Buf" 将数据转换成Buffer对象后,取length属性
 * @return {number} 字符串对应的直接长度
 */
export declare const getByteLength: (str: string, mode?: "C2**" | "Buf") => number;
/**
 * 获取请求客户端的IP地址
 * @param {*} req express/nest.js等框架或Node.js原生的HTTP请求对象
 * @return {string} 客户端IP地址,如果客户端启用了多层代理模式,请取第一个
 */
export declare const httpClientIp: (req: any) => string;
/**
 * 获取本机的IP地址
 * @return {*}  {string}
 */
export declare const localIp: () => string;
/**
 * 获取HTTP请求地址的参数
 * @param {string} url 地址
 * @param {string} [name] 参数名
 * @return {*}  {(string | Record<string, string>)}
 * - 如果指定了参数名,返回该参数的值
 * - 如果未指定参数名,返回所有的参数和值的KV对象
 */
export declare const getUrlParams: (url: string, name?: string) => string | Record<string, string>;
/**
 * 获取HTTP请求FormData数据
 * @param {IncomingMessage} req express/nest.js等框架或Node.js原生的HTTP请求对象
 * @return {Promise<{ form: any, tmpFiles: string[] }>} form信息及form中的文件临时存放地址,使用完后请自行删除
 */
export declare const getFormDataByRequest: (req: IncomingMessage) => Promise<{
    form: any;
    tmpFiles: string[];
}>;
/**
 * 解析HTTP请求数据包
 * @param {IncomingMessage} req express/nest.js等框架或Node.js原生的HTTP请求对象
 * @return {*}  {Promise<string | Record<string, any>>}
 */
export declare const getBodyByRequest: (req: IncomingMessage) => Promise<string | Record<string, any>>;
/**
 * 将命令行模式的数据转换成JSON格式
 * @param {string[]} argArray 命令行模式的数据
 * - 如 ["-p","80","-u":"admin"]
 * - 如 ["--port","80","--username":"admin"]
 * @return {*}  {Record<string, string>} 转换后的数据JSON对象
 */
export declare const convertCommandArgs2Json: (argArray: string[]) => Record<string, string>;
/**
 * 获取命令行参数信息
 * - 如 xxx -u root -p password
 * @return {*}  {Record<string, string>}
 */
export declare const getArgs: () => Record<string, string>;

版本迭代记录

2025-04-11 v1.0.0

  • 被移除后更名发布。

2025-02-14 v0.3.2

  • 修复已知Bug。
  • 打包编译增加注释文档。

2025-02-10 v0.2.2

  • 增加一些函数。

2024-10-08 v0.1.0

  • 继承obtian(重命名)

2024-06-12 v0.0.12

  • 修复type函数无法正确识别string和string<json>的Bug
  • 修复isJsonArray函数,判断空数组返回true的Bug

2024-06-11 v0.0.10

  • 修复type函数无法正确识别null和undefined的Bug

2024-06-06 v0.0.9

  • 修复type函数无法正确识别JSON的Bug
  • 增加typev2函数,返回一个maintype和subtype的JSON
  • type、typev2函数,增加string<json>的返回类型

2024-03-13 v0.0.8

  • getArgs函数Bug修复,不仅支持原有的“-p 80”还支持“--port 80”