@dasch-ng/utils

中文文档
0.6.2发布于 2026/11/11MITTypeScriptES Module构建来源已验证近 30 天下载 2316

A collection of useful Angular utilities including standalone pipes, dependency injection helpers, and type guards. Built with modern Angular patterns and full TypeScript support.

原始使用文档
文档目录10 节
  1. Installation
  2. Features
  3. Quick Start
  4. Available Utilities
  5. Pipes
  6. Functions
  7. Documentation
  8. API Reference
  9. License
  10. Running unit tests

@dasch-ng/utils

A collection of useful Angular utilities including standalone pipes, dependency injection helpers, and type guards. Built with modern Angular patterns and full TypeScript support.

npm version

Installation

npm install @dasch-ng/utils

or with bun:

bun add @dasch-ng/utils

Features

  • 🔧 Standalone Pipes - Ready-to-use pipes for common operations
  • 🎯 Type-Safe - Full TypeScript support with proper type inference
  • 📦 Tree-Shakeable - Import only what you need
  • 🚀 Modern Angular - Built for Angular 16+ with standalone components
  • 🔄 FxTS Integration - Leverages @fxts/core for functional utilities
  • 💉 DI Helpers - Simplified dependency injection patterns

Quick Start

import { Component } from '@angular/core';
import { DecimalBytesPipe, ReversePipe, IsNilPipe } from '@dasch-ng/utils';

@Component({
  selector: 'app-example',
  imports: [DecimalBytesPipe, ReversePipe, IsNilPipe],
  template: `
    <p>File size: {{ 1536000 | decimalBytes }}</p>
    <!-- Output: "1.54 MB" -->

    <div *ngFor="let item of items | reverse">
      {{ item }}
    </div>
    <!-- Displays items in reverse order -->

    <div *ngIf="data | isNil">No data available</div>
  `,
})
export class ExampleComponent {
  items = ['a', 'b', 'c'];
  data: string | null = null;
}

Available Utilities

Pipes

Array Manipulation:

  • reverse - Reverse arrays without mutation
  • join - Join array elements with separator
  • nth - Get nth element from iterable
  • sortBy - Sort by property (case-insensitive)

Collection Utilities:

  • size - Get size of any iterable
  • includes - Check if array includes value
  • includedIn - Check if value is in array
  • without - Remove values from an array
  • values - Values of a Map, Set or object, in insertion order

Object Utilities:

  • prop - Extract property from object
  • omit - Copy an object without some keys
  • parseJson - Parse JSON, null instead of an exception

Type Checking:

  • isNil - Check for null or undefined
  • isNull - Check for null
  • isUndefined - Check for undefined
  • isEmpty - Check if value is empty

Formatting:

  • decimalBytes - Format bytes to human-readable sizes
  • binaryBytes - Format bytes with base 1024 (KiB, MiB)

Text:

  • truncateText - Shorten text at a word boundary
  • middleTruncate - Split a string for an ellipsis in the middle
  • highlight - Split text into matching segments for a search term
  • upperFirst - Uppercase the first character, locale-aware

Symbol Utilities:

  • symbolKeyFor - Get key for global symbol

Intl Pipes (@dasch-ng/utils/intl, no registerLocaleData() needed):

  • intlNumber, intlCurrency (with minorUnits for cents), intlDate, intlDateRange, intlRelativeTime, intlList, intlPlural, intlDisplayName, intlDuration, intlBytes, intlLocalized, intlCanonicalLocale
import { IntlCurrencyPipe, IntlRelativeTimePipe } from '@dasch-ng/utils/intl';

Media Pipes (@dasch-ng/utils/media):

  • frameRate, shutterSpeed, coordinate, aspectRatio, codecName, pixelFormat

Functions

Dependency Injection Helpers:

  • provideValue - Create type-safe value providers
  • provideFactory - Create type-safe factory providers
  • provideClass - Create type-safe class providers
  • provideExisting - Create type-safe existing providers (aliases)
  • provideType - Create type-safe constructor providers

Resource Utilities:

  • resourceValueGuard - Safe value extraction from Angular Resources

Event Modifiers:

  • provideEventModifiers - (click.stop), (click.prevent), (click.self) and combinations like (click.stop.prevent) in templates

Overflow Detection:

  • OverflowDirective ([daschNgOverflow]) - Tells whether text is cut off by ellipsis or line clamp, e.g. to show a tooltip only then

Documentation

Full documentation is available at dasch.ng

API Reference

TypeDoc API documentation: dasch.ng/api/@dasch-ng/utils

License

MIT

Running unit tests

Run nx test ng-utils to execute the unit tests.

版本与发布记录

@dasch-ng/utils 共发布 13 个版本,首次发布于 2023/05/14;过去 12 个月发布了 4 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.6.2latest2026/11/11今天
0.6.12026/11/074 天前
0.6.02025/12/3110 个月前
0.5.12025/12/2510 个月前
0.4.12025/06/171.4 年前
0.4.02025/06/131.4 年前

关于 @dasch-ng/utils 的常见问题

@dasch-ng/utils 是什么?

A collection of useful Angular utilities including standalone pipes, dependency injection helpers, and type guards. Built with modern Angular patterns and full TypeScript support.

如何安装 @dasch-ng/utils?

在项目目录运行 npm install @dasch-ng/utils,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@fxts/core(>= 0.20.0)、@angular/core(^21.0.0 || ^22.0.0)、@angular/common(^21.0.0 || ^22.0.0)、@angular/platform-browser(^21.0.0 || ^22.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@dasch-ng/utils 支持 TypeScript 吗?

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

@dasch-ng/utils 支持 ESM 还是 CommonJS?

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

@dasch-ng/utils 可以商用吗?

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

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

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

@dasch-ng/utils 还在维护吗?

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