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

@phelan/toolkit

v0.0.1

Published

mohist utils

Readme

m-lib

一个功能完善的工具方法库,基于 unbuild 构建,使用 Changeset 进行版本管理。

功能特性

  • ✅ 代码规范: ESLint 代码规范检查
  • ✅ 常量管理: 域名常量、API 路径等常量配置
  • ✅ 环境判断: 项目当前所处环境(Dev/Stage/SL/Prod)判断
  • ✅ 域名管理: 当前环境域名判断和 API 地址生成
  • ✅ 通用监控: 错误监控、性能监控、用户行为监控
  • ✅ 多语言: i18n 国际化支持
  • ✅ 数字计算: decimal.js 封装,精确计算
  • ✅ 网络请求: axios 实例封装,支持拦截器、重试等
  • ✅ 表单校验: 常用验证器封装
  • ✅ 日期处理: dayjs 封装,常用日期方法

安装

npm install m-lib

使用示例

环境判断

import { getEnv, isDev, isProd, EnvType } from "m-lib";

// 获取当前环境
const env = getEnv(); // 'dev' | 'stage' | 'sl' | 'prod'

// 判断环境
if (isDev()) {
    console.log("开发环境");
}

if (isProd()) {
    console.log("生产环境");
}

域名管理

import { getDomain, getApiUrl } from "m-lib";

// 获取当前环境域名
const domain = getDomain();

// 获取完整API地址
const apiUrl = getApiUrl("/api/user/info");

监控

import { monitor } from "m-lib";

// 上报错误
monitor.error("login_error", new Error("登录失败"));

// 上报性能
monitor.performance("page_load", 1234);

// 上报用户行为
monitor.behavior("button_click", { buttonId: "submit" });

// 上报业务事件
monitor.business("order_created", { orderId: "123" });

多语言

import { i18n } from "m-lib";

// 设置语言
i18n.setLanguage("en-US");

// 添加翻译资源
i18n.addResources("zh-CN", {
    hello: "你好",
    user: {
        name: "用户名",
    },
});

// 翻译
const text = i18n.t("hello"); // '你好'
const userName = i18n.t("user.name"); // '用户名'
const withParams = i18n.t("welcome", { name: "John" }); // 支持 {{name}} 占位符

数字计算

import { add, subtract, multiply, divide, formatMoney } from "m-lib";

// 精确计算
const sum = add(0.1, 0.2); // 0.3
const product = multiply(1.5, 2.5); // 3.75

// 格式化
const money = formatMoney(1234.567); // '1234.57'

网络请求

import { request, get, post } from "m-lib";

// 使用默认实例
const data = await get("/api/user/info");

// POST请求
const result = await post("/api/user/login", {
    username: "admin",
    password: "123456",
});

// 创建自定义实例
import { createRequest } from "m-lib";
const customRequest = createRequest({
    baseURL: "https://api.example.com",
    timeout: 5000,
});

表单校验

import { Validator, validateForm } from "m-lib";

// 单个验证
const result = Validator.email("[email protected]");
if (!result.valid) {
    console.log(result.message);
}

// 组合验证
const rule = Validator.combine(
    Validator.required,
    Validator.stringLength(6, 20),
    Validator.pattern(/^[a-zA-Z0-9]+$/, "只能包含字母和数字")
);

// 表单验证
const formData = {
    username: "admin",
    email: "[email protected]",
};

const rules = {
    username: [Validator.required, Validator.stringLength(3, 20)],
    email: [Validator.required, Validator.email],
};

const { valid, errors } = validateForm(formData, rules);

日期处理

import { format, now, add, isToday, smartFormat } from "m-lib";

// 格式化日期
const dateStr = format(now(), "YYYY-MM-DD HH:mm:ss");

// 添加时间
import { addTime } from "m-lib";
const nextWeek = addTime(7, "day");

// 判断是否为今天
if (isToday(someDate)) {
    console.log("今天");
}

// 智能格式化
const smart = smartFormat(date); // '12:00' | '昨天 12:00' | '2024-01-01 12:00'

开发

安装依赖

npm install

构建

npm run build

开发模式(监听文件变化)

npm run dev

代码检查

npm run lint
npm run lint:fix

类型检查

npm run typecheck

版本管理

本项目使用 Changesets 进行版本管理。

创建变更集

npm run changeset

版本升级

npm run version

发布

npm run release

模块说明

constants

域名常量、API 路径常量等配置。

env

环境判断工具,支持 Dev/Stage/SL/Prod 四种环境。

domain

域名管理工具,根据环境自动获取对应域名。

monitor

通用监控工具,支持错误监控、性能监控、用户行为监控等。

i18n

多语言国际化工具,支持嵌套翻译、参数替换等。

decimal

基于 decimal.js 的精确数字计算工具。

request

基于 axios 的网络请求工具,支持拦截器、重试、错误处理等。

validator

表单验证工具,提供常用验证规则。

date

基于 dayjs 的日期处理工具,提供常用日期方法。

License

MIT