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

@occollective/recommendations

v1.3.1

Published

A lightweight, flexible recommendation engine for React applications. Define and manage product recommendations with custom display rules, priorities, and fallback options.

Readme

Recommendation Engine SDK

A lightweight, flexible recommendation engine for React applications. Define and manage product recommendations with custom display rules, priorities, and fallback options.

Features

  • 🚀 Lightweight and performant
  • 🎯 Component-based targeting
  • 🔄 Priority-based recommendations
  • ⚡️ Built-in caching
  • 🎨 Flexible display conditions
  • 📦 Fallback support
  • 🛡️ TypeScript support

Installation

npm install @occollective/recommendations

Quick Start

import { engine, useRecommendations } from '@occollective/recommendations';

// 1. Define your recommendations
engine.define(
  'holiday-sale',
  [
    { id: '1', name: 'Holiday Bundle', price: 99.99 },
    { id: '2', name: 'Gift Set', price: 49.99 },
  ],
  () => true,
  {
    component: 'product-slider',
  }
);

// 2. Use in your components
function ProductSlider() {
  const { recommendations, loading } = useRecommendations('product-slider');

  if (loading) return <div>Loading...</div>;
  if (!recommendations) return null;

  return (
    <div>
      {recommendations.map((product) => (
        <div key={product.id}>
          {product.name} - ${product.price}
        </div>
      ))}
    </div>
  );
}

Advanced Configuration

Custom Engine Instance

Create a configured engine instance for more control:

import {
  createEngine,
  RecommendationProvider,
} from '@occollective/recommendations';

const engine = createEngine({
  cache: {
    ttl: 5 * 60 * 1000, // 5 minutes
    maxSize: 1000, // Maximum cache entries
  },
});

function App() {
  return (
    <RecommendationProvider engine={engine}>
      <YourApp />
    </RecommendationProvider>
  );
}

Priority-Based Recommendations

Define multiple recommendations for the same component with different priorities:

// High priority - Flash Sale
engine.define(
  'flash-sale',
  flashSaleProducts,
  (context) => isFlashSaleActive(),
  {
    component: 'home-recommendations',
    priority: 3,
  }
);

// Medium priority - Personalized
engine.define(
  'personalized',
  personalizedProducts,
  (context) => hasUserPreferences(context),
  {
    component: 'home-recommendations',
    priority: 2,
  }
);

// Low priority - Default
engine.define('default', defaultProducts, () => true, {
  component: 'home-recommendations',
  priority: 1,
});

Fallback Support

Add fallback options for when primary recommendations don't match:

engine.define(
  'premium-products',
  premiumProducts,
  (context) => isPremiumUser(context),
  {
    component: 'product-recommendations',
    fallbackProducts: standardProducts, // Show these if user isn't premium
    priority: 2,
  }
);

Context-Aware Conditions

Pass context to your display conditions:

engine.define(
  'geo-specific',
  usProducts,
  (context) => {
    const userRegion = (context as { region?: string })?.region;
    return userRegion === 'US';
  },
  {
    component: 'regional-offers',
  }
);

// In your component:
function RegionalOffers() {
  const { recommendations } = useRecommendations('regional-offers', {
    region: 'US',
  });
  // ...
}

Performance Optimization

Caching

The engine includes built-in caching with configurable TTL and size limits:

const engine = createEngine({
  cache: {
    ttl: 5 * 60 * 1000, // 5 minutes
    maxSize: 1000, // Maximum entries
  },
});

Efficient Conditions

Write performant display conditions:

// ❌ Bad: Expensive operation on every check
engine.define('expensive', products, async (context) => {
  const data = await fetchLargeDataset();
  return processData(data);
});

// ✅ Good: Cache expensive operations
const dataCache = new Map();

engine.define('optimized', products, async (context) => {
  const cached = dataCache.get('key');
  if (cached) return cached;

  const result = await fetchLargeDataset();
  dataCache.set('key', result);
  return result;
});

TypeScript Support

The package includes comprehensive TypeScript definitions:

import type {
  Product,
  RecommendationOptions,
} from '@occollective/recommendations';

interface MyProduct extends Product {
  category: string;
  inStock: boolean;
}

const options: RecommendationOptions = {
  component: 'product-slider',
  priority: 2,
  fallbackProducts: defaultProducts,
};

Error Handling

Use error boundaries for robust error handling:

import { ErrorBoundary } from 'react-error-boundary';

function RecommendationsErrorBoundary({ children }) {
  return (
    <ErrorBoundary
      fallback={<DefaultRecommendations />}
      onError={(error) => {
        console.error('Recommendations failed:', error);
      }}
    >
      {children}
    </ErrorBoundary>
  );
}

Best Practices

  1. Component Organization: Group recommendations by component
  2. Priority Levels: Use consistent priority levels (1-3 recommended)
  3. Fallbacks: Always provide fallback options for critical components
  4. Performance: Cache expensive operations outside the display condition
  5. TypeScript: Utilize type definitions for better development experience

License

This project is licensed under the MIT License - see the LICENSE file for details.