npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@recursica/common

v1.2.0

Published

Shared TypeScript interfaces and types for Recursica projects

Downloads

47

Readme

@recursica/common

Shared TypeScript interfaces and types for Recursica projects.

Features

  • Parsers: Utility functions for parsing and transforming data
  • Detectors: Functions for detecting and analyzing data types
  • Strings: String manipulation utilities
  • Validators: JSON schema validation for Recursica files

Validation

The package includes validation functions for Recursica JSON files based on the schemas defined in @recursica/schemas. Each validation function is in its own module for better organization.

Usage

import {
  validateVariables,
  validateConfiguration,
  validateIcons,
} from "@recursica/common";

// Use specific validation functions
const variablesResult = validateVariables(data);
const configResult = validateConfiguration(data);
const iconsResult = validateIcons(data);

// Check validation results
if (variablesResult.isValid) {
  console.log("Variables are valid!");
} else {
  console.log("Validation errors:", variablesResult.errors);
}

Error Formatting

Validation errors are returned as plain text strings with clear location information using dot notation:

  • Root level errors: "root level: must have required property 'projectId'"
  • Nested property errors: "tokens.color.primary: must have required property 'value'"
  • Array index errors: "overrides.fontWeight.[0]: must be object"

The error messages are designed to be:

  • Plain text with no special characters or symbols
  • Location-aware indicating the exact path to the error in the JSON structure using dot notation
  • Human-readable with clear descriptions of what went wrong

Validation Functions

  • validateVariables(data) - Validates Recursica variables JSON files

    • Schema validation against the RecursicaVariables schema
    • Specialized reference validation:
      • UI Kit variables should NOT reference Tokens (only Themes)
      • Theme variables should ONLY reference Tokens (not other Themes)
    • Returns validation status and detailed error messages
  • validateConfiguration(data) - Validates Recursica configuration JSON files

  • validateIcons(data) - Validates Recursica icons JSON files

Variable Reference Rules

The validateVariables function includes specialized checks for proper variable reference relationships:

  1. UI Kit Layer: Should only reference variables from the Themes collection

    • ❌ Invalid: UI Kit → Tokens reference
    • ✅ Valid: UI Kit → Themes reference
  2. Themes Layer: Should only reference variables from the Tokens collection

    • ❌ Invalid: Themes → Themes reference
    • ✅ Valid: Themes → Tokens reference
  3. Tokens Layer: Contains direct values (no references)

This ensures a clean separation of concerns:

  • Tokens: Raw design values (colors, sizes, etc.)
  • Themes: Semantic design tokens that reference raw tokens
  • UI Kit: Component-specific tokens that reference semantic themes

Return Type

All validation functions return a ValidationResult object:

interface ValidationResult {
  isValid: boolean;
  errors?: string[];
}

Example

import { validateVariables } from "@recursica/common";

const variablesData = {
  projectId: "my-project",
  pluginVersion: "1.0.0",
  tokens: {
    /* ... */
  },
  themes: {
    /* ... */
  },
  uiKit: {
    /* ... */
  },
};

const result = validateVariables(variablesData);

if (result.isValid) {
  console.log("✅ Variables file is valid");
} else {
  console.log("❌ Validation errors:", result.errors);
}

Module Structure

The validation functions are organized in separate modules:

  • validators/validateVariables.ts - Variables schema validation
  • validators/validateConfiguration.ts - Configuration schema validation
  • validators/validateIcons.ts - Icons schema validation
  • validators/index.ts - Validators directory exports

Scripts

The package includes utility scripts in the scripts/ directory:

  • scripts/validate-sample.ts - Sample file validation utility
    • Demonstrates validation capabilities
    • Provides detailed error reporting
    • Categorizes violations by type

Installation

npm install @recursica/common

Development

npm run build         # Build the package
npm run dev           # Watch mode for development
npm run lint          # Run ESLint
npm run check-types   # Type checking
npm run test          # Run tests in watch mode
npm run test:run      # Run tests once
npm run test:coverage # Run tests with coverage report
npm run validate-sample # Validate sample variables file

Testing

The package uses Vitest for unit testing. Tests are located alongside the source files with .test.ts extensions.

Test Coverage

The validation functions have comprehensive test coverage including:

  • Valid data validation
  • Invalid data rejection
  • Error message verification
  • Edge cases and special scenarios
  • Real-world sample file validation - Tests against actual Recursica JSON files

Run npm run test:coverage to see detailed coverage reports.

Sample File Tests

The package includes comprehensive tests that validate against real Recursica JSON files:

  • Configuration files (recursica.json) - Tests project configuration validation
  • Icon files (recursica-icons.json) - Tests icon collection validation with SVG content
  • Variable files (recursica-bundle.json) - Tests large-scale token and theme validation

These tests ensure that the validation functions work correctly with real-world data and can handle large files efficiently.

Sample Validation Script

The package includes a utility script for validating sample files and demonstrating the validation capabilities:

npm run validate-sample

This script:

  • Loads and validates the sample recursica-bundle.json file
  • Categorizes violations by type (UI Kit → Tokens, Theme → Theme)
  • Provides detailed reporting with summary statistics and individual error messages
  • Demonstrates real-world usage of the validation functions

Example Output:

Validation Result: FAIL

Found 302 validation errors:

=== SUMMARY ===
UI Kit → Tokens violations: 117
Theme → Theme violations: 185
Total violations: 302

=== UI KIT → TOKENS VIOLATIONS (117) ===
1. uiKit.[UI-Kit][Mode-1][accordion/size/padding]: UI Kit variables should not reference Tokens collection, found reference to "size/spacer/2x"
2. uiKit.[UI-Kit][Mode-1][accordion/size/spacing]: UI Kit variables should not reference Tokens collection, found reference to "size/spacer/2x"
...

=== THEME → THEME VIOLATIONS (185) ===
1. themes.default.[Themes][Light][layers/layer-0/elements/interactive/color]: Theme variables should only reference Tokens collection, found reference to "colors/scale-1/default/tone" in Themes collection
2. themes.default.[Themes][Dark][layers/layer-0/elements/interactive/color]: Theme variables should only reference Tokens collection, found reference to "colors/scale-1/default/tone" in Themes collection
...

This script is useful for:

  • Development testing - Quickly validate changes to the validation logic
  • Documentation - Show real examples of validation errors
  • Debugging - Identify specific issues in sample data
  • Demonstration - Show the capabilities of the validation system