All packages/@batoanng/utils
Utilities

@batoanng/utils

General-purpose helpers and React hooks for the shared front-end ecosystem.

Version 2.4.21 min read3 entrypoints1 export

Quick install

npm install @batoanng/utils

Pull utility functions and hooks from the package root

The package is tree-shakable, so consumers can import narrow helpers without paying for the full surface area.

Context

What It Covers

Reach for small, typed utilities like slug conversion, delays, previous-value tracking, and error normalisation without rewriting them in each project.

  • โœ… Typed utility functions (e.g. sleep, slugify, short ID generator)
  • โš™๏ธ Server + client safe helpers
  • ๐Ÿช React hooks like usePrevious and useIsomorphicLayoutEffect
  • ๐Ÿงช Unit tested with Jest

โœจ Features

  • โœ… Typed utility functions (e.g. sleep, slugify, short ID generator)
  • โš™๏ธ Server + client-safe helpers
  • ๐Ÿช React hooks like usePrevious and useIsomorphicLayoutEffect
  • ๐Ÿงช Unit tested with Jest
  • ๐Ÿ“ฆ Lightweight and tree-shakable

Setup

Installation

Bring the package into your project with the published npm entrypoint.

npm install @batoanng/utils

๐Ÿ“ฆ Installation

npm install @batoanng/utils

Start

Pull utility functions and hooks from the package root

The package is tree-shakable, so consumers can import narrow helpers without paying for the full surface area.

import { sleep, toSlug, usePrevious } from '@batoanng/utils';

await sleep(250);
const previousValue = usePrevious(value);
const slug = toSlug('Design System Docs');

๐Ÿš€ Usage

import { sleep, generateShortId } from '@batoanng/utils';
import { usePrevious } from '@batoanng/utils';

Surface

Exports And Entrypoints

Export surface

  • . -> types: ./dist/index.d.ts, import: ./dist/index.js, require: ./dist/index.cjs, default: ./dist/index.js

Entrypoints

  • main: ./dist/index.cjs
  • module: ./dist/index.js
  • types: ./dist/index.d.ts

Key files

  • eslint.config.mjs
  • jest.config.cjs
  • package.json
  • src/
  • tsconfig.json

Integration

Integration Notes

  • @batoanng/eslint-config
  • @batoanng/jest-config
  • @batoanng/tsconfig
  • @batoanng/types

Ops

Development Notes

Latest release snapshot

2.4.2

Patch Changes

  • Replace published workspace:* development dependency ranges with npm semver ranges.

๐Ÿงน Linting

This package uses the shared flat ESLint setup via eslint.config.mjs:

import base from '@batoanng/eslint-config/base';
import test from '@batoanng/eslint-config/test';

export default [...base, ...test];

Source docs

Reference

The full README is rendered below so the package guide stays detailed and traceable to the source docs that live with the package itself.

npm version install size

A collection of general-purpose utility functions and React hooks used across multiple packages and applications.


โœจ Features

  • โœ… Typed utility functions (e.g. sleep, slugify, short ID generator)
  • โš™๏ธ Server + client-safe helpers
  • ๐Ÿช React hooks like usePrevious and useIsomorphicLayoutEffect
  • ๐Ÿงช Unit tested with Jest
  • ๐Ÿ“ฆ Lightweight and tree-shakable

๐Ÿ“ฆ Installation

npm install @batoanng/utils

๐Ÿš€ Usage

import { sleep, generateShortId } from '@batoanng/utils';
import { usePrevious } from '@batoanng/utils';

๐Ÿ“ Included Utilities

src/
โ”œโ”€โ”€ generateShortId.ts              # Short random string generator
โ”œโ”€โ”€ getNormalisedError.ts           # Transforms mixed errors to unified format
โ”œโ”€โ”€ SearchSpecBuilder.ts            # Siebel-like query builder for filters
โ”œโ”€โ”€ sleep.ts                        # Delay function using Promise
โ”œโ”€โ”€ toSlug.ts                       # Converts string to URL-friendly slug
โ”œโ”€โ”€ useIsomorphicLayoutEffect.tsx  # SSR-safe useLayoutEffect
โ”œโ”€โ”€ usePrevious.tsx                # React hook to get previous value

๐Ÿงน Linting

This package uses the shared flat ESLint setup via eslint.config.mjs:

import base from '@batoanng/eslint-config/base';
import test from '@batoanng/eslint-config/test';

export default [...base, ...test];