@rt-tools/core
v0.3.1
Published
Core utilities for Angular applications - MessageBus, PlatformService, WINDOW token, and helper functions
Maintainers
Readme
@rt-tools/core
Everything in the rt-tools workspace that needs Angular but is not a UI component: directives, pipes, validators, platform and breakpoint services, storage, a message bus and the BEM helpers the kit's templates are built on.
@rt-tools/store and @rt-tools/ui-kit build on it. The framework-free half — pure functions, list
models, type helpers — lives in @rt-tools/utils,
which this package depends on. Neither re-exports the other: isNil and INullable are imported
from @rt-tools/utils, always.
Installation
pnpm add @rt-tools/core
# or
npm install @rt-tools/core@rt-tools/utils comes along as a dependency.
Setup
import { provideRtUtils, provideRtStorage, provideRtIDBStorage } from '@rt-tools/core';
bootstrapApplication(RootComponent, {
providers: [
provideRtUtils(), // BreakpointService + PlatformService
provideRtStorage(), // local / session / in-memory storage
provideRtIDBStorage(), // IndexedDB storage
],
});What is in it
Services
import { BreakpointService, DeviceDetectorService, PlatformService, MessageBus } from '@rt-tools/core';
const breakpoints = inject(BreakpointService); // isMobile / isDesktop
const device = inject(DeviceDetectorService); // OS and device detection
const platform = inject(PlatformService); // isPlatformBrowser / isPlatformServerMessageBus is a small typed event bus over RxJS — the same one @rt-tools/store dispatches
through:
const bus = new MessageBus<'USER_LOGGED_IN' | 'USER_LOGGED_OUT'>();
bus.ofType('USER_LOGGED_IN').subscribe(() => {});
bus.emit({ type: 'USER_LOGGED_IN' });Storage
StorageService behind an injection token per backing store, with a pluggable converter
(JsonConverter by default), plus an IndexedDB service:
import { StorageService, LOCAL_STORAGE, SESSION_STORAGE, IN_MEMORY_STORAGE, IDBStorageService } from '@rt-tools/core';
const storage: StorageService = inject(LOCAL_STORAGE);
storage.setItem('key', { any: 'value' });IN_MEMORY_STORAGE is the fallback when the platform has no Window, so server-side rendering
keeps working instead of throwing.
Directives
import {
RtIconOutlinedDirective, // Material Symbols outlined weight
RtScrollToElementDirective,
RtScrollDirective,
RtNavigationDirective,
RtTabQueryParamDirective, // tab index ↔ query parameter
RtEscapeKeyDirective,
} from '@rt-tools/core';Pipes
import {
BreakStringPipe, // camelCase → readable
SanitizePipe,
EntityToStringPipe,
EmptyToDashPipe,
EqualPipe,
EqualChainPipe,
NotEqualPipe,
NotEqualChainPipe,
TernaryPipe,
IsEmailPipe,
} from '@rt-tools/core';{{ 'camelCaseString' | breakString }} {{ htmlContent | sanitize }} {{ condition | ternary: 'yes' : 'no' }}Validators
import { emailValidator, checkIsMatchingValues, arraysNotEmptyValidator } from '@rt-tools/core';
new FormControl('', [emailValidator]);
new FormGroup({ password, confirm }, { validators: checkIsMatchingValues('password', 'confirm') });BEM
The directives every rtui-* template uses to build class names, and what the kit's own lint rule
expects instead of hand-written class strings:
import { BlockDirective, ElemDirective, ModDirective } from '@rt-tools/core';<div rtBlock="card">
<div rtElem="title" [rtMod]="{ compact: true }">…</div>
</div>Tokens and helpers
import { WINDOW, NAVIGATOR, OVERLAY_POSITIONS, POSITION_ENUM, isHTMLElement } from '@rt-tools/core';
const win = inject(WINDOW); // safe on the serverRequirements
| Requirement | Version |
| ----------------- | --------- |
| Angular | ^22.0.0 |
| RxJS | ^7.8.0 |
| @rt-tools/utils | ^0.2.0 |
@angular/cdk, common, core, forms, platform-browser and router are peer dependencies.
License
Apache-2.0 © Yauheni Krumin
