@ecsbase/utils
v0.2.0
Published
@ecsbase/utils — reusable building block.
Readme
@ecsbase/utils
Framework-agnostic helper library: pure functions + a small set of Angular services. Every export is safe to import from Node.js unless explicitly noted.
Install
pnpm add @ecsbase/utilsPeer dependencies
@angular/common^20.0.0@angular/core^20.0.0
Sub-modules
| Module | Purpose |
| ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
| messaging | Typed pub/sub createChannel<T>(), generic NotificationItem, createNotificationItem |
| state | MemoryCollection, StorageAdapter (Memory/Local/Session), TypedStorage, LoadState + loadInto, optimisticUpdate, moveToHistory |
| ui | formatCurrency, formatCurrencyShort, formatNumber, formatDate; colour math (hexToRgb, lighten, darken, withAlpha, contrastText) |
| actions | handleAction(action, options) async wrapper + ActionDescriptor |
| filter | filterByDateRange, filterByStatus, filterByText, sortByState, buildFilterPipeline, applyToggleFilter |
| archive | filterByArchiveState, archive, restore soft-delete helpers |
| (root) | clone, groupBy, distinct, sum, clamp, retry, async, id, sanitize, date, error, logging, connectivity, polling, offline queue, keyboard shortcuts |
All sub-modules re-export from the main entry:
import {
createChannel,
formatCurrency,
handleAction,
filterByText,
filterByArchiveState,
LocalStorageAdapter,
} from '@ecsbase/utils';Quick examples
// Typed pub/sub
const events = createChannel<{ id: string }>();
const off = events.subscribe((e) => console.log(e.id));
events.publish({ id: 'abc' });
off();
// Currency
formatCurrency(1234.56, { locale: 'fr-FR', currency: 'EUR' });
// Async user action with toast + spinner callbacks
await handleAction(() => api.save(), {
setLoading: (b) => loading.set(b),
onError: (m) => toast.error(m),
onSuccess: (m) => toast.success(m),
successMessage: 'Saved',
});
// Generic filtering
const rows = filterByText(items, ['name', 'email'], term);
// Soft delete
const visible = filterByArchiveState(rows, 'active');Playground
Live demo: /utils — run
pnpm start:playground then visit http://localhost:4200/utils.
License
MIT — see LICENSE at the repository root.
