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

@mznjs/utils

v3.1.1

Published

工具库

Readme

@mznjs/utils

@mznjs/utils 是一个功能丰富的工具库,提供了多种实用工具函数,包括 JSON/JSON5 处理、VSCode 配置文件读取、BEM 命名规范工具和日志工具等。

安装

# 使用 pnpm
pnpm add @mznjs/utils

# 使用 npm
npm install @mznjs/utils

# 使用 yarn
yarn add @mznjs/utils

模块结构

JSON 工具

提供标准 JSON 格式处理工具,包括 JSON 格式化、注释移除等功能。

import { removeJsoncComments, formatJson, getJsonError } from '@mznjs/utils/json';

// 移除 JSON 注释
const cleanJson = removeJsoncComments(jsonWithComments);

// 格式化 JSON
const formattedJson = formatJson(jsonString, { space: 2 });

// 获取 JSON 解析错误
const error = getJsonError(invalidJson);

详细文档请参考 JSON 工具文档

JSON5 工具

提供 JSON5 格式的解析、序列化、格式化和验证工具。

import { parseJson5, stringifyJson5, formatJson5 } from '@mznjs/utils/json5';

// 解析 JSON5 字符串
const obj = parseJson5(json5String);

// 序列化为 JSON5 格式
const json5Str = stringifyJson5(obj, { space: 2 });

// 格式化 JSON5
const formattedJson5 = formatJson5(json5String, { space: 2 });

详细文档请参考 JSON5 工具文档

VSCode 配置文件读取工具

用于读取和解析 VSCode 配置文件,支持多目录读取和合并。

import { readVsCodeFiles, getAllVsCodeConfigs } from '@mznjs/utils/json';

// 读取 VSCode 配置文件
const configs = await readVsCodeFiles('path/to/directory');

// 获取所有 VSCode 配置
const allConfigs = await getAllVsCodeConfigs(['dir1', 'dir2']);

详细文档请参考 VSCode 配置文件读取工具文档

BEM 工具

提供 BEM (Block-Element-Modifier) 命名规范工具,用于生成符合 BEM 规范的 CSS 类名和变量。

import { useBEM } from '@mznjs/utils/bem';

// 创建 BEM 实例
const bem = useBEM('button');

// 生成类名
bem.b(); // 'button'
bem.be('icon'); // 'button__icon'
bem.bm('primary'); // 'button--primary'
bem.bem('icon', 'small'); // 'button__icon--small'

详细文档请参考 BEM 工具文档

日志工具

提供基于 consola 的日志记录工具,支持多级别日志输出、标签和环境配置。

import { logger } from '@mznjs/utils/logger';

// 不同级别的日志输出
logger.debug('调试信息');
logger.info('一般信息');
logger.success('操作成功');
logger.warn('警告信息');
logger.error('错误信息');

// 创建带标签的日志实例
const apiLogger = logger.create('api');
apiLogger.info('API 请求开始');

详细文档请参考 日志工具文档