Introduction to @arkyn/shared
@arkyn/shared is a comprehensive utility library designed to provide a collection of well-tested, reusable functions for common development tasks. Built with TypeScript and optimized for modern JavaScript environments, it offers a modular approach to handling data formatting, generation, parsing, validation, and general-purpose utilities.
Why @arkyn/shared?
When building modern applications, developers often find themselves writing the same utility functions repeatedly across different projects. @arkyn/shared solves this problem by providing a curated set of tools that handle common tasks with a consistent, well-documented API.
Key benefits:
- Type-safe: Written in TypeScript with full type definitions for excellent IDE support and compile-time safety
- Modular: Import only what you need—each function is independently exportable to keep your bundle size minimal
- Well-documented: Every function includes comprehensive documentation with usage examples
- Battle-tested: Functions are designed to handle edge cases and provide meaningful error messages
- Zero dependencies: Lightweight and self-contained, with no external runtime dependencies
- Framework agnostic: Works with any framework that uses the Web API
Request and Response objects
Installation
Important: @arkyn/templates is a mandatory peer dependency for @arkyn/shared. This dependency is required because several formatting and parsing utilities rely on predefined templates and patterns provided by @arkyn/templates to ensure consistent behavior across the package.
npm install @arkyn/shared @arkyn/templates
or with bun:
bun add @arkyn/shared @arkyn/templates
Module Overview
The library is organized into five main categories, each serving a specific purpose:
Formats
Functions for transforming and formatting data into standardized string representations. Includes formatters for dates, currencies (22+ international currencies), Brazilian documents (CPF, CNPJ, CEP), phone numbers, and text manipulation utilities.
import { formatDate, formatToCurrency, formatToCpf } from "@arkyn/shared";
formatDate(["25/12/2025"], "brazilianDate", "YYYY-MM-DD");
formatToCurrency(1234.56, "BRL");
formatToCpf("12345678909");
Generators
Utilities for creating unique identifiers, slugs, and other generated content. Perfect for database IDs, URL-friendly strings, and dynamic content generation.
import { generateId, generateSlug, generateColorByString } from "@arkyn/shared";
generateId("text", "v7");
generateSlug("Hello, World! This is a Test.");
generateColorByString("user@email.com");
Parsers
Functions for extracting, transforming, and sanitizing data. Includes tools for handling sensitive information, parsing dates, and processing large data fields.
import { parseSensitiveData, parseToDate } from "@arkyn/shared";
parseSensitiveData('{"password":"secret123"}', ["password"]);
Services
Service classes that encapsulate complex validation and business logic. These provide reusable, stateful utilities for common operations like date validation with leap year support.
import { ValidateDateService } from "@arkyn/shared";
const validator = new ValidateDateService();
validator.validateDateParts(2024, 2, 29);
Utilities
General-purpose helper functions for common tasks such as HTML processing, financial calculations, string manipulation, and data cleaning.
import { stripHtmlTags, calculateCardInstallment, isHtml } from "@arkyn/shared";
stripHtmlTags("<p>Hello <strong>World</strong></p>");
calculateCardInstallment({ cashPrice: 1000, numberInstallments: 12 });
Design Philosophy
@arkyn/shared follows these core principles:
- Predictable behavior: Functions behave consistently and throw meaningful errors when inputs are invalid
- Immutability: Functions never mutate input data—they always return new values
- Explicit over implicit: Required parameters are clearly documented, with sensible defaults for optional ones
- Internationalization ready: Built-in support for Brazilian formats (CPF, CNPJ, CEP, phone) and 22+ international currencies
Getting Started
Explore the documentation sections to learn about each function in detail:
- Formats — Data formatting utilities
- Generators — ID and content generation
- Parsers — Data parsing and transformation
- Services — Validation and business logic services
- Utilities — General-purpose helper functions