Utils
Utilities
Collection of generic TypeScript utilities, reusable ESLint configurations, and robust Server helpers.
Shared Utilities
The Utilities package (@riavzon/utils) is a tree-shakeable library containing cross-platform helper functions for data manipulation, strict typings, ESLint setups, and server operations.
Installation
If you are using this outside the monorepo, install via your preferred package manager:
pnpm add @riavzon/utils
yarn add @riavzon/utils
npm install @riavzon/utils
bun add @riavzon/utils
Core Features
The utilities are split into four main modules:
Generic Utilities
Core helper functions for array, object, promise, and string manipulation. Available for both client and server.
Server Utilities
Node.js-only helpers for path resolution, shell command execution, and CSV bulk uploads to MySQL and PostgreSQL.
Quick Example
Here is a brief look at how you can interact with the different modules available in the package:
import { ensureArray, cleanObject } from '@riavzon/utils'
// Ensures the provided value is an array
const items = ensureArray(undefined) // []
// Removes null/undefined values from objects
const filtered = cleanObject({ name: 'Example', empty: null }) // { name: 'Example' }
import { run, resolvePath } from '@riavzon/utils/server'
// Resolve a data file path relative to the project root
const dbPath = resolvePath('geo.mmdb', ['_data-sources', 'dist/_data-sources'])
// Execute a shell command and capture its output
const { stdout } = await run('node --version')
console.log(stdout) // "v22.0.0"
// eslint.config.mjs
import { defineStrictTSConfig } from '@riavzon/utils/eslint/strict'
export default defineStrictTSConfig({
rootDir: import.meta.dirname,
extraIgnores: ['coverage/**']
})
import type { Brand, Results } from '@riavzon/utils'
// Use Branding for nominal typing
type UserID = Brand<string, 'UserID'>
// Define consistent API results
async function getUser(): Promise<Results<{ name: string }>> {
return { ok: true, date: new Date().toISOString(), data: { name: 'Sergo' } }
}