@adviser/cement

中文文档
0.5.36发布于 2026/06/02AFL-2.0TypeScriptESM + CJS构建来源已验证近 30 天下载 3.2万

better try/catch/finally handling

原始使用文档
文档目录20 节
  1. Overview
  2. Key Features
  3. System Abstraction
  4. Structured Logging
  5. Additional Utilities
  6. Installation
  7. npm (Node.js)
  8. pnpm
  9. Deno
  10. Go
  11. Usage
  12. Basic Example
  13. Platform-Specific Imports
  14. Result Type for Error Handling
  15. Documentation
  16. Supported Platforms
  17. Development
  18. Contributing
  19. License
  20. Repository

Cement

An agnostic platform abstraction layer for TypeScript/JavaScript and Go that provides consistent APIs across Node.js, Deno, Cloudflare Workers, and other runtimes.

Overview

Cement provides a unified interface for common system operations, logging, and utilities across different JavaScript/TypeScript runtimes and Go. Write your code once and run it anywhere - whether that's Node.js, Deno, browsers, or Cloudflare Workers.

Key Features

System Abstraction

Cross-platform system operations through a unified interface:

interface SysAbstraction {
  Time(): Time;
  Stdout(): WritableStream<Uint8Array>;
  Stderr(): WritableStream<Uint8Array>;
  NextId(): string;
  Random0ToValue(value: number): number;
  System(): SystemService;
  FileSystem(): FileService;
}

Structured Logging

Inspired by Go's zerolog, providing efficient structured logging:

logger
  .Str("user", "john")
  .Uint64("id", 123)
  .Info()
  .Log("User logged in");

Additional Utilities

  • Result & Option Types: Type-safe error handling inspired by Rust
  • Future: Promise-based async utilities
  • URI Handling: Mutable URL utilities for safe URL manipulation
  • Crypto: Platform-agnostic cryptographic operations
  • Tracer: Distributed tracing support
  • LRU Cache: Efficient least-recently-used cache implementation
  • Path Operations: Cross-platform path manipulation
  • HTTP Headers: Type-safe HTTP header utilities
  • Poller: Polling utilities with configurable intervals
  • Timeouted: Timeout wrapper for async operations

Installation

npm (Node.js)

npm install @adviser/cement

pnpm

pnpm add @adviser/cement

Deno

import { ... } from "jsr:@adviser/cement";

Go

go get github.com/mabels/cement

Usage

Basic Example

import { BuildBasicSystemService } from "@adviser/cement/node";

const sys = BuildBasicSystemService();
const logger = sys.Logger();

logger
  .Str("module", "app")
  .Info()
  .Log("Application started");

// Use file system operations
const fs = sys.FileSystem();
await fs.writeFile("output.txt", "Hello World");

Platform-Specific Imports

// Node.js
import { BuildBasicSystemService } from "@adviser/cement/node";

// Deno
import { BuildBasicSystemService } from "@adviser/cement/deno";

// Cloudflare Workers
import { BuildBasicSystemService } from "@adviser/cement/cf";

// Browser/Web
import { BuildBasicSystemService } from "@adviser/cement/web";

Result Type for Error Handling

import { Result } from "@adviser/cement";

function divide(a: number, b: number): Result<number> {
  if (b === 0) {
    return Result.Err(new Error("Division by zero"));
  }
  return Result.Ok(a / b);
}

const result = divide(10, 2);
if (result.isOk()) {
  console.log("Result:", result.unwrap());
} else {
  console.error("Error:", result.unwrapErr());
}

Documentation

For comprehensive documentation, API references, and advanced usage examples, visit:

https://mabels.github.io/cement

Supported Platforms

  • Node.js (>= 20.19.0)
  • Deno
  • Cloudflare Workers
  • Web Browsers
  • Go (>= 1.22.0)

Development

# Install dependencies
pnpm install

# Run tests
pnpm test

# Run tests for specific platform
pnpm test:js     # Node.js/JavaScript tests
pnpm test:deno   # Deno tests

# Build
pnpm build

# Lint
pnpm lint

# Format code
pnpm format

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

Apache License 2.0 - See LICENSE for details.

Repository

版本与发布记录

@adviser/cement 共发布 215 个版本,首次发布于 2024/02/01;过去 12 个月发布了 50 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.5.36latest2026/06/025 个月前
0.5.352026/05/265 个月前
0.5.342026/03/177 个月前
0.5.332026/03/058 个月前
0.5.322026/03/048 个月前
0.5.312026/03/038 个月前

其他发布通道:dev → 0.4.64-dev。

关于 @adviser/cement 的常见问题

@adviser/cement 是什么?

better try/catch/finally handling

如何安装 @adviser/cement?

在项目目录运行 npm install @adviser/cement,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 cement,可以用 npx cement 直接运行。

@adviser/cement 支持 TypeScript 吗?

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

@adviser/cement 支持 ESM 还是 CommonJS?

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

@adviser/cement 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20.19.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@adviser/cement 可以商用吗?

@adviser/cement 使用 AFL-2.0 许可。声明的许可为 AFL-2.0,请阅读许可原文确认使用条件。以上为概括,不构成法律意见,请以许可原文为准。

@adviser/cement 的下载量有多少?

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

@adviser/cement 还在维护吗?

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