@drawbridge/drawbridge-utils

中文文档
0.0.232发布于 2026/11/12ISCTypeScriptESM + CJS近 30 天下载 3576

Shared helpers and data used across the drawbridge-* repositories.

原始使用文档
文档目录7 节
  1. Main entry
  2. Encrypt entry (server-only)
  3. Axios entry (server-only)
  4. Circuit entry (server-only)
  5. Upload entry
  6. Nanoid entry (server-only)
  7. Build & publish

@drawbridge/drawbridge-utils

Shared helpers and data used across the drawbridge-* repositories.

Main entry

const utils = require( '@drawbridge/drawbridge-utils' );
// or: import { capitalize } from '@drawbridge/drawbridge-utils';

Exports:

  • bytesToGB( bytes ) / bytesToMB( bytes ) — byte conversion.
  • capitalize( string ) — uppercases the first character.
  • constants — default record shape per Mongo collection name (action, brand, campaign, draw, member, organization, page, prize, range, referrer, template, usage, user).
  • currencies / currency( code ) — list of ISO currencies (key/value/code/digits) and lookup by code.
  • expiredPaymentMethod( card ) — checks if a card record's year/month is in the past.
  • formatCurrency({ code, digits, display, locale, value }) — Intl-based formatter. display: 'standard' (default) returns Intl's standard string; 'parts' returns symbol, number, then the code ("$500.00 CAD"), dropping the symbol for a currency that has none ("500.00 CHF").
  • formatDateString({ date, locale, time, options }) — Intl-based date formatter. time: true adds hour/minute.
  • formatNumber( number, digits ) — Intl-based number formatter with fixed-digit min/max.
  • getPlanFeature( plan, key ) — { granted, message } lookup.
  • infinite, isInfinite( value ), megabyte, gigabyte — size constants.
  • nanoid() — 8-char base36 random ID.
  • percentage( value1, value2, decimals ) — (value1 / value2) * 100, fixed decimals (default 1).
  • reducers.fields — reducer for grouping fields by additional / lead type.
  • regex.url / regex.protocols / regex.domain — shared regex constants.
  • shareUrls({ formUri, organization, page }) — builds share URLs from the configured form base URI. Falls back to process.env.APP_CLIENT_FORM_URI if formUri is not passed (server-only).
  • urlRoot( string ) — 'https://' if input contains 'https', else 'http://'.

Encrypt entry (server-only)

const { encrypt, decrypt } = require( '@drawbridge/drawbridge-utils/encrypt' );

Server-only because it uses Node crypto and reads process.env.ENCRYPT_CONNECTION_SECRET. Exposed as a sub-export so client bundles don't pull Node built-ins.

Axios entry (server-only)

const { safe, axios } = require( '@drawbridge/drawbridge-utils/axios' );
  • safe.get( url, axiosOptions ) — SSRF-protected GET request.
  • axios — raw axios passthrough for advanced usage.

Circuit entry (server-only)

const { circuit } = require( '@drawbridge/drawbridge-utils/circuit' );
  • circuit({ name, threshold, timeout }) — circuit breaker for async operations.

Upload entry

const { allowedUploadTypes, allowedMimes, resolveUploadType, isAllowedMime } = require( '@drawbridge/drawbridge-utils/upload' );
  • allowedUploadTypes / allowedMimes — shared whitelist constants.
  • resolveUploadType( type, extension ) — resolves an upload type from MIME + extension.
  • isAllowedMime( mime ) — predicate for the MIME whitelist.

Nanoid entry (server-only)

const { nanoid, retry } = require( '@drawbridge/drawbridge-utils/nanoid' );
  • nanoid() — 8-char base36 random ID (same as the main export).
  • retry({ field, operation, maxRetries }) — runs an async operation that generates a nanoid, retrying on Mongo duplicate-key errors.

Build & publish

nvm use
npm install
npm run build

build runs tsup (multi-entry, dual CJS + ESM output) and then npm publish. Bump version in package.json first.

版本与发布记录

@drawbridge/drawbridge-utils 共发布 221 个版本,首次发布于 2026/05/06;过去 12 个月发布了 221 个版本。

版本发布日期距今
0.0.232latest2026/11/121 天前
0.0.231espresso2026/11/103 天前
0.0.2302026/11/067 天前
0.0.2292026/11/067 天前
0.0.2282026/11/058 天前
0.0.2272026/11/058 天前

关于 @drawbridge/drawbridge-utils 的常见问题

@drawbridge/drawbridge-utils 是什么?

Shared helpers and data used across the drawbridge-* repositories.

如何安装 @drawbridge/drawbridge-utils?

在项目目录运行 npm install @drawbridge/drawbridge-utils,或使用 pnpm add / yarn add / bun add。

@drawbridge/drawbridge-utils 支持 TypeScript 吗?

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

@drawbridge/drawbridge-utils 支持 ESM 还是 CommonJS?

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

@drawbridge/drawbridge-utils 可以商用吗?

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

@drawbridge/drawbridge-utils 的下载量有多少?

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

@drawbridge/drawbridge-utils 还在维护吗?

最新版本 0.0.232 发布于 2026/11/12(1 天前);至今共发布 221 个版本,其中过去 12 个月发布了 221 个;首次发布于 2026/05/06。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。