@elgato/utils

中文文档
0.6.2发布于 2026/10/29MITTypeScriptES Module构建来源已验证近 30 天下载 7.3万

Utilities used throughout the Elgato ecosystem.

原始使用文档
文档目录27 节
  1. Installation
  2. Disposables
  3. deferredDisposable
  4. DisposableStack
  5. Events
  6. EventEmitter
  7. JSON
  8. JsonObject
  9. JsonPrimitive
  10. JsonValue
  11. Miscellaneous
  12. Enumerable
  13. Lazy
  14. Objects
  15. get(source, path)
  16. set(target, path, value)
  17. Parsers
  18. parseBoolean(value)
  19. parseNumber(value)
  20. Processes
  21. getProcesses()
  22. Promises
  23. withResolvers()
  24. Strings
  25. format(format, ...args)
  26. Timers
  27. debounce(fn, delay)

@elgato/utils

Utilities used throughout the Elgato ecosystem.

@elgato/utils npm package Elgato homepage

Installation

npm install @elgato/utils

Disposables

deferredDisposable

Creates a new function that implements Symbol.dispose and accepts a disposer function. The disposer function is called when the new function is disposed.

import { deferredDisposable } from "@elgato/utils";

{
    using deferredDisposable(() => console.log("Hello world"));
    // ...
}

// "Hello world"

DisposableStack

Stack of managed resources, controlled by a single disposer. Partial polyfill of TC39 Explicit Resource Management's DisposableStack.

import { DisposableStack } from "@elgato/utils";

{
    using stack = new DisposableStack();
    stack.defer(() => "Hello");
    stack.defer(() => "world");
    // ...
}

// "Hello"
// "world"

Events

EventEmitter

A strongly-typed event emitter that enables the listening for, and emitting of, events; supported in browser and Node.js environments.

import { EventEmitter } from "@elgato/utils";

type EventMap = {
    created: [name: string];
};

const emitter = new EventEmitter<EventMap>();
emitter.on("created", (name: string) => {
    // ...
});

JSON

JsonObject

Type that represents an object within JSON.

import { type JsonObject } from "@elgato/utils";

const obj: JsonObject = {
    name: "Elgato",
};

JsonPrimitive

Type that represents a primitive within JSON, for example a string or number.

import { type JsonPrimitive } from "@elgato/utils";

const value: JsonPrimitive = "Elgato";

JsonValue

Type that represents a valid JSON value, for example an object, array, or primitive.

import { type JsonValue } from "@elgato/utils";

const value: JsonValue = ["Hello", "World"];

Miscellaneous

Enumerable

Provides a read-only iterable collection of items that also acts as a partial polyfill for iterator helpers.

import { Enumerable } from "@elgato/utils";

const items = new Enumerable(["One", "Two", "Three", "Four"]);
items
    .drop(1) // Drop "One"
    .take(2); // Take "Two" & "Three"

Polyfilled iterator helpers:

  • Symbol.iterator
  • asIndexedPairs()
  • drop(limit)
  • every(predicate)
  • filter(predicate)
  • find(predicate)
  • findLast(predicate)
  • flatMap(mapper)
  • forEach(fn)
  • includes(search)
  • map(mapper)
  • reduce(accumulator, initial)
  • some(predicate)
  • take(limit)
  • toArray()

Lazy

Object that wraps a lazily instantiated value, similar to C# Lazy<T>.

import { Lazy } from "@elgato/utils";

const lazy = new Lazy(() => "Hello world");
lazy.value; // "Hello world";

Objects

get(source, path)

Gets the value at the specified (deep) path.

import { get } from "@elgato/utils";

const obj = {
    name: "Elgato",
};

get(obj, "name"); // Elgato

set(target, path, value)

Sets the value at the specified (deep) path.

import { get } from "@elgato/utils";

const obj = {
    name: "Gato",
};

set(obj, "name", "Elgato"); // { name: "Elgato" }

Parsers

parseBoolean(value)

Parses the value a truthy-boolean; the strings "0" and "false" are parsed as false.

import { parseBoolean } from "@elgato/utils";

const a = parseBoolean(1); // true
const b = parseBoolean("false"); // false

parseNumber(value)

Attempts to parse a value to a number; returns undefined when parsing was unsuccessful.

import { parseNumber } from "@elgato/utils";

const number = parseNumber("13"); // 13

Processes

getProcesses()

Gets the running processes in a cross-platform way.

import { getProcesses } from "@elgato/utils";

const processes = await getProcesses();
console.log(processes);

Promises

withResolvers()

Function that returns an object that contains the promise, and two functions to resolve or reject it. Polyfill of Promise.withResolvers().

import { withResolvers } from "@elgato/utils";

const { promise, resolve, reject } = withResolvers<string>();

Strings

format(format, ...args)

Formats the specified string, replacing placeholders with their associated arguments.

import { format } from "@elgato/utils";

format("Hello {0}, from {1}", "world", "Elgato"); // Hello world, from Elgato

Timers

debounce(fn, delay)

Wraps a function; subsequent invocations of the wrapped function made within the specified delay are debounced to prevent multiple calls.

import { debounce } from "@elgato/utils";

const fn = debounce(() => console.log("Hello world"), 1000);

fn(); // Debounced
fn(); // "Hello world"

版本与发布记录

@elgato/utils 共发布 15 个版本,首次发布于 2025/06/02;过去 12 个月发布了 7 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.6.2latest2026/10/2915 天前
0.6.12026/10/091 个月前
0.6.02026/08/172 个月前
0.5.02026/08/113 个月前
0.4.52026/04/176 个月前
0.4.42026/03/078 个月前

关于 @elgato/utils 的常见问题

@elgato/utils 是什么?

Utilities used throughout the Elgato ecosystem.

如何安装 @elgato/utils?

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

@elgato/utils 支持 TypeScript 吗?

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

@elgato/utils 支持 ESM 还是 CommonJS?

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

@elgato/utils 可以商用吗?

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

@elgato/utils 的下载量有多少?

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

@elgato/utils 还在维护吗?

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