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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@aftershootco/feature-guard

v1.0.4

Published

A flexible, framework-agnostic feature guard and toggle management library

Readme

@aftershoot/feature-guard

A modern, flexible feature flag and toggle management library with ref-based element manipulation and decision system architecture for complex business logic.

✨ Key Features

  • 🎯 Ref-based approach - Direct DOM manipulation, no wrapper components
  • 🧠 Decision System - Complex business logic with multiple data sources
  • 📱 Mobile-optimized tooltips - Touch-friendly floating tooltips
  • Performance optimized - resolveOne() for single feature checks
  • ⚛️ React integration - Modern hooks with TypeScript support
  • 🔧 Framework agnostic - Use with any JavaScript framework

🚀 Installation

npm install @aftershoot/feature-guard

📋 Quick Start

Basic Feature Toggle

import { useFeatureGuard } from '@aftershoot/feature-guard';

function PaymentButton() {
  const { featureRef } = useFeatureGuard({
    enabled: false,
    type: "disable",
    data: {
      tooltipConfig: {
        enabled: true,
        text: { defaultText: "Payment disabled by admin" }
      }
    }
  });

  return <button ref={featureRef}>Pay Now</button>;
}

Decision System for Complex Logic

import { createDecisionSystem, setSources } from '@aftershoot/feature-guard';

// Define your decision rules
const DS = createDecisionSystem<{ user: any; api: any }>();
const Decisions = DS.define({
  premiumFeature: {
    select: ({ user, api }) => user.tier === "premium" && api.enabled,
    type: (enabled) => enabled ? "show" : "blur",
    fallbackEnabled: false
  }
});

// Set global data sources
setSources(Decisions, {
  user: { tier: "free", role: "member" },
  api: { enabled: true }
});

// Use anywhere in your app
function PremiumComponent() {
  const toggle = useDecision("premiumFeature");
  const { featureRef } = useFeatureGuard(toggle);
  
  return <div ref={featureRef}>Premium Content</div>;
}

🎪 Interactive Examples

npm run storybook

View live examples with different scenarios:

  • Basic toggles with API data
  • Complex decision systems
  • Performance comparisons
  • Mobile tooltip interactions

📚 Documentation

🛡️ Toggle Types

  • show - Feature visible and enabled
  • hide - Feature completely hidden
  • disable - Feature visible but disabled with tooltip
  • blur - Feature visible but blurred with tooltip

⚡ Performance

Built for performance with:

  • resolveOne() for single feature checks
  • WeakMap cleanup for memory efficiency
  • IntersectionObserver for off-screen optimization
  • Debounced tooltip interactions

🔧 TypeScript Support

Full type safety with intelligent autocomplete:

type AppSources = {
  user: { tier: string; role: string };
  api: { enabled: boolean };
};

const DS = createDecisionSystem<AppSources>();
// TypeScript ensures your decision logic matches your data

🤝 Contributing

npm run build    # Build the package
npm run test     # Run tests  
npm run storybook # View examples

📜 License

MIT License - see LICENSE file.


Get started with the Usage Guide or explore API Reference