@dr.pogodin/js-utils

中文文档
0.2.0发布于 2026/07/04MITTypeScriptES Module近 30 天下载 4.2万

Collection of JavaScript (TypeScript) utilities.

原始使用文档
文档目录5 节
  1. Content
  2. Constants
  3. Types
  4. Functions
  5. Classes

JS Utils

Latest NPM Release NPM Downloads CircleCI GitHub repo stars Dr. Pogodin Studio

The aim for this repo/package is to move in from the React Utils the pieces which are not React-specific, thus are also useful cross non-React projects, and thus having them in a dedicated package will faciliate their re-use in generic JavaScript (and TypeScript) projects.

At least for the first time, all stuff moved in here will still be exposed from React Utils the same way as before, and the documentation for these pieces will be still kept at https://dr.pogodin.studio/docs/react-utils/index.html. Maybe later, time permitting, this will be documented as a stand-alone library, but prior to that it will be maintained and used as a stand-alone lib, but not very well documented as such.

Yeah, the source code will be written in TypeScript, and for the library version released to NPM it will be also compiled into plain JavaScript. Consumers of that NPM package thus will have access to both TS (/src folder) and JS (/build folder) version of the library.

Sponsor

Content

The library currently exports (links below lead to React Utils docs, but the same stuff can be imported from this @dr.pogodin/js-utils, and used in the same way):

Constants

  • SEC_MS — One second expressed in milliseconds.
  • MIN_MS — One minute expressed in milliseconds.
  • HOUR_MS — One hour expressed in milliseconds.
  • DAY_MS — One day expressed in milliseconds.
  • YEAR_MS — One year expressed in milliseconds.

Types

  • Extends<Base, T extends Base> — Validates compile-time the type T extends (is assignable to) the type Base; returns T if successful.
  • Implements<Base, T extends Base & ...> — Validates compile-time the type T extends (is assignable to) the type Base, and also has all (if any) optional fields defined in the Base; returns T if the validation passes.
  • ObjectKey — string | number | symbol — The most generic valid type of an object key in TypeScript.

Functions

  • assertEmptyObject() — Asserts given object is empty, both compile- and run-time.
  • timer() — Creates a Barrier which resolves after the specified timeout.
  • withRetries() — Attempts a given action multiple times until its succeeds.

Classes

  • Barrier — A Promise with resolve() and reject() exposed as instance methods.

  • Cached — A cache of (a)synchronously retrieved items with timestamp-based expiration.

  • Emitter — Simple listeneable data emitter.

  • Semaphore — Synchronization primitive.

  • Timer — The core implementation of timer() functionality, allowing to create further customized timer objects. To be documented.


Repository of this library also hosts some documents, to be referenced from other projects, as needed:

版本与发布记录

@dr.pogodin/js-utils 共发布 28 个版本,首次发布于 2023/04/27;过去 12 个月发布了 5 个版本。

版本发布日期距今
0.2.0latest2026/07/044 个月前
0.1.82026/05/165 个月前
0.1.72026/05/146 个月前
0.1.62026/02/238 个月前
0.1.52025/12/0111 个月前
0.1.42025/10/271 年前

关于 @dr.pogodin/js-utils 的常见问题

@dr.pogodin/js-utils 是什么?

Collection of JavaScript (TypeScript) utilities.

如何安装 @dr.pogodin/js-utils?

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

@dr.pogodin/js-utils 支持 TypeScript 吗?

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

@dr.pogodin/js-utils 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@dr.pogodin/js-utils 可以商用吗?

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

@dr.pogodin/js-utils 的下载量有多少?

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

@dr.pogodin/js-utils 还在维护吗?

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