@gaubee/node

中文文档
0.4.0发布于 2025/07/24MITTypeScriptESM + CJS近 30 天下载 2092

一些常见的nodejs-js工具函数

原始使用文档
文档目录7 节
  1. How to use
  2. Install
  3. Usage
  4. API
  5. env
  6. path
  7. promise

中文 / English

@gaubee/node

This project provides further supplements related to Node.js APIs based on @gaubee/util.

How to use

Install

# pnpm
pnpm add @gaubee/node
# npm
npm install @gaubee/node
# yarn
yarn add @gaubee/node
# jsr
deno add @gaubee/node

Usage

import { cwdResolver } from "@gaubee/node/path";

console.log(cwdResolver("file.txt"));

API

env

  • viteEnvSource:
    • (): Record<string, string>
    • Gets the Vite environment variable source.
  • nodeEnvSource:
    • (): Record<string, string>
    • Gets the Node.js environment variable source (process.env).
  • denoEnvSource:
    • (): Record<string, string>
    • Gets the Deno environment variable source.
  • bunEnvSource:
    • (): Record<string, string>
    • Gets the Bun environment variable source.
  • storageEnvSource:
    • (storage?: Storage): Record<string, string>
    • Gets an environment variable source based on the Storage API (e.g., sessionStorage).
  • autoEnvSource:
    • (fallback?: () => Record<string, string>): Record<string, string | undefined>
    • Automatically detects and returns the environment variable source for the current environment (Deno > Bun > Vite > Node.js > sessionStorage).
  • defineEnv:
    • <P extends string, KV extends Record<string, EnvConfig>>(prefix: P, kv: KV, source?: Record<string, string | undefined>, ext?: object): DefineEnvChain<P, DefineEnv<P, KV>>
    • Defines a set of environment variables, supporting type conversion, default values, and chained definitions.

path

  • normalizeFilePath:
    • (path: string | URL): string
    • Formats the path to standard POSIX format, supporting URL and Windows paths.
  • createResolver:
    • (cwd: string): PathResolver
    • Creates a path resolver that resolves paths relative to the specified cwd (current working directory).
    • The returned function has a dirname property with the value of the passed cwd.
  • cwdResolver:
    • PathResolver (i.e., ((...paths: string[]) => string) & {dirname: string})
    • A path resolver based on the current Node.js process's working directory (process.cwd()).
  • createResolverByRootFile:
    • (fromPath?: string | URL, rootFilename?: string): PathResolver
    • Creates a path resolver by looking up the specified root filename (defaults to package.json) upwards. The resolver will resolve paths based on the directory containing that root file.

promise

  • nodeTimmers:
    • { eventEmitter: NodeTimmer.EventEmiter }
    • An extension to timmers in @gaubee/util, providing Timmer related to Node.js events.
    • nodeTimmers.eventEmitter: A Timmer factory function for creating Timers based on node:events/EventEmitter for the delay function. It can listen for specified events and resolve the Promise when the event is triggered, with optional support for event argument filters.

版本与发布记录

@gaubee/node 共发布 9 个版本,首次发布于 2025/04/28;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.4.0latest2025/07/241.3 年前
0.3.02025/07/151.3 年前
0.2.42025/07/091.4 年前
0.2.32025/07/091.4 年前
0.2.22025/06/201.4 年前
0.2.12025/06/021.5 年前

关于 @gaubee/node 的常见问题

@gaubee/node 是什么?

一些常见的nodejs-js工具函数

如何安装 @gaubee/node?

在项目目录运行 npm install @gaubee/node,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@gaubee/util(*)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@gaubee/node 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@gaubee/node 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@gaubee/node 可以商用吗?

@gaubee/node 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@gaubee/node 的下载量有多少?

根据 npm 官方下载统计,@gaubee/node 在 2026/10/16 – 2026/11/14 这 30 天内被下载 2,092 次,日均约 70 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@gaubee/node 还在维护吗?

最新版本 0.4.0 发布于 2025/07/24(1.3 年前);至今共发布 9 个版本,其中过去 12 个月发布了 0 个;首次发布于 2025/04/28。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。