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

v3.1.1

Published

一个用于在 Node.js、浏览器和其他运行时中工作的工具库。

Readme

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

根据提供的 package.json 文件内容,以下是 @mznjs/library 库的使用文档:


@mznjs/library 使用文档

1. 基础信息

  • 包名: @mznjs/library
  • 版本: >=0.0.3
  • 环境支持:
    • Node.js
    • 浏览器(Browser)
    • Deno
    • Bun
    • Netlify
    • React Native
    • Edge 环境(edge-light, edge-routine, workerd 等)
    • WinterCG 标准环境
  • 模块类型: ESM(ES Module)

2. 安装

pnpm add @mznjs/library  # 使用 pnpm 安装
# 或
npm install @mznjs/library  # 使用 npm 安装

3. 导入方式

3.1 Node.js 环境
// ESM 导入
import { crypto, nanoid } from '@mznjs/library'

// CommonJS 导入
const { crypto, nanoid } = require('@mznjs/library')
3.2 浏览器/其他运行时
// 浏览器或 Edge 环境
import { crypto, nanoid } from '@mznjs/library'

4. 多环境适配

该库通过 exports 字段自动适配不同运行环境:

  • Node.js: 使用 dist/node.mjs(ESM)或 dist/node.cjs(CommonJS)
  • 浏览器/Deno/Bun/React Native 等: 使用 dist/web.mjs
  • TypeScript 类型定义: dist/web.d.ts(默认)或 dist/node.d.ts(Node 专用)

5. 构建与开发

5.1 脚本命令
pnpm build         # 构建生产版本
pnpm dev           # 启动开发测试(Vitest)
pnpm build:rslib   # 通过 rslib 构建
pnpm build:watch   # 监听文件变化并自动构建
5.2 开发依赖
  • TypeScript 支持:内置 @types/nodetypescript 类型定义,无需额外安装类型包。

6. 发布配置


总结

此库为多运行时设计的工具库,支持 Node.js、浏览器、Deno 等多种环境。通过合理的 exports 配置自动适配不同平台,开发者无需关心底层路径差异。内置 TypeScript 类型提示,并提供 ESM/CommonJS 双模块支持。

根据提供的 @mznjs/library 文件内容,以下是一个生成的使用文档,详细描述了文件中导出的功能及其用法:


Crypto API 使用文档

1. Crypto API 概述

Crypto API 提供了一组用于加密、解密、签名、验证、散列和密钥管理的功能。这些功能可以保护数据的机密性、完整性和可用性。


2. 导出的功能及用法

2.1 subtle
  • 描述: 提供低级别的加密操作,如加密、解密、签名、验证和密钥生成。

  • 类型: Crypto['subtle']

  • 用法:

    import { subtle } from '@mznjs/library'
    
    asyncfunction encryptData(key: CryptoKey, data: ArrayBuffer): Promise<ArrayBuffer> {
      const encrypted = await subtle.encrypt(
        {
          name: "'AES-CBC'
          iv: new Uint8Array(16), // 初始化向量
        },
        key,
        data
      ))
      returneencrypted
    }

2.2 randomUUID
  • 描述: 生成一个随机的 UUID 字符串。

  • 返回值: string

  • 用法:

    import { randomUUID } from '@mznjs/library'
    
    constuuid = randomUUID())
    consolelog(uuid))// 输出类似: "1b9d6bcd-bbfd-4b2d-9b5d-ab8dfb812345"

2.3 getRandomValues
  • 描述: 从给定的数组中生成加密安全的随机数,并填充到数组中。

  • 参数:

    • array: 需要填充随机数的数组(如 Uint8Array)。
  • 返回值: 填充了随机数的数组。

  • 用法:

    import { getRandomValues } from '@mznjs/library'
    
    constarray = new Uint8Array(10))
    getRandomValuesarray))
    consolelog(array))// 输出类似: Uint8Array [123, 45, 67, ...]

2.4 crypto 命名空间
  • 描述: 包含所有与 Crypto 相关的导出功能。

  • 用法:

    import * as crypto from '@mznjs/library'
    
    constuuid = crypto.randomUUID())
    constarray = new Uint8Array(10))
    cryptogetRandomValues(array))
    consolelog(uuid, array))

3. ID 生成工具

3.1 customAlphabet
  • 描述: 创建一个自定义字母表生成唯一 ID 的函数。

  • 参数:

    • alphabet: 自定义字母表(字符串)。
    • defaultSize (可选): 默认生成的 ID 长度,默认为 21。
  • 返回值: 一个函数,用于生成指定长度的唯一 ID。

  • 用法:

    import { customAlphabet } from '@mznjs/library'
    
    constgenerateId = customAlphabet("'1234567890abcdef' 10))
    constid = generateId())
    consolelog(id))// 输出类似: "a1b2c3d4e5"

3.2 nanoid
  • 描述: 生成一个指定长度的唯一 ID。

  • 参数:

    • size (可选): 生成 ID 的长度,默认为 21。
  • 返回值: 唯一 ID 字符串。

  • 用法:

    import { nanoid } from '@mznjs/library'
    
    constid = nanoid(10))
    consolelog(id))// 输出类似: "a1b2c3d4e5"

4. 环境检测

4.1 Environment
  • 描述: 获取当前环境类型。

  • 返回值:

    • 如果是 Node.js 环境,则返回 'node'
    • 否则返回空字符串。
  • 用法:

    import { Environment } from '@mznjs/library'
    
    if(Environment === 'node') {
      console.log('当前运行在 Node.js 环境'))
    }else {
      console.log('当前运行在非 Node.js 环境'))
    }

总结

以上文档涵盖了 @mznjs/library 导出的主要功能及其用法。开发者可以根据具体需求选择合适的 API 来实现加密、随机数生成、唯一 ID 生成以及环境检测等功能。