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/helper

v3.1.0

Published

JavaScript 函数库、工具类

Readme

文档采用DeepseekAI大模型自动生成的,仅供参考。

根据提供的 index.d.cts 文件内容,以下是生成的使用文档:


@mznjs/helper 工具库使用文档

1. 核心模块概览

export { db, storage, utils } // 主要导出内容
export { lib, stdEnv, unstorage } // 扩展工具库

2. 存储模块 (storage)

2.1 本地存储操作
import { storage } from '@mznjs/helper'

// 设置数据
storage.set('theme', 'dark')

// 获取数据
const theme = storage.get('theme') // 'dark'

// 删除数据
storage.remove('theme')
2.2 数据库操作 (unstorage)
import { db } from '@mznjs/helper'

// 设置键值
await db.setItem('cache:data', { timestamp: Date.now() })

// 获取键值
const data = await db.getItem('cache:data')

// 删除键值
await db.removeItem('cache:data')

3. 实用工具 (utils)

3.1 Favicon 获取工具
import { utils } from '@mznjs/helper'

// 创建实例
const fetcher = new utils.fav.FaviconFetcher('https://example.com')

// 获取 favicon URL
const url = await fetcher.getFaviconUrl()

// 获取二进制数据
const blob = await fetcher.fetchFavicon()

// 加载为图像
const img = await fetcher.loadFaviconAsImage()
3.2 数据验证工具
import { utils } from '@mznjs/helper'

// 手机号验证
utils.testValidate('13800138000', 'mobile') // true

// 邮箱验证
utils.testValidate('[email protected]', 'email') // true

// 支持的全部验证类型:
type ValidationType =
  | 'version' // 版本号 (x.y.z)
  | 'mobile' // 手机号
  | 'email' // 邮箱
  | 'ip' // IP地址
  | 'url' // URL
  | 'datetime' // 日期时间 (YYYY-MM-DD HH:mm:ss)
  | 'english+number' // 英文+数字组合
  | 'chinese' // 纯中文
  // ...共 25 种验证类型
3.3 URL 处理工具
import { utils } from '@mznjs/helper'

// URL 解析
const parsed = utils.url.parseUrlWithRegex('https://example.com:8080/path')
/* 返回:
{
  protocol: 'https',
  hostname: 'example.com',
  port: '8080',
  path: '/path'
}
*/

// 强制转换为 HTTP
utils.url.http('ftp://example.com') // 'http://example.com'

4. 扩展工具库

// 存储增强库 (unstorage)
import { unstorage } from '@mznjs/helper'

// 基础工具库 (@mznjs/library)
import { lib } from '@mznjs/helper'

// 环境检测库 (std-env)
import { stdEnv } from '@mznjs/helper'
lib.crypto.randomUUID()
console.log(stdEnv.isBrowser)

5. 类型定义

所有工具均包含完整的 TypeScript 类型定义,支持以下功能:

  • 方法参数类型提示
  • 返回值类型推断
  • 枚举类型自动补全(如 ValidationType
  • 类方法智能提示

典型应用场景

  1. 前端缓存管理:结合 storagedb 实现多级缓存
  2. 表单验证:使用 testValidate 进行实时输入校验
  3. 爬虫开发:利用 FaviconFetcher 获取网站图标
  4. URL 标准化:通过 url 工具处理第三方链接
  5. 环境适配:配合 stdEnv 实现跨平台兼容逻辑

完整类型定义可参考 index.d.cts 文件,所有接口均包含中文注释说明。